Search in sources :

Example 6 with FeatureDescriptor

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

Example 7 with FeatureDescriptor

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

Example 8 with FeatureDescriptor

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)));
    }
}
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 9 with FeatureDescriptor

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();
}
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)

Example 10 with FeatureDescriptor

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

Aggregations

FeatureDescriptor (org.whole.lang.reflect.FeatureDescriptor)100 IEntity (org.whole.lang.model.IEntity)43 InternalIEntity (org.whole.lang.model.InternalIEntity)6 ILanguageKit (org.whole.lang.reflect.ILanguageKit)6 HashSet (java.util.HashSet)5 IContributionItem (org.eclipse.jface.action.IContributionItem)5 ActionsVisibleWhen (org.whole.lang.e4.ui.expressions.ActionsVisibleWhen)5 VisibilityExpression (org.whole.lang.e4.ui.expressions.VisibilityExpression)5 ActionsCompositeContributionItem (org.whole.lang.e4.ui.menu.ActionsCompositeContributionItem)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 HashMap (java.util.HashMap)3 IBindingManager (org.whole.lang.bindings.IBindingManager)3 ITransactionScope (org.whole.lang.bindings.ITransactionScope)3 IdentityRequestEventHandler (org.whole.lang.events.IdentityRequestEventHandler)3 IMappingStrategy (org.whole.lang.xsd.codebase.IMappingStrategy)3 IEntityFactory (org.whole.lang.factories.IEntityFactory)2 ArrayType (org.whole.lang.pojo.model.ArrayType)2 CollectionType (org.whole.lang.pojo.model.CollectionType)2 MapType (org.whole.lang.pojo.model.MapType)2