Search in sources :

Example 36 with IEntity

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();
}
Also used : ICloneable(org.whole.lang.operations.ICloneable) IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager)

Example 37 with IEntity

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;
    }
}
Also used : IEntity(org.whole.lang.model.IEntity)

Example 38 with IEntity

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)));
    }
}
Also used : EntityDescriptor(org.whole.lang.reflect.EntityDescriptor) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) IEntity(org.whole.lang.model.IEntity) EntityKinds(org.whole.lang.reflect.EntityKinds) HashSet(java.util.HashSet)

Example 39 with IEntity

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);
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) EntityKinds(org.whole.lang.reflect.EntityKinds)

Example 40 with IEntity

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();
}
Also used : IEntity(org.whole.lang.model.IEntity) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) PrintWriter(java.io.PrintWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) HashSet(java.util.HashSet) IdentityRequestEventHandler(org.whole.lang.events.IdentityRequestEventHandler) PrintWriter(java.io.PrintWriter)

Aggregations

IEntity (org.whole.lang.model.IEntity)1407 ArrayList (java.util.ArrayList)604 Test (org.junit.Test)241 IBindingManager (org.whole.lang.bindings.IBindingManager)141 PathExpression (org.whole.lang.queries.model.PathExpression)68 ITemplateManager (org.whole.lang.templates.ITemplateManager)61 Grammar (org.whole.lang.grammars.model.Grammar)50 TestXmlGrammar (org.whole.lang.grammars.util.TestXmlGrammar)46 FeatureDescriptor (org.whole.lang.reflect.FeatureDescriptor)43 Model (org.whole.lang.models.model.Model)40 InternalIEntity (org.whole.lang.model.InternalIEntity)38 VisitException (org.whole.lang.visitors.VisitException)35 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)30 ModelsModel (org.whole.lang.models.codebase.ModelsModel)27 WholeIllegalArgumentException (org.whole.lang.exceptions.WholeIllegalArgumentException)26 StreamPersistenceProvider (org.whole.lang.codebase.StreamPersistenceProvider)24 ModelBuilderOperation (org.whole.lang.builders.ModelBuilderOperation)22 XmlModel (org.whole.lang.models.codebase.XmlModel)22 MissingVariableException (org.whole.lang.visitors.MissingVariableException)22 IEntityPart (org.whole.lang.ui.editparts.IEntityPart)21