use of org.whole.lang.factories.IEntityFactory 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.factories.IEntityFactory 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.factories.IEntityFactory in project whole by wholeplatform.
the class ReflectionServer method createEntity.
public <E extends IEntity> E createEntity(EntityDescriptor<E> ed) {
IEntityFactory ef = GenericEntityFactory.instance;
E entity = ef.create(ed);
// TODO add reflectionServer to entity compound model
// TODO ? set pid and put in pidInstanceMap or put in rootInstances and lazy set pid in AbstractEntiy
getPid(entity);
return entity;
}
use of org.whole.lang.factories.IEntityFactory in project whole by wholeplatform.
the class BindingManagerFactory method createNames.
public IEntity createNames(Set<String> includeNames) {
IEntityFactory ef = GenericEntityFactory.instance;
IEntity names = ef.create(getEdEnum().valueOf("Names"));
for (String name : includeNames) names.wAdd(ef.create(getEdEnum().valueOf("Name"), name));
return names;
}
use of org.whole.lang.factories.IEntityFactory in project whole by wholeplatform.
the class BindingManagerFactory method createFlatBindingsModel.
public IEntity createFlatBindingsModel(IBindingManager bm, Set<String> includeNames) {
IEntityFactory ef = GenericEntityFactory.instance;
IEntity bindings = ef.create(getEdEnum().valueOf("Bindings"));
Set<String> names = bm.wNames();
for (String name : new TreeSet<String>(includeNames)) bindings.wAdd(createBinding(name, names.contains(name) ? bm.wGet(name) : CommonsEntityFactory.instance.createResolver()));
return bindings;
}
Aggregations