use of org.apache.cayenne.configuration.EmptyConfigurationNodeVisitor 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);
}
use of org.apache.cayenne.configuration.EmptyConfigurationNodeVisitor 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());
}
use of org.apache.cayenne.configuration.EmptyConfigurationNodeVisitor 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();
}
}
use of org.apache.cayenne.configuration.EmptyConfigurationNodeVisitor in project cayenne by apache.
the class EOModelProcessorTest method assertLoaded.
protected void assertLoaded(String mapName, DataMap map) throws Exception {
assertNotNull(map);
assertEquals(mapName, map.getName());
// check obj entities
ObjEntity artistE = map.getObjEntity("Artist");
assertNotNull(artistE);
assertEquals("Artist", artistE.getName());
// check Db entities
DbEntity artistDE = map.getDbEntity("ARTIST");
DbEntity artistDE1 = artistE.getDbEntity();
assertSame(artistDE, artistDE1);
// check attributes
ObjAttribute a1 = artistE.getAttribute("artistName");
assertNotNull(a1);
DbAttribute da1 = a1.getDbAttribute();
assertNotNull(da1);
assertSame(da1, artistDE.getAttribute("ARTIST_NAME"));
// check ObjRelationships
ObjRelationship rel = artistE.getRelationship("artistExhibitArray");
assertNotNull(rel);
assertEquals(1, rel.getDbRelationships().size());
// check DbRelationships
DbRelationship drel = artistDE.getRelationship("artistExhibitArray");
assertNotNull(drel);
assertSame(drel, rel.getDbRelationships().get(0));
// flattened relationships
ObjRelationship frel = artistE.getRelationship("exhibitArray");
assertNotNull(frel);
assertEquals(2, frel.getDbRelationships().size());
// storing data map may uncover some inconsistencies
PrintWriter mockupWriter = new NullPrintWriter();
map.encodeAsXML(new XMLEncoder(mockupWriter), new EmptyConfigurationNodeVisitor());
}
use of org.apache.cayenne.configuration.EmptyConfigurationNodeVisitor in project cayenne by apache.
the class Ordering method toString.
@Override
public String toString() {
StringWriter buffer = new StringWriter();
PrintWriter pw = new PrintWriter(buffer);
XMLEncoder encoder = new XMLEncoder(pw);
encodeAsXML(encoder, new EmptyConfigurationNodeVisitor());
pw.close();
buffer.flush();
return buffer.toString();
}
Aggregations