Search in sources :

Example 31 with ModelBuilderOperation

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

the class ResourceArtifactsOperations method toArtifactsModel.

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

Example 32 with ModelBuilderOperation

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

the class JavaBuilderPersistenceKit method doWriteModel.

protected void doWriteModel(IEntity model, IPersistenceProvider pp) throws Exception {
    IBindingManager bm = pp.getBindings();
    if (bm.wIsSet("file")) {
        Object file = bm.wGetValue("file");
        if (file instanceof File)
            bm.wDefValue("className", StringUtils.stripFileExtension(((File) file).getName()));
    }
    if (// TODO test was !bm.wIsSet("className") &&
    bm.wIsSet("fileName"))
        bm.wDefValue("className", bm.wStringValue("fileName"));
    IEntity packageNameEntity = bm.wGet("packageName");
    String packageName = packageNameEntity != null ? packageNameEntity.wStringValue() : null;
    IEntity classNameEntity = bm.wGet("className");
    String className = classNameEntity != null ? bm.wStringValue("className") : "AnonymousClass";
    ModelBuilderOperation op = new ModelBuilderOperation();
    JavaStoreProducerBuilderOperation javaOp = new JavaStoreProducerBuilderOperation(op);
    ((JavaStoreProducerBuilder) javaOp.wGetBuilder()).buildStartCompilationUnit(packageName, className, model.wGetEntityDescriptor().getEntityType().getName());
    new ModelTemplate(model).apply(javaOp);
    ((JavaStoreProducerBuilder) javaOp.wGetBuilder()).buildEndCompilationUnit();
    IEntity javaModel = op.wGetResult();
    PrettyPrinterOperation.prettyPrint(javaModel, pp.getOutputStream(), pp.getEncoding());
}
Also used : ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) ModelTemplate(org.whole.lang.templates.ModelTemplate) JavaStoreProducerBuilder(org.whole.lang.java.util.JavaStoreProducerBuilder) IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) JavaStoreProducerBuilderOperation(org.whole.lang.java.util.JavaStoreProducerBuilderOperation) File(java.io.File)

Example 33 with ModelBuilderOperation

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

the class AbstractTemplateFactory method create.

@SuppressWarnings("unchecked")
public E create() {
    ModelBuilderOperation op = new ModelBuilderOperation();
    apply(op);
    return (E) ReflectionFactory.makeRootEntity(op.wGetResult());
}
Also used : ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation)

Example 34 with ModelBuilderOperation

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

the class AbstractTemplateManager method create.

public IEntity create(ITemplate template) {
    ModelBuilderOperation op = new ModelBuilderOperation();
    template.apply(op);
    return op.wGetResult();
}
Also used : ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation)

Example 35 with ModelBuilderOperation

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

the class JSONPersistencesTest method testStreamAndBuildParserEquivalence.

@Test
public void testStreamAndBuildParserEquivalence() throws Exception {
    IEntity sampleModelByFactory = JSONSourcePersistenceKit.instance().readModel(new StreamPersistenceProvider(getClass().getResourceAsStream("sample.json")));
    ModelBuilderOperation op = new ModelBuilderOperation();
    new JSONParserTemplateFactory(new JsonFactory().createParser(sampleString)).apply(op);
    IEntity sampleModelByBuilder = ReflectionFactory.makeRootEntity(op.wGetResult());
    assertTrue(Matcher.match(sampleModelByFactory, sampleModelByBuilder));
}
Also used : ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) IEntity(org.whole.lang.model.IEntity) JsonFactory(com.fasterxml.jackson.core.JsonFactory) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) JSONParserTemplateFactory(org.whole.lang.json.util.JSONParserTemplateFactory) Test(org.junit.Test)

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