return instance;
}
- File storage = extractStorageFileFromProperties(propertiesProvider);
- LOG.debug("Using file {}", storage.getAbsolutePath());
+ File localStorage = extractStorageFileFromProperties(propertiesProvider);
+ LOG.debug("Using file {}", localStorage.getAbsolutePath());
// Create file if it does not exist
- File parentFile = storage.getAbsoluteFile().getParentFile();
- if (parentFile.exists() == false) {
+ File parentFile = localStorage.getAbsoluteFile().getParentFile();
+ if (!parentFile.exists()) {
LOG.debug("Creating parent folders {}", parentFile);
parentFile.mkdirs();
}
- if (storage.exists() == false) {
+ if (!localStorage.exists()) {
LOG.debug("Storage file does not exist, creating empty file");
try {
- boolean result = storage.createNewFile();
- if (result == false) {
- throw new RuntimeException("Unable to create storage file " + storage);
+ boolean result = localStorage.createNewFile();
+ if (!result) {
+ throw new RuntimeException("Unable to create storage file " + localStorage);
}
} catch (IOException e) {
- throw new RuntimeException("Unable to create storage file " + storage, e);
+ throw new RuntimeException("Unable to create storage file " + localStorage, e);
}
}
if (numberOfStoredBackups == 0) {
throw new RuntimeException(NUMBER_OF_BACKUPS
+ " property should be either set to positive value, or ommited. Can not be set to 0.");
}
- setFileStorage(storage);
+ setFileStorage(localStorage);
instance = this;
return this;
xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
xif.setProperty(XMLInputFactory.SUPPORT_DTD, false);
XMLStreamReader xsr = xif.createXMLStreamReader(new StreamSource(from));
- return ((Config) um.unmarshal(xsr));
+ return (Config) um.unmarshal(xsr);
} catch (JAXBException | XMLStreamException e) {
throw new PersistException("Unable to restore configuration", e);
}
}
public void addConfigSnapshot(ConfigSnapshot snap, int numberOfStoredBackups) {
- if(shouldReplaceLast(numberOfStoredBackups) && snapshots.isEmpty() == false) {
+ if (shouldReplaceLast(numberOfStoredBackups) && !snapshots.isEmpty()) {
snapshots.remove(0);
}
snapshots.add(snap);
public static final String SNAPSHOT_ROOT_ELEMENT_NAME = "snapshot";
- private String configSnapshot;
+ private String configXml;
private SortedSet<String> capabilities = new TreeSet<>();
private Set<String> features = new HashSet<>();
ConfigSnapshot(String configXml, SortedSet<String> capabilities) {
- this.configSnapshot = configXml;
+ this.configXml = configXml;
this.capabilities = capabilities;
}
ConfigSnapshot(String configXml, SortedSet<String> capabilities, Set<String> features) {
- this.configSnapshot = configXml;
+ this.configXml = configXml;
this.capabilities = capabilities;
this.features = features;
}
- public ConfigSnapshot() {
+ ConfigSnapshot() {
}
public static ConfigSnapshot fromConfigSnapshot(ConfigSnapshotHolder cfg) {
@XmlAnyElement(SnapshotHandler.class)
public String getConfigSnapshot() {
- return configSnapshot;
+ return configXml;
}
public void setConfigSnapshot(String configSnapshot) {
- this.configSnapshot = configSnapshot;
+ this.configXml = configSnapshot;
}
@XmlElement(name = "capability")
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("ConfigSnapshot{");
- sb.append("configSnapshot='").append(configSnapshot).append('\'');
+ sb.append("configSnapshot='").append(configXml).append('\'');
sb.append(", capabilities=").append(capabilities);
sb.append(", features=").append(features);
sb.append('}');
return sb.toString();
}
-
}
private StringWriter xmlWriter = new StringWriter();
+ @Override
public StreamResult createUnmarshaller(ValidationEventHandler errorHandler) {
xmlWriter.getBuffer().setLength(0);
return new StreamResult(xmlWriter);
}
+ @Override
public String getElement(StreamResult rt) {
String xml = rt.getWriter().toString();
int beginIndex = xml.indexOf(START_TAG) + START_TAG.length();
return xml.substring(beginIndex, endIndex);
}
+ @Override
public Source marshal(String n, ValidationEventHandler errorHandler) {
try {
String xml = START_TAG + n.trim() + END_TAG;