Search in sources :

Example 1 with EntityDescriptor

use of org.whole.lang.reflect.EntityDescriptor in project whole by wholeplatform.

the class EntityDescriptorEnumBuilder method addCompositeEntity.

@SuppressWarnings("unchecked")
public void addCompositeEntity(String eName, String name, String eType, Set<String> modifiers, String elementType, Set<String> compositeModifiers) {
    // String eName = StringUtils.toSimpleName(eType);
    String eName_Ord = eName + "_ord";
    String oldType = entities.put(eName, eType);
    if (oldType == null) {
        // public static final int [eName_ord] = [nextOrdinal];
        FieldDeclaration fieldDecl = newFieldDeclaration("int", eName_Ord, newLiteral(nextOrdinal));
        // assume ModifierKeyword.PRIVATE_KEYWORD
        fieldDecl.modifiers().remove(0);
        fieldDecl.modifiers().add(ast.newModifier(ModifierKeyword.PUBLIC_KEYWORD));
        fieldDecl.modifiers().add(ast.newModifier(ModifierKeyword.STATIC_KEYWORD));
        fieldDecl.modifiers().add(ast.newModifier(ModifierKeyword.FINAL_KEYWORD));
        addBodyDeclaration(nextOrdinal++, fieldDecl);
        // public static final EntityDescriptor<eName> [eName] = (EntityDescriptor<eName>) instance.valueOf([eName_ord]);
        fieldDecl = newFieldDeclaration(newParameterizedType(EntityDescriptor.class.getName(), eName), newVariableDeclarationFragment(eName, newCastExpression(newParameterizedType(EntityDescriptor.class.getName(), eName), newMethodInvocation("instance", "valueOf", ast.newSimpleName(eName_Ord)))));
        // assume ModifierKeyword.PRIVATE_KEYWORD
        fieldDecl.modifiers().remove(0);
        fieldDecl.modifiers().add(ast.newModifier(ModifierKeyword.PUBLIC_KEYWORD));
        fieldDecl.modifiers().add(ast.newModifier(ModifierKeyword.STATIC_KEYWORD));
        fieldDecl.modifiers().add(ast.newModifier(ModifierKeyword.FINAL_KEYWORD));
        addBodyDeclaration(nextOrdinal * 2, fieldDecl);
    } else if (oldType.equals(eType))
        return;
    boolean isOrdered = false, isUnique = false, isReference = false, isDerived = false, isShared = false;
    if (compositeModifiers != null) {
        isOrdered = compositeModifiers.contains("ORDERED");
        isUnique = compositeModifiers.contains("UNIQUE");
        isReference = compositeModifiers.contains("REFERENCE");
        isDerived = compositeModifiers.contains("DERIVED");
        isShared = compositeModifiers.contains("SHARED");
    }
    // putCompositeEntity([eName_ord], "[eName]", [eType].class, ElementType_ord);
    MethodInvocation callExp = newMethodInvocation("putCompositeEntity");
    callExp.arguments().add(ast.newSimpleName(eName_Ord));
    callExp.arguments().add(newLiteral(name));
    if (!eName.equals(name))
        callExp.arguments().add(newLiteral(eName));
    callExp.arguments().add(newTypeLiteral(eType));
    callExp.arguments().add(newLiteral(modifiers != null && modifiers.contains("RELATIONSHIP")));
    callExp.arguments().add(ast.newSimpleName(generator.entityResolverSimpleName(elementType) + "_ord"));
    callExp.arguments().add(newLiteral(isOrdered));
    callExp.arguments().add(newLiteral(isUnique));
    if (isReference || isDerived || isShared) {
        callExp.arguments().add(newLiteral(isReference));
        callExp.arguments().add(newLiteral(isDerived));
        callExp.arguments().add(newLiteral(isShared));
    }
    ExpressionStatement expStm = newExpressionStatement(callExp);
    initEntityDescriptors.getBody().statements().add(expStm);
    etypeExpressionMap.put(eType, expStm);
}
Also used : EntityDescriptor(org.whole.lang.reflect.EntityDescriptor) ExpressionStatement(org.eclipse.jdt.core.dom.ExpressionStatement) MethodInvocation(org.eclipse.jdt.core.dom.MethodInvocation) FieldDeclaration(org.eclipse.jdt.core.dom.FieldDeclaration)

