use of org.whole.lang.reflect.EntityDescriptor in project whole by wholeplatform.
the class FramesContentAssistVisitor method allEntityTypes.
private boolean allEntityTypes(IEntity entity, EntityDescriptor<?> type) {
if (!EntityUtils.hasParent(entity))
return false;
boolean subtypeTest = false;
ActionsUIEntityFactory aef = ActionsUIEntityFactory.instance;
GroupAction languagesGroup = aef.createGroupAction();
languagesGroup.setFillStrategy(aef.createHierarchical(aef.createDistinctPrefix(), aef.createSize(10)));
languagesGroup.getText().setValue("frames.languages");
Actions actions = aef.createActions(0);
FramesEntityFactory fef = FramesEntityFactory.instance;
String actualLanguageURI = "";
String actualEntityName = "";
EntityDescriptor<?> actualED = null;
EntityDescriptor<?> targetED = type;
try {
actualED = CommonsDataTypePersistenceParser.parseEntityDescriptor(entity.wStringValue());
actualLanguageURI = actualED.getLanguageKit().getURI();
actualEntityName = actualED.getName();
} catch (Exception e) {
if (DataTypeUtils.getDataKind(entity).isString())
actualEntityName = entity.wStringValue();
}
IResourceRegistry<ILanguageKit> registry = ReflectionFactory.getLanguageKitRegistry();
for (ILanguageKit languageKit : registry.getResources(false, ResourceUtils.SIMPLE_COMPARATOR)) {
if (languageKit.getURI().equals(actualLanguageURI))
continue;
EntityDescriptorEnum edEnum = languageKit.getEntityDescriptorEnum();
EntityDescriptor<?> ed = null;
if (actualEntityName.length() > 0)
ed = edEnum.valueOf(actualEntityName);
if (ed == null) {
if (subtypeTest)
ed = edEnum.valueOf(0);
else {
Iterator<EntityDescriptor<?>> iterator = edEnum.values().iterator();
EntityDescriptor<?> nextED;
while (ed == null && iterator.hasNext()) if (!(nextED = iterator.next()).isAbstract())
ed = nextED;
if (ed == null)
continue;
}
}
IEntity prototype = fef.create(targetED, CommonsDataTypePersistenceParser.unparseEntityDescriptor(ed));
actions.wAdd(aef.createReplaceDifferentTemplateAction(prototype, ResourceUtils.SIMPLE_NAME_PROVIDER.toString(registry, languageKit), IActionConstants.SELECT_LANGUAGE_ICON));
}
languagesGroup.setActions(actions);
boolean addedLanguages = EntityUtils.isResolver(entity) ? mergeResult(targetED, languagesGroup) : mergeResult(languagesGroup);
if (actualED != null) {
GroupAction typenamesGroup = aef.createGroupAction();
typenamesGroup.setFillStrategy(aef.createHierarchical(aef.createDistinctPrefix(), aef.createSize(10)));
typenamesGroup.getText().setValue(subtypeTest ? "frames.subtypenames" : "frames.typenames");
actions = aef.createActions(0);
EntityDescriptorEnum edEnum = actualED.getEntityDescriptorEnum();
List<EntityDescriptor<?>> eds = new ArrayList<EntityDescriptor<?>>(edEnum.values());
Collections.sort(eds, EnumValueImpl.getByNameComparator());
for (EntityDescriptor<?> ed : eds) {
if (ed.equals(actualED) || (!subtypeTest && ed.isAbstract()))
continue;
IEntity prototype = fef.create(targetED, CommonsDataTypePersistenceParser.unparseEntityDescriptor(ed));
actions.wAdd(aef.createReplaceDifferentTemplateAction(prototype, ed.getName()));
}
typenamesGroup.setActions(actions);
addedLanguages |= EntityUtils.isResolver(entity) ? mergeResult(targetED, typenamesGroup) : mergeResult(typenamesGroup);
}
return addedLanguages;
}
use of org.whole.lang.reflect.EntityDescriptor in project whole by wholeplatform.
the class DataTypePersistenceKit method doReadModel.
@Override
protected IEntity doReadModel(IPersistenceProvider pp) throws Exception {
EntityDescriptor<?> ed = null;
IBindingManager bindings = pp.getBindings();
if (bindings.wIsSet("entityDescriptor"))
ed = (EntityDescriptor<?>) bindings.wGetValue("entityDescriptor");
else if (bindings.wIsSet("entityDescriptorName")) {
String edName = bindings.wStringValue("entityDescriptorName");
ed = CommonsDataTypePersistenceParser.parseEntityDescriptor(edName);
}
String data = StringUtils.readAsString(pp.getInputStream(), pp.getEncoding());
if (ed != null)
return DataTypeUtils.createFromPersistenceString(ed, data);
else
return BindingManagerFactory.instance.createValue(data);
}
use of org.whole.lang.reflect.EntityDescriptor in project whole by wholeplatform.
the class HandlersBehavior method canAddEntity.
public static boolean canAddEntity(IBindingManager bm) {
if (!isValidFocusEntityPart(bm))
return false;
IEntity focusEntity = bm.wGet("focusEntity");
EntityDescriptor<?> ed = (EntityDescriptor<?>) bm.wGetValue("entityDescriptor");
if (bm.wIsSet("featureDescriptor"))
focusEntity = focusEntity.wGet((FeatureDescriptor) bm.wGetValue("featureDescriptor"));
return EntityUtils.isAddable(focusEntity, ed);
}
use of org.whole.lang.reflect.EntityDescriptor in project whole by wholeplatform.
the class HandlersBehavior method canReplaceEntity.
public static boolean canReplaceEntity(IBindingManager bm) {
if (!isValidFocusEntityPart(bm))
return false;
IEntity primarySelectedEntity = bm.wGet("focusEntity");
EntityDescriptor<?> ed = (EntityDescriptor<?>) bm.wGetValue("entityDescriptor");
if (bm.wIsSet("featureDescriptor"))
primarySelectedEntity = primarySelectedEntity.wGet((FeatureDescriptor) bm.wGetValue("featureDescriptor"));
return EntityUtils.isReplaceable(primarySelectedEntity, ed);
}
use of org.whole.lang.reflect.EntityDescriptor in project whole by wholeplatform.
the class EntityDescriptorEnumBuilder method addMapEntity.
@SuppressWarnings("unchecked")
public void addMapEntity(String eType, String name, Set<String> modifiers, String keyType, String valueType) {
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;
// putMapEntity([eName_ord], "[eName]", [eType].class, ElementType_ord);
MethodInvocation callExp = newMethodInvocation("putMapEntity");
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));
callExp.arguments().add(ast.newSimpleName(generator.entityResolverSimpleName(keyType) + "_ord"));
callExp.arguments().add(ast.newSimpleName(generator.entityResolverSimpleName(valueType) + "_ord"));
ExpressionStatement expStm = newExpressionStatement(callExp);
initEntityDescriptors.getBody().statements().add(expStm);
etypeExpressionMap.put(eType, expStm);
}
Aggregations