Search in sources :

Example 1 with ModelTemplate

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));
}
Also used : ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) ModelTemplate(org.whole.lang.templates.ModelTemplate) SaxConsumerHandler(org.whole.lang.xml.util.SaxConsumerHandler) SaxHandlerBuilderOperation(org.whole.lang.xml.util.SaxHandlerBuilderOperation) Document(org.whole.lang.xml.model.Document) Test(org.junit.Test)

Example 2 with ModelTemplate

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;
}
Also used : ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) ModelTemplate(org.whole.lang.templates.ModelTemplate) XmlStoreProducerBuilder(org.whole.lang.xml.util.XmlStoreProducerBuilder) IEntity(org.whole.lang.model.IEntity) XmlStoreProducerBuilderOperation(org.whole.lang.xml.util.XmlStoreProducerBuilderOperation) XmlStoreConsumerVisitor(org.whole.lang.xml.util.XmlStoreConsumerVisitor)

Example 3 with ModelTemplate

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);
}
Also used : ModelTemplate(org.whole.lang.templates.ModelTemplate)

Example 4 with ModelTemplate

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());
}
Also used : XmlPrettyPrinterBuilderOperation(org.whole.lang.xml.codebase.XmlPrettyPrinterBuilderOperation) ModelTemplate(org.whole.lang.templates.ModelTemplate) StringWriter(java.io.StringWriter) IEntity(org.whole.lang.model.IEntity) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) PrintWriter(java.io.PrintWriter)

Example 5 with ModelTemplate

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();
    }
}
Also used : PrintStream(java.io.PrintStream) XmlStoreProducerBuilder(org.whole.lang.xml.util.XmlStoreProducerBuilder) IEntity(org.whole.lang.model.IEntity) BPELModel(org.whole.lang.models.codebase.BPELModel) OutputStream(java.io.OutputStream) IOException(java.io.IOException) XmlStoreProducerBuilderOperation(org.whole.lang.xml.util.XmlStoreProducerBuilderOperation) Date(java.util.Date) IOException(java.io.IOException) XmlPrettyPrinterBuilderOperation(org.whole.lang.xml.codebase.XmlPrettyPrinterBuilderOperation) ModelTemplate(org.whole.lang.templates.ModelTemplate) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) PrintWriter(java.io.PrintWriter)

Aggregations

ModelTemplate (org.whole.lang.templates.ModelTemplate)15 IEntity (org.whole.lang.model.IEntity)11 Test (org.junit.Test)7 ModelBuilderOperation (org.whole.lang.builders.ModelBuilderOperation)6 StreamPersistenceProvider (org.whole.lang.codebase.StreamPersistenceProvider)4 XmlStoreProducerBuilderOperation (org.whole.lang.xml.util.XmlStoreProducerBuilderOperation)4 PrintWriter (java.io.PrintWriter)3 XmlStoreProducerBuilder (org.whole.lang.xml.util.XmlStoreProducerBuilder)3 IOException (java.io.IOException)2 IBindingManager (org.whole.lang.bindings.IBindingManager)2 JavaStoreProducerBuilder (org.whole.lang.java.util.JavaStoreProducerBuilder)2 JavaStoreProducerBuilderOperation (org.whole.lang.java.util.JavaStoreProducerBuilderOperation)2 ModelsModel (org.whole.lang.models.codebase.ModelsModel)2 XmlGenericBuilderAdapter (org.whole.lang.xml.builders.XmlGenericBuilderAdapter)2 XmlPrettyPrinterBuilderOperation (org.whole.lang.xml.codebase.XmlPrettyPrinterBuilderOperation)2 Document (org.whole.lang.xml.model.Document)2 SaxHandlerBuilderOperation (org.whole.lang.xml.util.SaxHandlerBuilderOperation)2 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 File (java.io.File)1