use of org.simpleframework.xml.core.Persister in project netxms by netxms.
the class PerfTabGraphSettings method createXml.
/**
* Create XML document from object
*
* @return XML document
* @throws Exception if the schema for the object is not valid
*/
public String createXml() throws Exception {
Serializer serializer = new Persister();
Writer writer = new StringWriter();
serializer.write(this, writer);
return writer.toString();
}
use of org.simpleframework.xml.core.Persister in project c2mon by c2mon.
the class AlarmValueImpl method getXml.
public String getXml() {
Serializer serializer = new Persister(new AnnotationStrategy());
StringWriter fw = null;
String result = null;
try {
fw = new StringWriter();
serializer.write(this, fw);
result = fw.toString();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (fw != null) {
try {
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return result;
}
use of org.simpleframework.xml.core.Persister in project c2mon by c2mon.
the class TagConfigImpl method fromXml.
public static TagConfigImpl fromXml(final String xml) throws Exception {
TagConfigImpl conf = null;
StringReader sr = null;
Serializer serializer = new Persister(new AnnotationStrategy());
try {
sr = new StringReader(xml);
conf = serializer.read(TagConfigImpl.class, new StringReader(xml), false);
} finally {
if (sr != null) {
sr.close();
}
}
return conf;
}
use of org.simpleframework.xml.core.Persister in project c2mon by c2mon.
the class DataTagAddressTest method deserializeAndSerializeWithSimpleXml.
@Test
public void deserializeAndSerializeWithSimpleXml() {
try {
// setup Data
HashMap<String, String> map = new HashMap<>();
map.put("key1", "value1");
map.put("key2", "value2");
DataTagAddress address = new DataTagAddress(map);
address.setTimeToLive(100);
Serializer serializer = new Persister();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// serialization
serializer.write(address, baos);
String content = new String(baos.toByteArray(), "UTF-8");
DataTagAddress address2 = serializer.read(DataTagAddress.class, content);
assertEquals(address2, address);
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.simpleframework.xml.core.Persister in project c2mon by c2mon.
the class DeviceClassFacadeImpl method parseXmlCommands.
/**
* Parse the XML representation of the commands of a device class (which comes
* from configuration) and return it as a list of commands.
*
* @param xmlString the XML representation string of the device class commands
*
* @return the list of commands
* @throws Exception if the XML could not be parsed
*/
private List<Command> parseXmlCommands(String xmlString) throws Exception {
List<Command> commands = new ArrayList<>();
Serializer serializer = new Persister();
CommandList commandList = serializer.read(CommandList.class, xmlString);
for (Command command : commandList.getCommands()) {
commands.add(command);
}
return commands;
}
Aggregations