use of org.whole.lang.model.IEntity in project whole by wholeplatform.
the class CompoundResourceRegistry method getFunctionCode.
@SuppressWarnings("unchecked")
public <B extends ICloneable> B getFunctionCode(String functionUri, boolean loadOnDemand, IBindingManager bm) {
ICloneable functionCode = uriCodeMap.get(functionUri);
if (functionCode == null) {
IEntity functionModel = getFunctionModel(functionUri, loadOnDemand, bm);
functionCode = uriCodeMap.get(functionUri);
if (functionModel != null && functionCode == null) {
IBindingManager args = BindingManagerFactory.instance.createArguments();
DynamicCompilerOperation.compile(functionModel, args);
functionCode = uriCodeMap.get(functionUri);
}
}
if (functionCode == null)
// TODO should be configurable
functionCode = IteratorFactory.emptyIterator();
return (B) functionCode.clone();
}
use of org.whole.lang.model.IEntity in project whole by wholeplatform.
the class BehaviorUtils method evaluateSingletonResult.
public static final IEntity evaluateSingletonResult(IBindingManager bm) {
if (bm.hasResultIterator()) {
IEntityIterator<?> resultIterator = bm.getResultIterator();
bm.setResultIterator(null);
IEntity selfEntity = bm.wGet("self");
if (selfEntity != null)
resultIterator.reset(selfEntity);
return resultIterator.evaluateSingleton();
} else {
IEntity result = bm.getResult();
if (result == null)
throw new IllegalArgumentException("The result is not a singleton");
return result;
}
}
use of org.whole.lang.model.IEntity 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.model.IEntity in project whole by wholeplatform.
the class DefaultWrapWithinTransformer method transform.
public void transform(IEntity oldEntity, IEntity newEntity) {
EntityKinds newKind = newEntity.wGetEntityKind();
if (newKind.isData())
return;
IEntity containerEntity;
if (featureDescriptor != null)
containerEntity = newEntity.wGet(featureDescriptor);
else
containerEntity = newEntity;
if (!EntityUtils.isComposite(containerEntity))
return;
if (containerEntity.wGetEntityDescriptor(0).isPlatformSupertypeOf(oldEntity.wGetEntityDescriptor())) {
IEntity clone = EntityUtils.clone(oldEntity);
containerEntity.wSet(0, clone);
}
}
use of org.whole.lang.model.IEntity 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();
}
Aggregations