Search in sources :

Example 46 with FeatureDescriptor

use of org.whole.lang.reflect.FeatureDescriptor in project whole by wholeplatform.

the class QueriesUtils method sort.

public static IEntity sort(IEntity entity) {
    if (entity.wGetEntityDescriptor().getCompositeKind().isOrdered()) {
        List<IEntity> entityList = (List<IEntity>) entity;
        IEntity[] array = entityList.toArray(new IEntity[entity.wSize()]);
        entityList.clear();
        Arrays.sort(array, new Comparator<IEntity>() {

            public int compare(IEntity e1, IEntity e2) {
                IEntity e1Adaptee = e1.wGetAdaptee(false);
                IEntity e2Adaptee = e2.wGetAdaptee(false);
                EntityDescriptor<?> e1Ed = e1Adaptee.wGetEntityDescriptor();
                EntityDescriptor<?> e2Ed = e2Adaptee.wGetEntityDescriptor();
                if (e1Ed != e2Ed)
                    return 0;
                switch(e1Ed.getEntityKind()) {
                    case DATA:
                        return DataTypeUtils.compare(e1Adaptee, e2Adaptee);
                    default:
                    case COMPOSITE:
                        return 0;
                    case SIMPLE:
                        boolean idBased = false;
                        List<FeatureDescriptor> entityFeatureDescriptors = e1Ed.getEntityFeatureDescriptors();
                        for (FeatureDescriptor fd : entityFeatureDescriptors) {
                            if (fd.isId()) {
                                idBased = true;
                                int result = compare(e1Adaptee.wGet(fd), e2Adaptee.wGet(fd));
                                if (result != 0)
                                    return result;
                            }
                        }
                        if (idBased)
                            return 0;
                        for (FeatureDescriptor fd : entityFeatureDescriptors) {
                            int result = compare(e1Adaptee.wGet(fd), e2Adaptee.wGet(fd));
                            if (result != 0)
                                return result;
                        }
                        return 0;
                }
            }
        });
        for (IEntity child : array) entity.wAdd(child);
        return entity;
    } else
        return entity;
}
Also used : EntityDescriptor(org.whole.lang.reflect.EntityDescriptor) IEntity(org.whole.lang.model.IEntity) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) List(java.util.List)

Example 47 with FeatureDescriptor

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

Example 48 with FeatureDescriptor

use of org.whole.lang.reflect.FeatureDescriptor 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());
    }
}
Also used : ITransactionScope(org.whole.lang.bindings.ITransactionScope) IEntity(org.whole.lang.model.IEntity) IEntityFactory(org.whole.lang.factories.IEntityFactory) Arguments(org.whole.lang.workflows.model.Arguments) Assignments(org.whole.lang.workflows.model.Assignments) WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException) MissingVariableException(org.whole.lang.visitors.MissingVariableException) IOException(java.io.IOException) IWholeRuntimeException(org.whole.lang.exceptions.IWholeRuntimeException) VisitException(org.whole.lang.visitors.VisitException) ParseException(org.whole.lang.parsers.ParseException) WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) IEntityRegistryProvider(org.whole.lang.factories.IEntityRegistryProvider) Expressions(org.whole.lang.workflows.model.Expressions)

Example 49 with FeatureDescriptor

use of org.whole.lang.reflect.FeatureDescriptor in project whole by wholeplatform.

the class ReflectLibraryDeployer method getFeatureDescriptor.

public static FeatureDescriptor getFeatureDescriptor(IEntity selfEntity, IBindingManager bm) {
    FeatureDescriptor fd = null;
    if (DataTypeUtils.getDataKind(selfEntity).isString()) {
        String uri = selfEntity.wStringValue();
        if (ResourceUtils.hasFragmentPart(uri)) {
            String languageUri = ResourceUtils.stripFragmentPart(uri);
            String descriptorName = ResourceUtils.getFragmentPart(uri);
            ILanguageKit languageKit = ReflectionFactory.safeGetLanguageKit(languageUri, true, bm);
            if (languageKit != null)
                fd = languageKit.getFeatureDescriptorEnum().valueOf(descriptorName);
        }
    } else if (DataTypeUtils.getDataKind(selfEntity).isEnumValue() && selfEntity.wEnumValue() instanceof FeatureDescriptor)
        fd = (FeatureDescriptor) selfEntity.wEnumValue();
    else if (DataTypeUtils.getDataKind(selfEntity).isObject() && selfEntity.wGetValue() instanceof FeatureDescriptor)
        fd = (FeatureDescriptor) selfEntity.wGetValue();
    return fd;
}
Also used : FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) ILanguageKit(org.whole.lang.reflect.ILanguageKit)

Example 50 with FeatureDescriptor

use of org.whole.lang.reflect.FeatureDescriptor in project whole by wholeplatform.

the class ReflectLibraryDeployer method setFeatureDescriptorResult.

public static void setFeatureDescriptorResult(IBindingManager bm, EntityDescriptor<?> ed) {
    FeatureDescriptor fd = bm.wIsSet("feature") ? getFeatureDescriptor(bm.wGet("feature"), bm) : null;
    String featureName = fd == null && bm.wIsSet("featureName") ? bm.wStringValue("featureName") : null;
    int featureIndex = fd == null && featureName == null && bm.wIsSet("featureIndex") ? bm.wIntValue("featureIndex") : -1;
    FeatureDescriptor lfd = null;
    if (fd != null) {
        if (fd.getLanguageKit().equals(ed.getLanguageKit()))
            lfd = fd;
        else
            featureName = fd.getName();
    }
    if (featureName != null)
        lfd = ed.getFeatureDescriptorEnum().valueOf(featureName);
    FeatureDescriptor efd = null;
    if (lfd != null)
        featureIndex = ed.indexOf(lfd);
    if (featureIndex > -1 && featureIndex < ed.featureSize())
        efd = ed.getEntityFeatureDescriptor(featureIndex);
    bm.setResult(efd != null ? BindingManagerFactory.instance.createValue(efd) : null);
}
Also used : FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor)

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