Search in sources :

Example 1 with Property

use of org.whole.lang.pojo.model.Property in project whole by wholeplatform.

the class PojoNormalizerVisitor method addReferenceTypeMappingDataType.

public static void addReferenceTypeMappingDataType(ReferenceType type, Library entity, IBindingManager bindings, FreshNameGenerator entityNameGenerator) {
    Property property = (Property) bindings.wGet("property");
    Declaration declaration = PojoUtils.findProductDeclaration(type, entity);
    boolean hasDataTypeModifier = property.getAnnotations().wContainsValue(ModifierEnum.DATATYPE);
    boolean needsDeclaration = declaration == null;
    boolean needsModifier = property.equals(type.wGetParent()) && !hasDataTypeModifier && (needsDeclaration || Matcher.matchImpl(PojoEntityDescriptorEnum.DataTypeDeclaration, declaration));
    if (needsModifier)
        property.getAnnotations().wAdd(PojoEntityFactory.instance.createModifier(ModifierEnum.DATATYPE));
    if (needsDeclaration)
        PojoUtils.addDataTypeDeclaration(type, entityNameGenerator.nextFreshName(PojoUtils.calculateTypeName(type)), entity);
}
Also used : PojoDeclaration(org.whole.lang.pojo.model.PojoDeclaration) ProductDeclaration(org.whole.lang.pojo.model.ProductDeclaration) Declaration(org.whole.lang.pojo.model.Declaration) Property(org.whole.lang.pojo.model.Property)

Example 2 with Property

use of org.whole.lang.pojo.model.Property in project whole by wholeplatform.

the class PojoNormalizerVisitor method createDefaultTemplateInProperties.

public static void createDefaultTemplateInProperties(Library entity, IBindingManager bindings) {
    Path findAllPropertiesWithoutTemplate = (Path) PojoTemplateManager.instance().create("findAllPropertiesWithoutTemplate");
    bindings.wEnterScope();
    for (Property property : BehaviorUtils.<Property>compileAndLazyEvaluate(findAllPropertiesWithoutTemplate, entity, bindings)) property.setTemplate((Name) EntityUtils.clone(bindings.wGet("name")));
    bindings.wExitScope();
}
Also used : Path(org.whole.lang.queries.model.Path) Property(org.whole.lang.pojo.model.Property) Name(org.whole.lang.pojo.model.Name)

Example 3 with Property

use of org.whole.lang.pojo.model.Property in project whole by wholeplatform.

the class PojoUtils method createInstanceUsingConstructor.

public static Object createInstanceUsingConstructor(IEntity fromEntity, PojoDeclaration pojoDeclaration, Library library) throws Exception {
    ReferenceType referenceType = pojoDeclaration.getName();
    Class<?> clazz = Class.forName(referenceType.getValue(), true, ReflectionFactory.getPlatformClassLoader());
    Constructor constructor = findConstructor(pojoDeclaration);
    int params = constructor.getParameters().wSize();
    List<Class<?>> parameterTypes = new ArrayList<Class<?>>(params);
    List<Object> initargs = new ArrayList<Object>(params);
    IBindingManager bindings = BindingManagerFactory.instance.createArguments();
    Expression findPropertyByTemplate = (Expression) PojoTemplateManager.instance().create("findPropertyByTemplate");
    Expression findParameterByTemplate = (Expression) PojoTemplateManager.instance().create("findParameterByTemplate");
    IEntityIterator<Parameter> iterator = BehaviorUtils.<Parameter>compileAndLazyEvaluate(findParameterByTemplate, constructor, bindings);
    while (iterator.hasNext()) {
        iterator.next();
        Property property = BehaviorUtils.<Property>evaluateFirstResult(findPropertyByTemplate, pojoDeclaration, bindings);
        Type type = property.getType();
        Name template = property.getTemplate();
        FeatureDescriptor fd = fromEntity.wGetEntityDescriptor().getFeatureDescriptorEnum().valueOf(template.wStringValue());
        IEntity fieldEntity = fromEntity.wGet(fd);
        parameterTypes.add(getClass(type));
        initargs.add(Matcher.match(PrimitiveType, type) ? fieldEntity.wGetValue() : create(fieldEntity, library));
    }
    return clazz.getConstructor(parameterTypes.toArray(new Class<?>[0])).newInstance(initargs.toArray());
}
Also used : IEntity(org.whole.lang.model.IEntity) Constructor(org.whole.lang.pojo.model.Constructor) ArrayList(java.util.ArrayList) ReferenceType(org.whole.lang.pojo.reflect.PojoEntityDescriptorEnum.ReferenceType) ReferenceType(org.whole.lang.pojo.model.ReferenceType) Name(org.whole.lang.pojo.model.Name) PrimitiveType(org.whole.lang.pojo.model.PrimitiveType) PrimitiveType(org.whole.lang.pojo.reflect.PojoEntityDescriptorEnum.PrimitiveType) Type(org.whole.lang.pojo.model.Type) MapType(org.whole.lang.pojo.model.MapType) ArrayType(org.whole.lang.pojo.model.ArrayType) ReferenceType(org.whole.lang.pojo.reflect.PojoEntityDescriptorEnum.ReferenceType) CollectionType(org.whole.lang.pojo.model.CollectionType) ReferenceType(org.whole.lang.pojo.model.ReferenceType) Expression(org.whole.lang.queries.model.Expression) PathExpression(org.whole.lang.queries.model.PathExpression) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) IBindingManager(org.whole.lang.bindings.IBindingManager) Parameter(org.whole.lang.pojo.model.Parameter) Property(org.whole.lang.pojo.model.Property)

