Search in sources :

Example 26 with ModelBuilderOperation

use of org.whole.lang.builders.ModelBuilderOperation in project whole by wholeplatform.

the class XsiModelTemplateTest method testXsdModelTemplate.

@Test
public void testXsdModelTemplate() throws Exception {
    String pacs002FileName = "pacs.002.001.02S2.xsd";
    IEntity xsdPacs002 = loadXMLSchema(pacs002FileName);
    CommonsEntityFactory.instance.createRootFragment(xsdPacs002.wGetAdapter(CommonsEntityDescriptorEnum.Any));
    IEntity xmlPacs002 = XmlSourcePersistenceKit.instance().readModel(new StreamPersistenceProvider(getInputStream(pacs002FileName)));
    CommonsEntityFactory.instance.createRootFragment(xmlPacs002.wGetAdapter(CommonsEntityDescriptorEnum.Any));
    ModelBuilderOperation mop = new ModelBuilderOperation();
    XmlNormalizerBuilderOperation xnbo = new XmlNormalizerBuilderOperation(mop);
    XsdModelTemplate xsdModelTemplate = new XsdModelTemplate(xsdPacs002);
    xsdModelTemplate.apply(xnbo);
    IEntity xmlModelFromXsdPacs002 = mop.wGetResult();
    Assert.assertTrue(OrderedMatcher.match(xmlModelFromXsdPacs002, xmlPacs002, comparatorsMap));
    String credTrfFileName = "SCTCcfBlkCredTrf.xsd";
    IEntity xsdCredTrf = loadXMLSchema(credTrfFileName);
    CommonsEntityFactory.instance.createRootFragment(xsdCredTrf.wGetAdapter(CommonsEntityDescriptorEnum.Any));
    IEntity xmlCredTrf = XmlSourcePersistenceKit.instance().readModel(new StreamPersistenceProvider(getInputStream(credTrfFileName)));
    CommonsEntityFactory.instance.createRootFragment(xmlCredTrf.wGetAdapter(CommonsEntityDescriptorEnum.Any));
    mop = new ModelBuilderOperation();
    xnbo = new XmlNormalizerBuilderOperation(mop);
    xsdModelTemplate = new XsdModelTemplate(xsdCredTrf);
    xsdModelTemplate.apply(xnbo);
    IEntity xmlModelFromXsdCredTrf = mop.wGetResult();
    Assert.assertTrue(OrderedMatcher.match(xmlModelFromXsdCredTrf, xmlCredTrf, comparatorsMap));
}
Also used : ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) IEntity(org.whole.lang.model.IEntity) XmlNormalizerBuilderOperation(org.whole.lang.xml.codebase.XmlNormalizerBuilderOperation) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) Test(org.junit.Test)

Example 27 with ModelBuilderOperation

use of org.whole.lang.builders.ModelBuilderOperation in project whole by wholeplatform.

the class AttributesMatcherFactory method getDefaultNsDeclPattern.

private static IEntity getDefaultNsDeclPattern() {
    if (defaultNsDeclPattern == null) {
        ModelBuilderOperation mop = new ModelBuilderOperation();
        IXmlBuilder xb = (IXmlBuilder) mop.wGetBuilder(XmlLanguageKit.URI);
        ICommonsBuilder cb = (ICommonsBuilder) mop.wGetBuilder(CommonsLanguageKit.URI);
        xb.Attribute_();
        xb.Name("xmlns");
        cb.Variable_();
        cb.VarType(XmlEntityDescriptorEnum.Value);
        cb.VarName("uri");
        cb.Quantifier(QuantifierEnum.MANDATORY);
        cb._Variable();
        xb._Attribute();
        defaultNsDeclPattern = mop.wGetResult();
    }
    return defaultNsDeclPattern;
}
Also used : ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) IXmlBuilder(org.whole.lang.xml.builders.IXmlBuilder) ICommonsBuilder(org.whole.lang.commons.builders.ICommonsBuilder)

Example 28 with ModelBuilderOperation

use of org.whole.lang.builders.ModelBuilderOperation in project whole by wholeplatform.

