Search in sources :

Example 76 with Persister

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();
}
Also used : StringWriter(java.io.StringWriter) Persister(org.simpleframework.xml.core.Persister) StringWriter(java.io.StringWriter) Writer(java.io.Writer) Serializer(org.simpleframework.xml.Serializer)

Example 77 with Persister

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;
}
Also used : AnnotationStrategy(org.simpleframework.xml.convert.AnnotationStrategy) Persister(org.simpleframework.xml.core.Persister) Serializer(org.simpleframework.xml.Serializer)

Example 78 with Persister

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;
}
Also used : AnnotationStrategy(org.simpleframework.xml.convert.AnnotationStrategy) StringReader(java.io.StringReader) Persister(org.simpleframework.xml.core.Persister)

Example 79 with Persister

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();
    }
}
Also used : DataTagAddress(cern.c2mon.shared.common.datatag.DataTagAddress) HashMap(java.util.HashMap) Persister(org.simpleframework.xml.core.Persister) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Serializer(org.simpleframework.xml.Serializer) Test(org.junit.Test)

Example 80 with Persister

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;
}
Also used : CommandList(cern.c2mon.server.common.device.CommandList) Command(cern.c2mon.server.common.device.Command) ArrayList(java.util.ArrayList) Persister(org.simpleframework.xml.core.Persister) Serializer(org.simpleframework.xml.Serializer)

Aggregations

Persister (org.simpleframework.xml.core.Persister)177 Serializer (org.simpleframework.xml.Serializer)141 StringWriter (java.io.StringWriter)74 Writer (java.io.Writer)62 Registry (org.simpleframework.xml.convert.Registry)23 RegistryStrategy (org.simpleframework.xml.convert.RegistryStrategy)23 Strategy (org.simpleframework.xml.strategy.Strategy)23 AnnotationStrategy (org.simpleframework.xml.convert.AnnotationStrategy)20 File (java.io.File)18 Test (org.junit.Test)14 IOException (java.io.IOException)12 StorageException (org.syncany.plugins.transfer.StorageException)8 RegistryMatcher (org.simpleframework.xml.transform.RegistryMatcher)6 ConfigTO (org.syncany.config.to.ConfigTO)5 UnreliableLocalTransferSettings (org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 FileOutputStream (java.io.FileOutputStream)4 DateFormat (java.text.DateFormat)4 SimpleDateFormat (java.text.SimpleDateFormat)4 ArrayList (java.util.ArrayList)4