use of org.whole.lang.templates.ModelTemplate in project whole by wholeplatform.
the class PersistenceTest method testSaxHandlerBuilder.
@Test
public void testSaxHandlerBuilder() throws Exception {
Document xmlModel = (Document) XmlSourcePersistenceKit.instance().readModel(new ClasspathPersistenceProvider("org/whole/lang/xsd/util/javaee_web_services_client_1_2.xsd"));
ModelBuilderOperation op = new ModelBuilderOperation();
SaxConsumerHandler saxHandler = new SaxConsumerHandler(op, !EntityUtils.isResolver(xmlModel.getProlog().getXmlDecl()));
SaxHandlerBuilderOperation sbop = new SaxHandlerBuilderOperation(saxHandler, saxHandler);
new ModelTemplate(xmlModel).apply(sbop);
assertTrue(Matcher.match(op.wGetResult(), xmlModel));
}
use of org.whole.lang.templates.ModelTemplate in project whole by wholeplatform.
the class PersistenceTest method xmlRoundtrip.
private IEntity xmlRoundtrip(IEntity model1) {
ModelBuilderOperation op = new ModelBuilderOperation();
XmlStoreProducerBuilderOperation xmlOp = new XmlStoreProducerBuilderOperation(op);
((XmlStoreProducerBuilder) xmlOp.wGetBuilder()).buildStartDocument();
new ModelTemplate(model1).apply(xmlOp);
((XmlStoreProducerBuilder) xmlOp.wGetBuilder()).buildEndDocument();
IEntity xmlModel = op.wGetResult();
op = new ModelBuilderOperation();
new XmlStoreConsumerVisitor(op).visit(xmlModel);
IEntity model2 = op.wGetResult();
return model2;
}
use of org.whole.lang.templates.ModelTemplate in project whole by wholeplatform.
the class XmlSpecific2XsiBuilderAdapter method anyAttributeEntity.
protected void anyAttributeEntity(EntityDescriptor<?> context, Attribute anyAttribute) {
builder.wEntity_(CommonsEntityDescriptorEnum.SameStageFragment);
new ModelTemplate(anyAttribute).apply(builder);
builder._wEntity(CommonsEntityDescriptorEnum.SameStageFragment);
}
use of org.whole.lang.templates.ModelTemplate in project whole by wholeplatform.
the class XmlPrettyPrinterBuilderTest method comparePrettyPrints.
private void comparePrettyPrints(String filename) throws Exception {
IEntity model = XmlSourcePersistenceKit.instance().readModel(new StreamPersistenceProvider(getClass().getResourceAsStream(filename)));
StringWriter stringWriter = new StringWriter();
XmlPrettyPrinterBuilderOperation xppbop = new XmlPrettyPrinterBuilderOperation(new PrintWriter(stringWriter, true));
new ModelTemplate(model).apply(new XmlGenericBuilderAdapter((IXmlBuilder) xppbop.wGetBuilder(XmlLanguageKit.URI)));
assertEquals(toPrettyPrintString(model), stringWriter.toString());
}
use of org.whole.lang.templates.ModelTemplate in project whole by wholeplatform.
the class XmlPrettyPrinterBuilderTest method _testPerformance.
public void _testPerformance() {
IEntity model = new BPELModel().create();
PrintStream nullPrintStream = new PrintStream(new OutputStream() {
@Override
public void write(int b) throws IOException {
// do nothing
}
});
try {
long timestamp = new Date().getTime();
for (int i = 0; i < 1000; i++) {
XmlPrettyPrinterBuilderOperation op = new XmlPrettyPrinterBuilderOperation(new PrintWriter(nullPrintStream));
XmlStoreProducerBuilderOperation xmlOp = new XmlStoreProducerBuilderOperation(op);
((XmlStoreProducerBuilder) xmlOp.wGetBuilder()).buildStartDocument();
new ModelTemplate(model).apply(xmlOp);
((XmlStoreProducerBuilder) xmlOp.wGetBuilder()).buildEndDocument();
}
long timediff = new Date().getTime() - timestamp;
System.out.println("PrettyPrinterBuilder elapsed time: " + timediff + "ms");
timestamp = new Date().getTime();
for (int i = 0; i < 1000; i++) XmlBuilderPersistenceKit.instance().writeModel(model, new StreamPersistenceProvider(nullPrintStream));
timediff = new Date().getTime() - timestamp;
System.out.println("PrettyPrinterVisitor elapsed time: " + timediff + "ms");
} catch (Exception e) {
fail();
}
}
Aggregations