the class AttributesMatcherFactory method getRefAttrPattern.

private static IEntity getRefAttrPattern() {
    if (refAttrPattern == null) {
        ModelBuilderOperation mop = new ModelBuilderOperation();
        IXmlBuilder xb = (IXmlBuilder) mop.wGetBuilder(XmlLanguageKit.URI);
        ICommonsBuilder cb = (ICommonsBuilder) mop.wGetBuilder(CommonsLanguageKit.URI);
        xb.Attribute_();
        xb.Name("ref");
        cb.Variable_();
        cb.VarType(XmlEntityDescriptorEnum.Value);
        cb.VarName("value");
        cb.Quantifier(QuantifierEnum.MANDATORY);
        cb._Variable();
        xb._Attribute();
        refAttrPattern = mop.wGetResult();
    }
    return refAttrPattern;
}
Also used : ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) IXmlBuilder(org.whole.lang.xml.builders.IXmlBuilder) ICommonsBuilder(org.whole.lang.commons.builders.ICommonsBuilder)

Example 29 with ModelBuilderOperation

use of org.whole.lang.builders.ModelBuilderOperation in project whole by wholeplatform.

the class XmlBuilderPersistenceKit method doReadModel.

protected IEntity doReadModel(IPersistenceProvider pp) throws Exception {
    IEntity xmlModel = SaxConsumerHandler.parse(pp.getInputStream(), pp.getEncoding());
    ModelBuilderOperation op = new ModelBuilderOperation().withBindings(pp.getBindings());
    new XmlStoreConsumerVisitor(op).visit(xmlModel);
    return ReflectionFactory.makeRootEntity(op.wGetResult());
}
Also used : ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) IEntity(org.whole.lang.model.IEntity) XmlStoreConsumerVisitor(org.whole.lang.xml.util.XmlStoreConsumerVisitor)

Example 30 with ModelBuilderOperation

use of org.whole.lang.builders.ModelBuilderOperation in project whole by wholeplatform.

the class WorkspaceResourceOperations method toArtifactsModel.

public IEntity toArtifactsModel(IResource resource) {
    ModelBuilderOperation mbo = new ModelBuilderOperation();
    WorkspaceTemplate resourceTemplate = new WorkspaceTemplate(resource, false);
    resourceTemplate.apply(mbo);
    return mbo.wGetResult();
}
Also used : ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) WorkspaceTemplate(org.whole.lang.artifacts.templates.WorkspaceTemplate)

Aggregations

ModelBuilderOperation (org.whole.lang.builders.ModelBuilderOperation)41 IEntity (org.whole.lang.model.IEntity)21 Test (org.junit.Test)18 ICommonsBuilder (org.whole.lang.commons.builders.ICommonsBuilder)8 File (java.io.File)6 ModelTemplate (org.whole.lang.templates.ModelTemplate)6 XmlNormalizerBuilderOperation (org.whole.lang.xml.codebase.XmlNormalizerBuilderOperation)6 ResourceTemplate (org.whole.lang.artifacts.templates.ResourceTemplate)5 IBindingManager (org.whole.lang.bindings.IBindingManager)5 IXmlBuilder (org.whole.lang.xml.builders.IXmlBuilder)5 IArtifactsBuilder (org.whole.lang.artifacts.builders.IArtifactsBuilder)4 StreamPersistenceProvider (org.whole.lang.codebase.StreamPersistenceProvider)4 Document (org.whole.lang.xml.model.Document)4 XmlStoreProducerBuilderOperation (org.whole.lang.xml.util.XmlStoreProducerBuilderOperation)4 XmlStoreConsumerVisitor (org.whole.lang.xml.util.XmlStoreConsumerVisitor)3 Category (org.junit.experimental.categories.Category)2 WorkspaceTemplate (org.whole.lang.artifacts.templates.WorkspaceTemplate)2 IBuilderOperation (org.whole.lang.builders.IBuilderOperation)2 JavaStoreProducerBuilder (org.whole.lang.java.util.JavaStoreProducerBuilder)2 JavaStoreProducerBuilderOperation (org.whole.lang.java.util.JavaStoreProducerBuilderOperation)2