Search in sources :

Example 1 with ConfigurationNodeVisitor

use of org.apache.cayenne.configuration.ConfigurationNodeVisitor 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)

Example 2 with ConfigurationNodeVisitor

use of org.apache.cayenne.configuration.ConfigurationNodeVisitor in project cayenne by apache.

the class ProjectTest method testRootNode.

@Test
public void testRootNode() {
    ConfigurationNode object = new ConfigurationNode() {

        public <T> T acceptVisitor(ConfigurationNodeVisitor<T> visitor) {
            return null;
        }
    };
    Project project = new Project(new ConfigurationTree<ConfigurationNode>(object));
    assertSame(object, project.getRootNode());
    assertFalse(project.isModified());
    project.setModified(true);
    assertTrue(project.isModified());
}
Also used : ConfigurationNodeVisitor(org.apache.cayenne.configuration.ConfigurationNodeVisitor) ConfigurationNode(org.apache.cayenne.configuration.ConfigurationNode) Test(org.junit.Test)

Aggregations

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