Example 2 with EntityDescriptor

use of org.whole.lang.reflect.EntityDescriptor in project whole by wholeplatform.

the class EntityDescriptorEnumBuilder method addDataEntity.

@SuppressWarnings("unchecked")
public void addDataEntity(String eName, String name, String eType, Set<String> modifiers, String fType, String fName) {
    String eName_Ord = eName + "_ord";
    String oldType = entities.put(eName, eType);
    if (oldType == null) {
        // public static final int [eName_ord] = [nextOrdinal];
        FieldDeclaration fieldDecl = newFieldDeclaration("int", eName_Ord, newLiteral(nextOrdinal));
        // assume ModifierKeyword.PRIVATE_KEYWORD
        fieldDecl.modifiers().remove(0);
        fieldDecl.modifiers().add(ast.newModifier(ModifierKeyword.PUBLIC_KEYWORD));
        fieldDecl.modifiers().add(ast.newModifier(ModifierKeyword.STATIC_KEYWORD));
        fieldDecl.modifiers().add(ast.newModifier(ModifierKeyword.FINAL_KEYWORD));
        addBodyDeclaration(nextOrdinal++, fieldDecl);
        // public static final EntityDescriptor<eName> [eName] = (EntityDescriptor<eName>) instance.valueOf([eName_ord]);
        fieldDecl = newFieldDeclaration(newParameterizedType(EntityDescriptor.class.getName(), eName), newVariableDeclarationFragment(eName, newCastExpression(newParameterizedType(EntityDescriptor.class.getName(), eName), newMethodInvocation("instance", "valueOf", ast.newSimpleName(eName_Ord)))));
        // assume ModifierKeyword.PRIVATE_KEYWORD
        fieldDecl.modifiers().remove(0);
        fieldDecl.modifiers().add(ast.newModifier(ModifierKeyword.PUBLIC_KEYWORD));
        fieldDecl.modifiers().add(ast.newModifier(ModifierKeyword.STATIC_KEYWORD));
        fieldDecl.modifiers().add(ast.newModifier(ModifierKeyword.FINAL_KEYWORD));
        addBodyDeclaration(nextOrdinal * 2, fieldDecl);
    } else if (oldType.equals(eType))
        return;
    // putDataEntity([eName_ord], "[eName]", [eType].class);
    MethodInvocation callExp = newMethodInvocation("putDataEntity");
    callExp.arguments().add(ast.newSimpleName(eName_Ord));
    callExp.arguments().add(newLiteral(name));
    if (!eName.equals(name))
        callExp.arguments().add(newLiteral(eName));
    callExp.arguments().add(newTypeLiteral(eType));
    callExp.arguments().add(newLiteral(modifiers != null && modifiers.contains("RELATIONSHIP")));
    // newEnumSetOfExpression(EntityModifiers.class.getName(), modifiers));
    // if (fType.indexOf('.')!=-1 || fType.endsWith("Enum.Value"))
    callExp.arguments().add(newQualifiedTypeLiteral(fType));
    // else
    // callExp.arguments().add(newTypeLiteral(fType));
    ExpressionStatement expStm = newExpressionStatement(callExp);
    initEntityDescriptors.getBody().statements().add(expStm);
    etypeExpressionMap.put(eType, expStm);
}
Also used : EntityDescriptor(org.whole.lang.reflect.EntityDescriptor) ExpressionStatement(org.eclipse.jdt.core.dom.ExpressionStatement) MethodInvocation(org.eclipse.jdt.core.dom.MethodInvocation) FieldDeclaration(org.eclipse.jdt.core.dom.FieldDeclaration)

Example 3 with EntityDescriptor

use of org.whole.lang.reflect.EntityDescriptor in project whole by wholeplatform.

the class DefaultCopyTransformer method transform.

