Search in sources :

Example 1 with PojoEntityFactory

use of org.whole.lang.pojo.factories.PojoEntityFactory in project whole by wholeplatform.

the class PojoNormalizerVisitor method createDefaultTemplateInDeclarations.

public static void createDefaultTemplateInDeclarations(Library entity, IBindingManager bindings, FreshNameGenerator entityNameGenerator) {
    PojoEntityFactory pef = PojoEntityFactory.instance;
    Path findAllProductDeclarationsWithEmptyTemplate = (Path) PojoTemplateManager.instance().create("findAllProductDeclarationsWithEmptyTemplate");
    bindings.wEnterScope();
    for (ProductDeclaration declaration : BehaviorUtils.<ProductDeclaration>compileAndLazyEvaluate(findAllProductDeclarationsWithEmptyTemplate, entity, bindings)) {
        String name = StringUtils.toSimpleName(bindings.wStringValue("name"));
        declaration.setTemplate(pef.createName(entityNameGenerator.nextFreshName(name)));
    }
    bindings.wExitScope();
}
Also used : PojoEntityFactory(org.whole.lang.pojo.factories.PojoEntityFactory) Path(org.whole.lang.queries.model.Path) ProductDeclaration(org.whole.lang.pojo.model.ProductDeclaration)

Example 2 with PojoEntityFactory

use of org.whole.lang.pojo.factories.PojoEntityFactory in project whole by wholeplatform.

the class Helpers method toPojoType.

public static Type toPojoType(IEntity javaType, IEntity packageName) {
    PojoEntityFactory pef = PojoEntityFactory.instance;
    switch(javaType.wGetEntityDescriptor().getOrdinal()) {
        case JavaEntityDescriptorEnum.SimpleType_ord:
        case JavaEntityDescriptorEnum.QualifiedType_ord:
            String javaTypeName = DataTypeUtils.getAsPersistenceString(javaType);
            String packageNameString = packageName.wStringValue();
            String typeName = (javaTypeName.indexOf('.') == -1 ? (StringUtils.isAmbiguous(javaTypeName) ? "java.lang" : packageNameString) + "." : "") + javaTypeName;
            if (StringUtils.isString(typeName))
                return pef.createPrimitiveType(PrimitiveTypeEnum.String);
            else if ("java.util.Set".equals(typeName))
                return pef.createCollectionType(pef.createCollectionInterface(CollectionInterfaceEnum.Set), pef.createReferenceType("java.lang.Object"));
            else if ("java.util.List".equals(typeName))
                return pef.createCollectionType(pef.createCollectionInterface(CollectionInterfaceEnum.List), pef.createReferenceType("java.lang.Object"));
            else if ("java.util.Map".equals(typeName))
                return pef.createMapType(pef.createReferenceType("java.lang.Object"), pef.createReferenceType("java.lang.Object"));
            else
                return pef.createReferenceType(typeName);
        case JavaEntityDescriptorEnum.PrimitiveType_ord:
            return (Type) DataTypeUtils.convertCloneIfParented(JavaEntityFactory.instance.createPrimitiveType(((PrimitiveType) javaType).getValue()), PojoEntityDescriptorEnum.PrimitiveType);
        case JavaEntityDescriptorEnum.ArrayType_ord:
            ArrayType arrayType = (ArrayType) javaType;
            return pef.createArrayType(toPojoType(arrayType.getComponentType(), packageName));
        case JavaEntityDescriptorEnum.ParameterizedType_ord:
            ParameterizedType parameterizedType = (ParameterizedType) javaType;
            Types typeArguments = parameterizedType.getTypeArguments();
            Type pojoType = toPojoType(parameterizedType.getType(), packageName);
            if (Matcher.matchImpl(PojoEntityDescriptorEnum.CollectionType, pojoType) && typeArguments.wSize() == 1)
                ((CollectionType) pojoType).setElementType(toPojoType(typeArguments.wGet(0), packageName));
            else if (Matcher.matchImpl(PojoEntityDescriptorEnum.MapType, pojoType) && typeArguments.wSize() == 2) {
                ((MapType) pojoType).setKeyType(toPojoType(typeArguments.wGet(0), packageName));
                ((MapType) pojoType).setValueType(toPojoType(typeArguments.wGet(1), packageName));
            }
            return pojoType;
        default:
            throw new IllegalStateException("cannot convert java type to pojo type: " + javaType);
    }
}
Also used : PojoEntityFactory(org.whole.lang.pojo.factories.PojoEntityFactory) ArrayType(org.whole.lang.java.model.ArrayType) ParameterizedType(org.whole.lang.java.model.ParameterizedType) Types(org.whole.lang.java.model.Types) MapType(org.whole.lang.pojo.model.MapType) Type(org.whole.lang.pojo.model.Type) ParameterizedType(org.whole.lang.java.model.ParameterizedType) CollectionType(org.whole.lang.pojo.model.CollectionType) ArrayType(org.whole.lang.java.model.ArrayType) PrimitiveType(org.whole.lang.java.model.PrimitiveType)

Example 3 with PojoEntityFactory

use of org.whole.lang.pojo.factories.PojoEntityFactory in project whole by wholeplatform.

the class PojoUtils method findProductDeclarationByTemplateName.

public static ProductDeclaration findProductDeclarationByTemplateName(EntityDescriptor<?> ed, Library library) {
    PojoEntityFactory pef = PojoEntityFactory.instance;
    Expression findProductDeclarationByTemplateName = (Expression) PojoTemplateManager.instance().create("findProductDeclarationByTemplateName");
    Name templateName = pef.createName(ed.getName());
    IBindingManager bindings = BindingManagerFactory.instance.createArguments();
    bindings.wDef("templateName", templateName);
    return BehaviorUtils.evaluateFirstResult(findProductDeclarationByTemplateName, library, bindings);
}
Also used : PojoEntityFactory(org.whole.lang.pojo.factories.PojoEntityFactory) Expression(org.whole.lang.queries.model.Expression) PathExpression(org.whole.lang.queries.model.PathExpression) IBindingManager(org.whole.lang.bindings.IBindingManager) Name(org.whole.lang.pojo.model.Name)

Aggregations

PojoEntityFactory (org.whole.lang.pojo.factories.PojoEntityFactory)3 IBindingManager (org.whole.lang.bindings.IBindingManager)1 ArrayType (org.whole.lang.java.model.ArrayType)1 ParameterizedType (org.whole.lang.java.model.ParameterizedType)1 PrimitiveType (org.whole.lang.java.model.PrimitiveType)1 Types (org.whole.lang.java.model.Types)1 CollectionType (org.whole.lang.pojo.model.CollectionType)1 MapType (org.whole.lang.pojo.model.MapType)1 Name (org.whole.lang.pojo.model.Name)1 ProductDeclaration (org.whole.lang.pojo.model.ProductDeclaration)1 Type (org.whole.lang.pojo.model.Type)1 Expression (org.whole.lang.queries.model.Expression)1 Path (org.whole.lang.queries.model.Path)1 PathExpression (org.whole.lang.queries.model.PathExpression)1