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);
}
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);
}
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)));
}
}
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();
}
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);
}
Aggregations