Search in sources :

Example 1 with JavaStoreProducerBuilderOperation

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

use of org.whole.lang.java.util.JavaStoreProducerBuilderOperation in project whole by wholeplatform.

the class PersistenceTest method testSingleBuilder2Java.

@Test
public void testSingleBuilder2Java() {
    ModelBuilderOperation op = new ModelBuilderOperation();
    JavaStoreProducerBuilderOperation javaOp = new JavaStoreProducerBuilderOperation(op);
    ((JavaStoreProducerBuilder) javaOp.wGetBuilder()).buildStartCompilationUnit("test", "Test");
    try {
        Properties props = PropertiesUtils.translate(System.getProperties());
        props.getEntries().wAdd(0, createResolver(PropertiesEntityDescriptorEnum.Property));
        new ModelTemplate(props).apply(javaOp);
    } catch (IOException e) {
        e.printStackTrace();
    }
    // new TopDownTraversal(new ModelsModel().create()).apply(javaOp);
    ((JavaStoreProducerBuilder) javaOp.wGetBuilder()).buildEndCompilationUnit();
    // new ModelsModel().apply(new JavaStoreProducerBuilderOperation(op));
    IEntity model = op.wGetResult();
    PrettyPrinterOperation.prettyPrint(model);
}
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) JavaStoreProducerBuilderOperation(org.whole.lang.java.util.JavaStoreProducerBuilderOperation) IOException(java.io.IOException) Properties(org.whole.lang.properties.model.Properties) Test(org.junit.Test)

Aggregations

ModelBuilderOperation (org.whole.lang.builders.ModelBuilderOperation)2 JavaStoreProducerBuilder (org.whole.lang.java.util.JavaStoreProducerBuilder)2 JavaStoreProducerBuilderOperation (org.whole.lang.java.util.JavaStoreProducerBuilderOperation)2 IEntity (org.whole.lang.model.IEntity)2 ModelTemplate (org.whole.lang.templates.ModelTemplate)2 File (java.io.File)1 IOException (java.io.IOException)1 Test (org.junit.Test)1 IBindingManager (org.whole.lang.bindings.IBindingManager)1 Properties (org.whole.lang.properties.model.Properties)1