use of org.whole.lang.reflect.FeatureDescriptor in project whole by wholeplatform.
the class AbstractEntityRegistryConfiguration method enforceMandatoryFeatures.
public static void enforceMandatoryFeatures(IEntityRegistry er, EntityDescriptor<?> ed, IEntity prototype, boolean[] isEnforced) {
if (isEnforced[ed.getOrdinal()])
return;
isEnforced[ed.getOrdinal()] = true;
if (ed.getEntityKind().isSimple()) {
List<FeatureDescriptor> eds = ed.getEntityFeatureDescriptors();
for (int i = 0, size = eds.size(); i < size; i++) {
FeatureDescriptor efd = eds.get(i);
EntityDescriptor<?> fed = efd.getEntityDescriptor();
if (fed.isPolymorphic() || efd.isOptional() || efd.isReference())
continue;
IEntity child = prototype.wGet(i);
if (!EntityUtils.isResolver(child))
continue;
if (fed.isAbstract())
continue;
child = er.get(fed);
enforceMandatoryFeatures(er, fed, child, isEnforced);
child = EntityUtils.clone(child);
prototype.wSet(i, child);
// if (fed.getEntityKind().isComposite() && !fed.getEntityFeatureDescriptor(0).isOptional())
// try {
// child.wAdd(CommonsEntityAdapterFactory.createResolver(fed.getEntityDescriptor(0)));
// } catch (UnsupportedOperationException e) {
// //FIXME workaround for Map entity
// }
}
// } else if (ed.getEntityKind().isComposite() && !ed.getEntityFeatureDescriptor(0).isOptional()) {
// try {
// prototype.wAdd(CommonsEntityAdapterFactory.createResolver(ed.getEntityDescriptor(0)));
// } catch (UnsupportedOperationException e) {
// //FIXME workaround for Map entity
// }
}
}
use of org.whole.lang.reflect.FeatureDescriptor in project whole by wholeplatform.
the class EntityUtils method setCloneIfReparenting.
public static final void setCloneIfReparenting(IEntity entity, FeatureDescriptor fd, IEntity value) {
FeatureDescriptor efd = fd.isEntityFeatureDescriptor() ? fd : entity.wGetEntityDescriptor().getEntityFeatureDescriptor(fd);
entity.wSet(fd, cloneIfReparenting(value, efd.isReference()));
}
use of org.whole.lang.reflect.FeatureDescriptor 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.FeatureDescriptor in project whole by wholeplatform.
the class InterpreterOperation method interpret.
public static IBindingScope interpret(IEntity program, IBindingManager args, Reader in, Writer out) {
final Set<String> newIONames = new HashSet<String>();
if (!args.wIsSet("reader"))
newIONames.add("reader");
if (!args.wIsSet("writer"))
newIONames.add("writer");
if (!args.wIsSet("printWriter"))
newIONames.add("printWriter");
final InterpreterOperation op = new InterpreterOperation(args, null);
if (in != null)
args.wDefValue("reader", op.reader = in);
else if (!args.wIsSet("reader")) {
args.wDefValue("reader", (Object) null);
args.wGet("reader").wAddRequestEventHandler(new IdentityRequestEventHandler() {
public Object notifyRequested(IEntity source, FeatureDescriptor feature, Object value) {
return op.getReader();
}
});
} else
op.reader = (Reader) args.wGetValue("reader");
if (out != null) {
args.wDefValue("writer", op.writer = out);
if (out instanceof PrintWriter)
args.wDefValue("printWriter", op.printWriter = (PrintWriter) out);
} else {
if (args.wIsSet("printWriter"))
op.writer = op.printWriter = (PrintWriter) args.wGetValue("printWriter");
if (args.wIsSet("writer"))
op.writer = (Writer) args.wGetValue("writer");
else {
args.wDefValue("writer", (Object) null);
args.wGet("writer").wAddRequestEventHandler(new IdentityRequestEventHandler() {
public Object notifyRequested(IEntity source, FeatureDescriptor feature, Object value) {
return op.getWriter();
}
});
}
}
if (!args.wIsSet("printWriter")) {
args.wDefValue("printWriter", (Object) null);
args.wGet("printWriter").wAddRequestEventHandler(new IdentityRequestEventHandler() {
public Object notifyRequested(IEntity source, FeatureDescriptor feature, Object value) {
return op.getPrintWriter();
}
});
}
op.stagedVisit(program);
for (String name : newIONames) args.wUnset(name);
op.flushPrintWriter();
return op.getResultsScope();
}
use of org.whole.lang.reflect.FeatureDescriptor in project whole by wholeplatform.
the class ArtifactsUtils method cloneArtifact.
public static IEntity cloneArtifact(IEntity artifact, IEntity appendChild) {
IEntityFactory ef = GenericEntityFactory.instance(RegistryConfigurations.RESOLVER);
EntityDescriptor<?> ed = artifact.wGetEntityDescriptor();
IEntity newArtifact = ef.create(ed);
for (FeatureDescriptor fd : ed.getEntityFeatureDescriptors()) {
if (artifacts.equals(fd) || projects.equals(fd)) {
IEntity composite = newArtifact.wGet(fd);
if (appendChild != null)
composite.wAdd(appendChild);
else
composite.wResolveWith(fd.getEntityDescriptor());
} else
newArtifact.wSet(fd, EntityUtils.clone(artifact.wGet(fd)));
}
return newArtifact;
}
Aggregations