Search in sources :

Example 1 with XmlStoreProducerBuilder

use of org.whole.lang.xml.util.XmlStoreProducerBuilder 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 2 with XmlStoreProducerBuilder

use of org.whole.lang.xml.util.XmlStoreProducerBuilder 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)

Example 3 with XmlStoreProducerBuilder

use of org.whole.lang.xml.util.XmlStoreProducerBuilder in project whole by wholeplatform.

the class XmlBuilderPersistenceKit method doWriteModel.

protected void doWriteModel(IEntity model, IPersistenceProvider pp) throws Exception {
    PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(pp.getOutputStream(), pp.getEncoding()));
    XmlPrettyPrinterBuilderOperation op = new XmlPrettyPrinterBuilderOperation(printWriter);
    XmlStoreProducerBuilderOperation xmlOp = new XmlStoreProducerBuilderOperation(op);
    ((XmlStoreProducerBuilder) xmlOp.wGetBuilder()).buildStartDocument();
    new ModelTemplate(model).apply(xmlOp);
    ((XmlStoreProducerBuilder) xmlOp.wGetBuilder()).buildEndDocument();
    printWriter.flush();
}
Also used : ModelTemplate(org.whole.lang.templates.ModelTemplate) XmlStoreProducerBuilder(org.whole.lang.xml.util.XmlStoreProducerBuilder) OutputStreamWriter(java.io.OutputStreamWriter) XmlStoreProducerBuilderOperation(org.whole.lang.xml.util.XmlStoreProducerBuilderOperation) PrintWriter(java.io.PrintWriter)

Example 4 with XmlStoreProducerBuilder

use of org.whole.lang.xml.util.XmlStoreProducerBuilder in project whole by wholeplatform.

the class PersistenceTest method testMultipleBuilders2Xml.

@Test
public void testMultipleBuilders2Xml() {
    ModelBuilderOperation op = new ModelBuilderOperation();
    XmlStoreProducerBuilderOperation xmlOp = new XmlStoreProducerBuilderOperation(op);
    ((XmlStoreProducerBuilder) xmlOp.wGetBuilder()).buildStartDocument();
    new WholeLanguage().apply(xmlOp);
    ((XmlStoreProducerBuilder) xmlOp.wGetBuilder()).buildEndDocument();
    IEntity xmlModel = op.wGetResult();
    PrettyPrinterOperation.prettyPrint(xmlModel);
}
Also used : ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) XmlStoreProducerBuilder(org.whole.lang.xml.util.XmlStoreProducerBuilder) IEntity(org.whole.lang.model.IEntity) XmlStoreProducerBuilderOperation(org.whole.lang.xml.util.XmlStoreProducerBuilderOperation) WholeLanguage(org.whole.lang.misc.codebase.WholeLanguage) Test(org.junit.Test)

Aggregations

XmlStoreProducerBuilder (org.whole.lang.xml.util.XmlStoreProducerBuilder)4 XmlStoreProducerBuilderOperation (org.whole.lang.xml.util.XmlStoreProducerBuilderOperation)4 IEntity (org.whole.lang.model.IEntity)3 ModelTemplate (org.whole.lang.templates.ModelTemplate)3 PrintWriter (java.io.PrintWriter)2 ModelBuilderOperation (org.whole.lang.builders.ModelBuilderOperation)2 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintStream (java.io.PrintStream)1 Date (java.util.Date)1 Test (org.junit.Test)1 StreamPersistenceProvider (org.whole.lang.codebase.StreamPersistenceProvider)1 WholeLanguage (org.whole.lang.misc.codebase.WholeLanguage)1 BPELModel (org.whole.lang.models.codebase.BPELModel)1 XmlPrettyPrinterBuilderOperation (org.whole.lang.xml.codebase.XmlPrettyPrinterBuilderOperation)1 XmlStoreConsumerVisitor (org.whole.lang.xml.util.XmlStoreConsumerVisitor)1