use of org.whole.lang.reflect.FeatureDescriptor in project whole by wholeplatform.
the class QueriesUtils method sort.
public static IEntity sort(IEntity entity) {
if (entity.wGetEntityDescriptor().getCompositeKind().isOrdered()) {
List<IEntity> entityList = (List<IEntity>) entity;
IEntity[] array = entityList.toArray(new IEntity[entity.wSize()]);
entityList.clear();
Arrays.sort(array, new Comparator<IEntity>() {
public int compare(IEntity e1, IEntity e2) {
IEntity e1Adaptee = e1.wGetAdaptee(false);
IEntity e2Adaptee = e2.wGetAdaptee(false);
EntityDescriptor<?> e1Ed = e1Adaptee.wGetEntityDescriptor();
EntityDescriptor<?> e2Ed = e2Adaptee.wGetEntityDescriptor();
if (e1Ed != e2Ed)
return 0;
switch(e1Ed.getEntityKind()) {
case DATA:
return DataTypeUtils.compare(e1Adaptee, e2Adaptee);
default:
case COMPOSITE:
return 0;
case SIMPLE:
boolean idBased = false;
List<FeatureDescriptor> entityFeatureDescriptors = e1Ed.getEntityFeatureDescriptors();
for (FeatureDescriptor fd : entityFeatureDescriptors) {
if (fd.isId()) {
idBased = true;
int result = compare(e1Adaptee.wGet(fd), e2Adaptee.wGet(fd));
if (result != 0)
return result;
}
}
if (idBased)
return 0;
for (FeatureDescriptor fd : entityFeatureDescriptors) {
int result = compare(e1Adaptee.wGet(fd), e2Adaptee.wGet(fd));
if (result != 0)
return result;
}
return 0;
}
}
});
for (IEntity child : array) entity.wAdd(child);
return entity;
} else
return entity;
}
use of org.whole.lang.reflect.FeatureDescriptor in project whole by wholeplatform.
the class JSONLDEntityDecoder method decode.
public IEntity decode(org.whole.lang.json.model.Object jsonEntity) {
String edUri = null;
Value body = jsonEntity;
for (int i = 0; i < jsonEntity.size(); i++) {
Pair pair = jsonEntity.get(i);
String name = pair.getName().getValue();
if (name.equals("@type"))
edUri = pair.getValue().wStringValue();
else if (name.equals("@list") || name.equals("@set") || name.equals("@value"))
body = pair.getValue();
}
if (edUri == null)
return super.applyRules(jsonEntity);
EntityDescriptor<?> ed = CommonsDataTypePersistenceParser.getEntityDescriptor(edUri, true, null);
IEntityFactory ef = GenericEntityFactory.instance(RegistryConfigurations.RESOLVER);
IEntity entity = ef.create(ed);
switch(ed.getEntityKind()) {
case SIMPLE:
FeatureDescriptorEnum fdEnum = ed.getFeatureDescriptorEnum();
for (int i = 0; i < body.wSize(); i++) {
Pair pair = (Pair) body.wGet(i);
String name = pair.getName().getValue();
if (!name.startsWith("@")) {
FeatureDescriptor fd = fdEnum.valueOf(name);
entity.wSet(fd, applyRules(pair.getValue()));
}
}
break;
case COMPOSITE:
for (int i = 0; i < body.wSize(); i++) entity.wAdd(applyRules(body.wGet(i)));
break;
case DATA:
DataTypeUtils.convert(body, entity);
}
return entity;
}
use of org.whole.lang.reflect.FeatureDescriptor in project whole by wholeplatform.
the class WorkflowsInterpreterVisitor method visit.
@Override
public void visit(CreateEntity entity) {
try {
entity.getEntityName().accept(this);
String typeName = getResultString();
EntityDescriptor<?> ed = CommonsDataTypePersistenceParser.parseEntityDescriptor(typeName);
if (ed == null)
throw new WholeIllegalArgumentException("The requested entity does not exist: " + typeName).withSourceEntity(entity).withBindings(getBindings());
IEntityRegistryProvider provider = null;
switch(entity.getRegistry().getValue().getOrdinal()) {
case RegistryEnum.DEFAULT_ord:
provider = RegistryConfigurations.DEFAULT;
break;
case RegistryEnum.RESOLVER_ord:
provider = RegistryConfigurations.RESOLVER;
break;
case RegistryEnum.ADAPTER_ord:
provider = RegistryConfigurations.ADAPTER;
break;
case RegistryEnum.STRICT_ord:
provider = RegistryConfigurations.STRICT;
break;
case RegistryEnum.CUSTOM_ord:
provider = RegistryConfigurations.CUSTOM;
break;
}
IEntityFactory ef = GenericEntityFactory.instance(provider);
IEntity model;
Arguments arguments = entity.getArguments();
if (Matcher.matchImpl(WorkflowsEntityDescriptorEnum.Assignments, arguments)) {
ITransactionScope resettableScope = BindingManagerFactory.instance.createTransactionScope();
getBindings().wEnterScope(resettableScope);
arguments.accept(this);
for (int i = 0; i < arguments.wSize(); i++) {
String name = ((Assignments) arguments).get(i).getName().getValue();
FeatureDescriptor fd = ed.getFeatureDescriptorEnum().valueOf(name);
if (fd != null)
getBindings().wDef(name, EntityUtils.convertCloneIfReparenting(getBindings().wGet(name), ed.getEntityFeatureDescriptor(fd)));
}
model = ef.create(ed, getBindings());
resettableScope.rollback();
getBindings().wExitScope();
} else if (Matcher.matchImpl(WorkflowsEntityDescriptorEnum.Expressions, arguments)) {
IEntity selfEntity = getBindings().wGet("self");
if (ed.getEntityKind().isData()) {
((Expressions) arguments).get(0).accept(this);
model = DataTypeUtils.convertCloneIfParented(getResult(), ed);
resetSelfEntity(selfEntity);
} else {
IEntity[] values = new IEntity[arguments.wSize()];
for (int i = 0; i < values.length; i++) {
((Expressions) arguments).get(i).accept(this);
values[i] = EntityUtils.convertCloneIfReparenting(getResult(), ed.getEntityFeatureDescriptor(i));
resetSelfEntity(selfEntity);
}
model = ef.create(ed, values);
}
} else
model = ef.create(ed);
setResult(entity.getModel(), model);
} catch (Exception e) {
throw IWholeRuntimeException.asWholeException(e, entity, getBindings());
}
}
use of org.whole.lang.reflect.FeatureDescriptor in project whole by wholeplatform.
the class ReflectLibraryDeployer method getFeatureDescriptor.
public static FeatureDescriptor getFeatureDescriptor(IEntity selfEntity, IBindingManager bm) {
FeatureDescriptor fd = null;
if (DataTypeUtils.getDataKind(selfEntity).isString()) {
String uri = selfEntity.wStringValue();
if (ResourceUtils.hasFragmentPart(uri)) {
String languageUri = ResourceUtils.stripFragmentPart(uri);
String descriptorName = ResourceUtils.getFragmentPart(uri);
ILanguageKit languageKit = ReflectionFactory.safeGetLanguageKit(languageUri, true, bm);
if (languageKit != null)
fd = languageKit.getFeatureDescriptorEnum().valueOf(descriptorName);
}
} else if (DataTypeUtils.getDataKind(selfEntity).isEnumValue() && selfEntity.wEnumValue() instanceof FeatureDescriptor)
fd = (FeatureDescriptor) selfEntity.wEnumValue();
else if (DataTypeUtils.getDataKind(selfEntity).isObject() && selfEntity.wGetValue() instanceof FeatureDescriptor)
fd = (FeatureDescriptor) selfEntity.wGetValue();
return fd;
}
use of org.whole.lang.reflect.FeatureDescriptor in project whole by wholeplatform.
the class ReflectLibraryDeployer method setFeatureDescriptorResult.
public static void setFeatureDescriptorResult(IBindingManager bm, EntityDescriptor<?> ed) {
FeatureDescriptor fd = bm.wIsSet("feature") ? getFeatureDescriptor(bm.wGet("feature"), bm) : null;
String featureName = fd == null && bm.wIsSet("featureName") ? bm.wStringValue("featureName") : null;
int featureIndex = fd == null && featureName == null && bm.wIsSet("featureIndex") ? bm.wIntValue("featureIndex") : -1;
FeatureDescriptor lfd = null;
if (fd != null) {
if (fd.getLanguageKit().equals(ed.getLanguageKit()))
lfd = fd;
else
featureName = fd.getName();
}
if (featureName != null)
lfd = ed.getFeatureDescriptorEnum().valueOf(featureName);
FeatureDescriptor efd = null;
if (lfd != null)
featureIndex = ed.indexOf(lfd);
if (featureIndex > -1 && featureIndex < ed.featureSize())
efd = ed.getEntityFeatureDescriptor(featureIndex);
bm.setResult(efd != null ? BindingManagerFactory.instance.createValue(efd) : null);
}
Aggregations