public void transform(IEntity oldEntity, IEntity newEntity) {
    // if (newEntity.wGetEntityDescriptor().equals(oldEntity.wGetEntityDescriptor()))
    // return;
    EntityKinds oldKind = oldEntity.wGetEntityKind();
    EntityKinds newKind = newEntity.wGetEntityKind();
    if ((oldKind.isSimple() && newKind.isSimple()) || (EntityUtils.isVariable(oldEntity) && EntityUtils.isVariable(newEntity))) {
        // TODO workaround
        List<FeatureDescriptor> oldFeatures = oldEntity.wGetEntityDescriptor().getEntityFeatureDescriptors();
        Set<FeatureDescriptor> commonFeatures = new HashSet<FeatureDescriptor>();
        for (FeatureDescriptor fd : newEntity.wGetEntityDescriptor().getEntityFeatureDescriptors()) if (oldFeatures.contains(fd.getFeatureDescriptor()))
            commonFeatures.add(fd);
        for (FeatureDescriptor fd : commonFeatures) {
            IEntity oldChild = oldEntity.wGet(fd.getFeatureDescriptor());
            if (fd.getEntityDescriptor().isPlatformSupertypeOf(oldChild.wGetEntityDescriptor()))
                newEntity.wSet(fd, EntityUtils.clone(oldChild));
        }
    } else if (oldKind.isComposite() && newKind.isComposite()) {
        EntityDescriptor<?> newComponentDescriptor = newEntity.wGetEntityDescriptor(0);
        for (int i = 0, size = oldEntity.wSize(); i < size; i++) {
            IEntity oldChild = oldEntity.wGet(i);
            if (newComponentDescriptor.isPlatformSupertypeOf(oldChild.wGetEntityDescriptor()))
                newEntity.wSet(i, EntityUtils.clone(oldChild));
        }
    } else if (EntityUtils.isFragment(oldEntity) && EntityUtils.isFragment(newEntity)) {
        // TODO workaround
        newEntity.wSet(0, EntityUtils.clone(oldEntity.wGet(0)));
    }
}
Also used : EntityDescriptor(org.whole.lang.reflect.EntityDescriptor) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) IEntity(org.whole.lang.model.IEntity) EntityKinds(org.whole.lang.reflect.EntityKinds) HashSet(java.util.HashSet)

Example 4 with EntityDescriptor

use of org.whole.lang.reflect.EntityDescriptor in project whole by wholeplatform.

the class CompiledMappingStrategy method getUnionEntityMappings.

public Collection<EntityDescriptor<?>> getUnionEntityMappings(EntityDescriptor<?> context) {
    // TODO optimize
    String contextURI = unparseEntityDescriptor(context);
    AbstractPatternFilterIterator<UnionMapping> i2 = IteratorFactory.<UnionMapping>childMatcherIterator().withPattern(UnionMapping);
    i2.reset(strategy.getMappings());
    for (UnionMapping mapping : i2) if (contextURI.equals(mapping.getContextEntityType().getValue())) {
        Types unionTypes = mapping.getUnionTypes();
        int size = unionTypes.wSize();
        List<EntityDescriptor<?>> list = new ArrayList<EntityDescriptor<?>>(size);
        for (int i = 0; i < size; i++) list.add(parseEntityDescriptor(unionTypes.wGet(i).wStringValue()));
        return list;
    }
    return Collections.emptyList();
}
Also used : Types(org.whole.lang.xsd.mapping.model.Types) SchemaDataTypes(org.whole.lang.xsd.parsers.SchemaDataTypes) EntityDescriptor(org.whole.lang.reflect.EntityDescriptor) ArrayList(java.util.ArrayList) List(java.util.List) UnionMapping(org.whole.lang.xsd.mapping.model.UnionMapping)

Example 5 with EntityDescriptor

use of org.whole.lang.reflect.EntityDescriptor in project whole by wholeplatform.

the class CommandFactory method addOverCompositeConstraints.

