Search in sources :

Example 1 with Name

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

the class PojoUtils method getReadOnlyFields.

public static Set<Name> getReadOnlyFields(PojoDeclaration pojoDeclaration) {
    Set<Name> readOnlyFields = new HashSet<Name>();
    IBindingManager bindings = BindingManagerFactory.instance.createArguments();
    Expression findAllReadOnlyFields = (Expression) PojoTemplateManager.instance().create("findAllReadOnlyFields");
    for (Name readOnlyField : BehaviorUtils.<Name>compileAndLazyEvaluate(findAllReadOnlyFields, pojoDeclaration, bindings)) readOnlyFields.add(readOnlyField);
    return readOnlyFields;
}
Also used : 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) HashSet(java.util.HashSet)

Example 2 with Name

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

the class PojoUtils method findConstructor.

public static Constructor findConstructor(PojoDeclaration pojoDeclaration) {
    IBindingManager bindings = BindingManagerFactory.instance.createArguments();
    Expression findParameterByTemplate = (Expression) PojoTemplateManager.instance().create("findParameterByTemplate");
    List<Constructor> constructors = getConstructors(pojoDeclaration);
    int[] supportedFields = new int[constructors.size()];
    Expression findAllReadOnlyFields = (Expression) PojoTemplateManager.instance().create("findAllReadOnlyFields");
    IEntityIterator<Name> iterator = BehaviorUtils.<Name>compileAndLazyEvaluate(findAllReadOnlyFields, pojoDeclaration, bindings);
    int readOnlyFieldCount = 0;
    while (iterator.hasNext()) {
        iterator.next();
        for (int i = 0; i < supportedFields.length; i++) if (BehaviorUtils.evaluateFirstResult(findParameterByTemplate, constructors.get(i), bindings) != null)
            supportedFields[i]++;
        readOnlyFieldCount++;
    }
    for (int i = 0; i < supportedFields.length; i++) if (supportedFields[i] >= readOnlyFieldCount)
        return constructors.get(i);
    return constructors.get(supportedFields.length - 1);
}
Also used : Expression(org.whole.lang.queries.model.Expression) PathExpression(org.whole.lang.queries.model.PathExpression) Constructor(org.whole.lang.pojo.model.Constructor) IBindingManager(org.whole.lang.bindings.IBindingManager) Name(org.whole.lang.pojo.model.Name)

Example 3 with Name

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

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

the class PojoArtifactsGeneratorVisitor method visit.

@Override
public void visit(Library library) {
    Name libraryName = library.getName();
    if (!EntityUtils.isNotResolver(libraryName))
        throw new VisitException("No library name");
    String modelFileName = DataTypeUtils.getAsPersistenceString(libraryName) + "Model";
    Model model = PojoMappingUtils.getModel(library);
    env().wDefValue("modelFileName", modelFileName);
    env().wDef("modelFileContent", model);
    IEntity ws = ModelsArtifactsTemplateManager.instance().create("ModelFileArtifact");
    Matcher.substitute(ws, env(), false);
    ArtifactsUtils.moveArtifactsIntoWorkspace(ws, env());
}
Also used : IEntity(org.whole.lang.model.IEntity) VisitException(org.whole.lang.visitors.VisitException) Model(org.whole.lang.models.model.Model) Name(org.whole.lang.pojo.model.Name)

Example 5 with Name

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

Name (org.whole.lang.pojo.model.Name)10 IBindingManager (org.whole.lang.bindings.IBindingManager)4 Expression (org.whole.lang.queries.model.Expression)4 PathExpression (org.whole.lang.queries.model.PathExpression)4 IEntity (org.whole.lang.model.IEntity)3 ArrayType (org.whole.lang.pojo.model.ArrayType)3 CollectionType (org.whole.lang.pojo.model.CollectionType)3 MapType (org.whole.lang.pojo.model.MapType)3 PrimitiveType (org.whole.lang.pojo.model.PrimitiveType)3 Property (org.whole.lang.pojo.model.Property)3 ReferenceType (org.whole.lang.pojo.model.ReferenceType)3 Type (org.whole.lang.pojo.model.Type)3 PrimitiveType (org.whole.lang.pojo.reflect.PojoEntityDescriptorEnum.PrimitiveType)3 ReferenceType (org.whole.lang.pojo.reflect.PojoEntityDescriptorEnum.ReferenceType)3 Field (java.lang.reflect.Field)2 Method (java.lang.reflect.Method)2 Constructor (org.whole.lang.pojo.model.Constructor)2 Parameter (org.whole.lang.pojo.model.Parameter)2 PojoDeclaration (org.whole.lang.pojo.model.PojoDeclaration)2 Path (org.whole.lang.queries.model.Path)2