Search in sources :

Example 1 with XMLEncoder

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

the class ConfigurationSaver method visitDataChannelDescriptor.

@Override
public Void visitDataChannelDescriptor(DataChannelDescriptor node) {
    XMLEncoder encoder = new XMLEncoder(printWriter, "\t", version);
    printXMLHeader(encoder);
    delegate.setXMLEncoder(encoder);
    node.encodeAsXML(encoder, delegate);
    return null;
}
Also used : XMLEncoder(org.apache.cayenne.util.XMLEncoder)

Example 2 with XMLEncoder

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

the class FileProjectSaver method saveToTempFile.

void saveToTempFile(SaveUnit unit, PrintWriter printWriter) {
    ConfigurationNodeVisitor<?> visitor;
    if (unit.delegate == null) {
        visitor = new ConfigurationSaver(printWriter, getSupportedVersion(), delegate);
    } else {
        XMLEncoder encoder = new XMLEncoder(printWriter, "\t", getSupportedVersion());
        encoder.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
        unit.delegate.setXMLEncoder(encoder);
        visitor = unit.delegate;
    }
    unit.node.acceptVisitor(visitor);
}
Also used : XMLEncoder(org.apache.cayenne.util.XMLEncoder)

Example 3 with XMLEncoder

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

the class EJBQLQueryIT method testEncodeAsXML.

@Test
public void testEncodeAsXML() {
    String ejbql = "select a FROM Artist a";
    String name = "Test";
    StringWriter w = new StringWriter();
    XMLEncoder e = new XMLEncoder(new PrintWriter(w));
    String separator = System.getProperty("line.separator");
    String s = "<query name=\"" + name + "\" type=\"EJBQLQuery\">" + separator + "<ejbql><![CDATA[" + ejbql + "]]></ejbql>" + separator + "</query>" + separator;
    EJBQLQueryDescriptor descriptor = new EJBQLQueryDescriptor();
    descriptor.setEjbql(ejbql);
    descriptor.setName(name);
    descriptor.encodeAsXML(e, new EmptyConfigurationNodeVisitor());
    assertEquals(w.getBuffer().toString(), s);
}
Also used : EJBQLQueryDescriptor(org.apache.cayenne.map.EJBQLQueryDescriptor) XMLEncoder(org.apache.cayenne.util.XMLEncoder) EmptyConfigurationNodeVisitor(org.apache.cayenne.configuration.EmptyConfigurationNodeVisitor) StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 4 with XMLEncoder

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

the class ObjRelationshipIT method testEncodeAsXML.

@Test
public void testEncodeAsXML() {
    StringWriter buffer = new StringWriter();
    PrintWriter out = new PrintWriter(buffer);
    XMLEncoder encoder = new XMLEncoder(out);
    DataMap map = new DataMap("M");
    ObjEntity source = new ObjEntity("S");
    ObjEntity target = new ObjEntity("T");
    map.addObjEntity(source);
    map.addObjEntity(target);
    ObjRelationship r = new ObjRelationship("X");
    r.setSourceEntity(source);
    r.setTargetEntityName("T");
    r.setCollectionType("java.util.Map");
    r.setMapKey("bla");
    r.encodeAsXML(encoder, new EmptyConfigurationNodeVisitor());
    out.close();
    String lineBreak = System.getProperty("line.separator");
    assertEquals("<obj-relationship name=\"X\" source=\"S\" target=\"T\" " + "collection-type=\"java.util.Map\" map-key=\"bla\"/>" + lineBreak, buffer.getBuffer().toString());
}
Also used : XMLEncoder(org.apache.cayenne.util.XMLEncoder) EmptyConfigurationNodeVisitor(org.apache.cayenne.configuration.EmptyConfigurationNodeVisitor) StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 5 with XMLEncoder

use of org.apache.cayenne.util.XMLEncoder 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

XMLEncoder (org.apache.cayenne.util.XMLEncoder)9 PrintWriter (java.io.PrintWriter)6 EmptyConfigurationNodeVisitor (org.apache.cayenne.configuration.EmptyConfigurationNodeVisitor)6 StringWriter (java.io.StringWriter)5 Test (org.junit.Test)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 List (java.util.List)1 ConfigurationNodeVisitor (org.apache.cayenne.configuration.ConfigurationNodeVisitor)1 XMLDataMapLoader (org.apache.cayenne.configuration.xml.XMLDataMapLoader)1 DbAttribute (org.apache.cayenne.map.DbAttribute)1 DbEntity (org.apache.cayenne.map.DbEntity)1 DbRelationship (org.apache.cayenne.map.DbRelationship)1 EJBQLQueryDescriptor (org.apache.cayenne.map.EJBQLQueryDescriptor)1 ObjAttribute (org.apache.cayenne.map.ObjAttribute)1 ObjEntity (org.apache.cayenne.map.ObjEntity)1 ObjRelationship (org.apache.cayenne.map.ObjRelationship)1 URLResource (org.apache.cayenne.resource.URLResource)1 XMLSerializable (org.apache.cayenne.util.XMLSerializable)1