Example 4 with Property

use of org.whole.lang.pojo.model.Property in project whole by wholeplatform.

the class PojoUtils method translate.

public static void translate(IEntity fromEntity, Object toObject, PojoDeclaration pojoDeclaration, Library library) {
    // translate inherited properties
    IEntityIterator<ReferenceType> superPojosIterator = IteratorFactory.<ReferenceType>childIterator();
    superPojosIterator.reset(pojoDeclaration.getTypes());
    for (ReferenceType superType : superPojosIterator) {
        PojoDeclaration superDeclaration = (PojoDeclaration) findProductDeclaration(superType, library);
        translate(fromEntity, toObject, superDeclaration, library);
    }
    // translate declared properties
    IEntityIterator<Property> iterator = IteratorFactory.<Property>childIterator();
    iterator.reset(pojoDeclaration.getProperties());
    EntityDescriptor<?> ed = fromEntity.wGetEntityDescriptor();
    Property property = null;
    try {
        while (iterator.hasNext()) {
            property = iterator.next();
            if (isReadOnly(property))
                continue;
            Type type = property.getType();
            Name template = property.getTemplate();
            FeatureDescriptor fd = ed.getFeatureDescriptorEnum().valueOf(template.wStringValue());
            IEntity fieldEntity = fromEntity.wGet(fd);
            if (!EntityUtils.isNotResolver(fieldEntity))
                continue;
            if (Matcher.match(PrimitiveType, type))
                setPropertyValue(property, toObject, fieldEntity.wGetValue());
            else
                setPropertyValue(property, toObject, create(fieldEntity, library));
        }
    } catch (Exception e) {
        throw new IllegalStateException("Cannot translate property: " + property, e);
    }
}
Also used : PojoDeclaration(org.whole.lang.pojo.reflect.PojoEntityDescriptorEnum.PojoDeclaration) PojoDeclaration(org.whole.lang.pojo.model.PojoDeclaration) PrimitiveType(org.whole.lang.pojo.model.PrimitiveType) PrimitiveType(org.whole.lang.pojo.reflect.PojoEntityDescriptorEnum.PrimitiveType) Type(org.whole.lang.pojo.model.Type) MapType(org.whole.lang.pojo.model.MapType) ArrayType(org.whole.lang.pojo.model.ArrayType) ReferenceType(org.whole.lang.pojo.reflect.PojoEntityDescriptorEnum.ReferenceType) CollectionType(org.whole.lang.pojo.model.CollectionType) ReferenceType(org.whole.lang.pojo.model.ReferenceType) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) IEntity(org.whole.lang.model.IEntity) Property(org.whole.lang.pojo.model.Property) ReferenceType(org.whole.lang.pojo.reflect.PojoEntityDescriptorEnum.ReferenceType) ReferenceType(org.whole.lang.pojo.model.ReferenceType) InvocationTargetException(java.lang.reflect.InvocationTargetException) Name(org.whole.lang.pojo.model.Name)

Example 5 with Property

use of org.whole.lang.pojo.model.Property in project whole by wholeplatform.

the class PropertyPart method getModelSpecificChildren.

protected List<IEntity> getModelSpecificChildren() {
    Property property = getModelEntity();
    List<IEntity> list = new ArrayList<IEntity>(4);
    list.add(property.getAnnotations());
    list.add(property.getType());
    list.add(property.getName());
    list.add(property.getTemplate());
    return list;
}
Also used : IEntity(org.whole.lang.model.IEntity) ArrayList(java.util.ArrayList) Property(org.whole.lang.pojo.model.Property)

Aggregations

Property (org.whole.lang.pojo.model.Property)5 IEntity (org.whole.lang.model.IEntity)3 Name (org.whole.lang.pojo.model.Name)3 ArrayList (java.util.ArrayList)2 ArrayType (org.whole.lang.pojo.model.ArrayType)2 CollectionType (org.whole.lang.pojo.model.CollectionType)2 MapType (org.whole.lang.pojo.model.MapType)2 PojoDeclaration (org.whole.lang.pojo.model.PojoDeclaration)2 PrimitiveType (org.whole.lang.pojo.model.PrimitiveType)2 ReferenceType (org.whole.lang.pojo.model.ReferenceType)2 Type (org.whole.lang.pojo.model.Type)2 PrimitiveType (org.whole.lang.pojo.reflect.PojoEntityDescriptorEnum.PrimitiveType)2 ReferenceType (org.whole.lang.pojo.reflect.PojoEntityDescriptorEnum.ReferenceType)2 FeatureDescriptor (org.whole.lang.reflect.FeatureDescriptor)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 IBindingManager (org.whole.lang.bindings.IBindingManager)1 Constructor (org.whole.lang.pojo.model.Constructor)1 Declaration (org.whole.lang.pojo.model.Declaration)1 Parameter (org.whole.lang.pojo.model.Parameter)1 ProductDeclaration (org.whole.lang.pojo.model.ProductDeclaration)1