protected synchronized void addOverCompositeConstraints(final Object[][] dndRules) {
    EnablerPredicateFactory pf = getEnablerPredicateFactory();
    List<IPartRequestHandler> addList = new ArrayList<IPartRequestHandler>(dndRules.length * 3);
    List<IPartRequestHandler> cloneList = new ArrayList<IPartRequestHandler>(dndRules.length * 3);
    List<IPartRequestHandler> shareList = new ArrayList<IPartRequestHandler>(dndRules.length * 3);
    for (Object[] dndRule : dndRules) {
        EntityDescriptor<?> dndED = (EntityDescriptor<?>) dndRule[0];
        EntityDescriptor<?> targetED = (EntityDescriptor<?>) dndRule[1];
        IFeatureTransformer featureTransformer = (IFeatureTransformer) dndRule[2];
        boolean isExecutable = (Boolean) dndRule[3];
        addList.add(new PartRequestHandler(pf.dndSingleOverResolverIn(dndED, targetED), isExecutable ? new ReplaceChildCommandFactory(featureTransformer) : unexecutableFeature));
        cloneList.add(new PartRequestHandler(pf.dndSingleOverResolverIn(dndED, targetED), isExecutable ? new ReplaceChildCommandFactory(CLONE(featureTransformer)) : unexecutableFeature));
        shareList.add(new PartRequestHandler(pf.dndSingleOverResolverIn(dndED, targetED), isExecutable ? new ReplaceChildCommandFactory(SHARE(featureTransformer)) : unexecutableFeature));
        addList.add(new PartRequestHandler(pf.dndOverResolverIn(dndED, targetED), isExecutable ? new CompoundReplaceChildCommandFactory(featureTransformer) : unexecutableFeature));
        cloneList.add(new PartRequestHandler(pf.dndOverResolverIn(dndED, targetED), isExecutable ? new CompoundReplaceChildCommandFactory(CLONE(featureTransformer)) : unexecutableFeature));
        shareList.add(new PartRequestHandler(pf.dndOverResolverIn(dndED, targetED), isExecutable ? new CompoundReplaceChildCommandFactory(SHARE(featureTransformer)) : unexecutableFeature));
        addList.add(new PartRequestHandler(pf.dndOver(dndED, targetED), isExecutable ? new CompositeAddCommandFactory(featureTransformer) : unexecutableFeature));
        cloneList.add(new PartRequestHandler(pf.dndOver(dndED, targetED), isExecutable ? new CompositeAddCommandFactory(CLONE(featureTransformer)) : unexecutableFeature));
        shareList.add(new PartRequestHandler(pf.dndOver(dndED, targetED), isExecutable ? new CompositeAddCommandFactory(SHARE(featureTransformer)) : unexecutableFeature));
    }
    addHandlers(PartRequest.MOVE_ADD_CHILD, addList);
    addHandlers(PartRequest.CLONE_CHILD, cloneList);
    addHandlers(PartRequest.SHARE_CHILD, shareList);
}
Also used : EnablerPredicateFactory(org.whole.lang.ui.actions.EnablerPredicateFactory) ArrayList(java.util.ArrayList) EntityDescriptor(org.whole.lang.reflect.EntityDescriptor)

Aggregations

EntityDescriptor (org.whole.lang.reflect.EntityDescriptor)29 IEntity (org.whole.lang.model.IEntity)13 ArrayList (java.util.ArrayList)9 ILanguageKit (org.whole.lang.reflect.ILanguageKit)7 HashMap (java.util.HashMap)5 EntityDescriptorEnum (org.whole.lang.reflect.EntityDescriptorEnum)5 ExpressionStatement (org.eclipse.jdt.core.dom.ExpressionStatement)4 FieldDeclaration (org.eclipse.jdt.core.dom.FieldDeclaration)4 MethodInvocation (org.eclipse.jdt.core.dom.MethodInvocation)4 Actions (org.whole.lang.actions.model.Actions)3 GroupAction (org.whole.lang.actions.model.GroupAction)3 ActionsUIEntityFactory (org.whole.lang.actions.ui.factories.ActionsUIEntityFactory)3 IBindingManager (org.whole.lang.bindings.IBindingManager)3 FeatureDescriptor (org.whole.lang.reflect.FeatureDescriptor)3 Comparator (java.util.Comparator)2 HashSet (java.util.HashSet)2 List (java.util.List)2 IAction (org.eclipse.jface.action.IAction)2 Test (org.junit.Test)2 Database (org.whole.lang.rdb.model.Database)2