Search in sources :

Example 1 with XMLSerializable

use of org.apache.cayenne.util.XMLSerializable in project cayenne by apache.

the class CayenneTransferable method getTransferData.

public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
    if (flavor == CAYENNE_FLAVOR) {
        return data;
    } else {
        StringWriter out = new StringWriter();
        XMLEncoder encoder = new XMLEncoder(new PrintWriter(out), "\t");
        ConfigurationNodeVisitor visitor = new EmptyConfigurationNodeVisitor();
        encoder.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
        if (data instanceof XMLSerializable) {
            ((XMLSerializable) data).encodeAsXML(encoder, visitor);
        } else if (data instanceof List) {
            for (Object o : (List) data) {
                ((XMLSerializable) o).encodeAsXML(encoder, visitor);
            }
        }
        return out.toString();
    }
}
Also used : XMLEncoder(org.apache.cayenne.util.XMLEncoder) EmptyConfigurationNodeVisitor(org.apache.cayenne.configuration.EmptyConfigurationNodeVisitor) XMLSerializable(org.apache.cayenne.util.XMLSerializable) StringWriter(java.io.StringWriter) ConfigurationNodeVisitor(org.apache.cayenne.configuration.ConfigurationNodeVisitor) EmptyConfigurationNodeVisitor(org.apache.cayenne.configuration.EmptyConfigurationNodeVisitor) List(java.util.List) PrintWriter(java.io.PrintWriter)

Aggregations

PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 List (java.util.List)1 ConfigurationNodeVisitor (org.apache.cayenne.configuration.ConfigurationNodeVisitor)1 EmptyConfigurationNodeVisitor (org.apache.cayenne.configuration.EmptyConfigurationNodeVisitor)1 XMLEncoder (org.apache.cayenne.util.XMLEncoder)1 XMLSerializable (org.apache.cayenne.util.XMLSerializable)1