Search in sources :

Example 1 with Parameter

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

the class PojoNormalizerVisitor method createDefaultTypeInParameters.

public static void createDefaultTypeInParameters(Library entity, IBindingManager bindings) {
    Path findAllParametersWithoutType = (Path) PojoTemplateManager.instance().create("findAllParametersWithoutType");
    Path findParameterType = (Path) PojoTemplateManager.instance().create("findPropertyType");
    bindings.wEnterScope();
    for (Parameter parameter : BehaviorUtils.<Parameter>compileAndLazyEvaluate(findAllParametersWithoutType, entity, bindings)) {
        PojoDeclaration pojo = (PojoDeclaration) bindings.wGet("pojo");
        Type type = BehaviorUtils.<Type>evaluateFirstResult(findParameterType, pojo, bindings);
        if (type != null)
            parameter.setType(EntityUtils.clone(type));
        else
            throw new IllegalArgumentException("Missing " + bindings.wStringValue("name") + " property in " + pojo.getName().wStringValue() + " pojo declaration");
    }
    bindings.wExitScope();
}
Also used : Path(org.whole.lang.queries.model.Path) PojoDeclaration(org.whole.lang.pojo.model.PojoDeclaration) MapType(org.whole.lang.pojo.model.MapType) ArrayType(org.whole.lang.pojo.model.ArrayType) PrimitiveType(org.whole.lang.pojo.model.PrimitiveType) Type(org.whole.lang.pojo.model.Type) CollectionType(org.whole.lang.pojo.model.CollectionType) ReferenceType(org.whole.lang.pojo.model.ReferenceType) Parameter(org.whole.lang.pojo.model.Parameter)

Example 2 with Parameter

use of org.whole.lang.pojo.model.Parameter 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 3 with Parameter

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

the class PojoNormalizerVisitor method createDefaultTemplateInParameters.

public static void createDefaultTemplateInParameters(Library entity, IBindingManager bindings) {
    Path findAllParametersWithoutTemlate = (Path) PojoTemplateManager.instance().create("findAllParametersWithoutTemlate");
    Path findParameterTemplate = (Path) PojoTemplateManager.instance().create("findPropertyTemplate");
    bindings.wEnterScope();
    for (Parameter parameter : BehaviorUtils.<Parameter>compileAndLazyEvaluate(findAllParametersWithoutTemlate, entity, bindings)) {
        PojoDeclaration pojo = (PojoDeclaration) bindings.wGet("pojo");
        Name name = BehaviorUtils.<Name>evaluateFirstResult(findParameterTemplate, pojo, bindings);
        if (name != null)
            parameter.setTemplate(EntityUtils.clone(name));
    }
    bindings.wExitScope();
}
Also used : Path(org.whole.lang.queries.model.Path) PojoDeclaration(org.whole.lang.pojo.model.PojoDeclaration) Parameter(org.whole.lang.pojo.model.Parameter) Name(org.whole.lang.pojo.model.Name)

Example 4 with Parameter

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

the class ParameterPart method getModelSpecificChildren.

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

Aggregations

Parameter (org.whole.lang.pojo.model.Parameter)4 ArrayList (java.util.ArrayList)2 IEntity (org.whole.lang.model.IEntity)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 Name (org.whole.lang.pojo.model.Name)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 Path (org.whole.lang.queries.model.Path)2 IBindingManager (org.whole.lang.bindings.IBindingManager)1 Constructor (org.whole.lang.pojo.model.Constructor)1 Property (org.whole.lang.pojo.model.Property)1 PrimitiveType (org.whole.lang.pojo.reflect.PojoEntityDescriptorEnum.PrimitiveType)1 ReferenceType (org.whole.lang.pojo.reflect.PojoEntityDescriptorEnum.ReferenceType)1 Expression (org.whole.lang.queries.model.Expression)1 PathExpression (org.whole.lang.queries.model.PathExpression)1 FeatureDescriptor (org.whole.lang.reflect.FeatureDescriptor)1