Search in sources :

Example 56 with FeatureDescriptor

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

the class XmlSpecific2XsiBuilderAdapter method _elementEntity.

protected void _elementEntity(EntityDescriptor<?> context) {
    // FIXME unions
    if (!EntityUtils.isData(context) && !(context.isAbstract() && context.isPolymorphic())) {
        // was getConcreteSubtypesInLanguage().size() > 1)) {
        ;
        // sets an empty string if content entity maps to a string data type
        FeatureDescriptor fd = getContentFeatureMapping(context);
        if (fd != null && builder.wCurrentIndexOf() <= context.indexOf(fd)) {
            EntityDescriptor<?> ed = getContentEntityMapping(context);
            // FIXME lists/unions
            if (ed.getDataKind().isString()) {
                builder.wFeature(fd);
                DataTypeUtils.buildFromPersistenceString(builder, ed, "");
            }
        }
        builder._wEntity(context);
    }
}
Also used : FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor)

Example 57 with FeatureDescriptor

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

the class AbstractMappingStrategy method getElementFeatureMappings.

public Collection<FeatureDescriptor> getElementFeatureMappings(EntityDescriptor<?> context, QName name) {
    Set<CompiledMapping> mappings = indexes.findMappings(ElementMapping, context, name.getLocalPart());
    if (mappings.isEmpty())
        mappings = Collections.singleton(indexes.findMapping(AnyElementMapping, context));
    Set<FeatureDescriptor> featureMappings = new HashSet<FeatureDescriptor>(mappings.size());
    for (CompiledMapping mapping : mappings) featureMappings.add(mapping.fd);
    return featureMappings;
}
Also used : CompiledMapping(org.whole.lang.xsd.codebase.MappingIndexes.CompiledMapping) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) HashSet(java.util.HashSet)

Example 58 with FeatureDescriptor

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

the class DefaultValueFactory method setUniqueDefault.

public static void setUniqueDefault(IEntity entity) {
    final String defaultPrefix = entity.wStringValue();
    entity.wAddRequestEventHandler(new IdentityRequestEventHandler() {

        int max = 0;

        void updateMax(int value) {
            if (value > max)
                max = value;
        }

        public String notifyRequested(final IEntity source, FeatureDescriptor feature, String value) {
            if (value.equals(defaultPrefix)) {
                final EntityDescriptor<?> sourceDescriptor = source.wGetEntityDescriptor();
                final EntityDescriptor<?> parentDescriptor = source.wGetParent().wGetEntityDescriptor();
                GenericTraversalFactory.instance.topDown(new AbstractVisitor() {

                    public void visit(IEntity entity) {
                        if (entity == source)
                            return;
                        if (sourceDescriptor.equals(entity.wGetEntityDescriptor()) && parentDescriptor.equals(entity.wGetParent().wGetEntityDescriptor())) {
                            String strValue = entity.wStringValue();
                            if (strValue.startsWith(defaultPrefix)) {
                                try {
                                    int value = Integer.parseInt(strValue.substring(defaultPrefix.length()));
                                    updateMax(value);
                                } catch (NumberFormatException e) {
                                } catch (IndexOutOfBoundsException e) {
                                }
                            }
                        }
                    }
                }, false).visit(EntityUtils.getCompoundRoot(source));
                source.wSetValue(value = defaultPrefix + ++max);
                source.wRemoveRequestEventHandler(this);
            }
            return value;
        }
    });
}
Also used : EntityDescriptor(org.whole.lang.reflect.EntityDescriptor) AbstractVisitor(org.whole.lang.visitors.AbstractVisitor) IEntity(org.whole.lang.model.IEntity) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor)

Example 59 with FeatureDescriptor

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

the class PojoUtils method createInstanceUsingConstructor.

public static Object createInstanceUsingConstructor(IEntity fromEntity, PojoDeclaration pojoDeclaration, Library library) throws Exception {
    ReferenceType referenceType = pojoDeclaration.getName();
    Class<?> clazz = Class.forName(referenceType.getValue(), true, ReflectionFactory.getPlatformClassLoader());
    Constructor constructor = findConstructor(pojoDeclaration);
    int params = constructor.getParameters().wSize();
    List<Class<?>> parameterTypes = new ArrayList<Class<?>>(params);
    List<Object> initargs = new ArrayList<Object>(params);
    IBindingManager bindings = BindingManagerFactory.instance.createArguments();
    Expression findPropertyByTemplate = (Expression) PojoTemplateManager.instance().create("findPropertyByTemplate");
    Expression findParameterByTemplate = (Expression) PojoTemplateManager.instance().create("findParameterByTemplate");
    IEntityIterator<Parameter> iterator = BehaviorUtils.<Parameter>compileAndLazyEvaluate(findParameterByTemplate, constructor, bindings);
    while (iterator.hasNext()) {
        iterator.next();
        Property property = BehaviorUtils.<Property>evaluateFirstResult(findPropertyByTemplate, pojoDeclaration, bindings);
        Type type = property.getType();
        Name template = property.getTemplate();
        FeatureDescriptor fd = fromEntity.wGetEntityDescriptor().getFeatureDescriptorEnum().valueOf(template.wStringValue());
        IEntity fieldEntity = fromEntity.wGet(fd);
        parameterTypes.add(getClass(type));
        initargs.add(Matcher.match(PrimitiveType, type) ? fieldEntity.wGetValue() : create(fieldEntity, library));
    }
    return clazz.getConstructor(parameterTypes.toArray(new Class<?>[0])).newInstance(initargs.toArray());
}
Also used : IEntity(org.whole.lang.model.IEntity) Constructor(org.whole.lang.pojo.model.Constructor) ArrayList(java.util.ArrayList) ReferenceType(org.whole.lang.pojo.reflect.PojoEntityDescriptorEnum.ReferenceType) ReferenceType(org.whole.lang.pojo.model.ReferenceType) Name(org.whole.lang.pojo.model.Name) PrimitiveType(org.whole.lang.pojo.model.PrimitiveType) PrimitiveType(org.whole.lang.pojo.reflect.PojoEntityDescriptorEnum.PrimitiveType) Type(org.whole.lang.pojo.model.Type) MapType(org.whole.lang.pojo.model.MapType) ArrayType(org.whole.lang.pojo.model.ArrayType) ReferenceType(org.whole.lang.pojo.reflect.PojoEntityDescriptorEnum.ReferenceType) CollectionType(org.whole.lang.pojo.model.CollectionType) ReferenceType(org.whole.lang.pojo.model.ReferenceType) Expression(org.whole.lang.queries.model.Expression) PathExpression(org.whole.lang.queries.model.PathExpression) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) IBindingManager(org.whole.lang.bindings.IBindingManager) Parameter(org.whole.lang.pojo.model.Parameter) Property(org.whole.lang.pojo.model.Property)

Example 60 with FeatureDescriptor

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

the class PojoUtils method translate.

public static void translate(IEntity fromEntity, Object toObject, PojoDeclaration pojoDeclaration, Library library) {
    // translate inherited properties
    IEntityIterator<ReferenceType> superPojosIterator = IteratorFactory.<ReferenceType>childIterator();
    superPojosIterator.reset(pojoDeclaration.getTypes());
    for (ReferenceType superType : superPojosIterator) {
        PojoDeclaration superDeclaration = (PojoDeclaration) findProductDeclaration(superType, library);
        translate(fromEntity, toObject, superDeclaration, library);
    }
    // translate declared properties
    IEntityIterator<Property> iterator = IteratorFactory.<Property>childIterator();
    iterator.reset(pojoDeclaration.getProperties());
    EntityDescriptor<?> ed = fromEntity.wGetEntityDescriptor();
    Property property = null;
    try {
        while (iterator.hasNext()) {
            property = iterator.next();
            if (isReadOnly(property))
                continue;
            Type type = property.getType();
            Name template = property.getTemplate();
            FeatureDescriptor fd = ed.getFeatureDescriptorEnum().valueOf(template.wStringValue());
            IEntity fieldEntity = fromEntity.wGet(fd);
            if (!EntityUtils.isNotResolver(fieldEntity))
                continue;
            if (Matcher.match(PrimitiveType, type))
                setPropertyValue(property, toObject, fieldEntity.wGetValue());
            else
                setPropertyValue(property, toObject, create(fieldEntity, library));
        }
    } catch (Exception e) {
        throw new IllegalStateException("Cannot translate property: " + property, e);
    }
}
Also used : PojoDeclaration(org.whole.lang.pojo.reflect.PojoEntityDescriptorEnum.PojoDeclaration) PojoDeclaration(org.whole.lang.pojo.model.PojoDeclaration) PrimitiveType(org.whole.lang.pojo.model.PrimitiveType) PrimitiveType(org.whole.lang.pojo.reflect.PojoEntityDescriptorEnum.PrimitiveType) Type(org.whole.lang.pojo.model.Type) MapType(org.whole.lang.pojo.model.MapType) ArrayType(org.whole.lang.pojo.model.ArrayType) ReferenceType(org.whole.lang.pojo.reflect.PojoEntityDescriptorEnum.ReferenceType) CollectionType(org.whole.lang.pojo.model.CollectionType) ReferenceType(org.whole.lang.pojo.model.ReferenceType) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) IEntity(org.whole.lang.model.IEntity) Property(org.whole.lang.pojo.model.Property) ReferenceType(org.whole.lang.pojo.reflect.PojoEntityDescriptorEnum.ReferenceType) ReferenceType(org.whole.lang.pojo.model.ReferenceType) InvocationTargetException(java.lang.reflect.InvocationTargetException) Name(org.whole.lang.pojo.model.Name)

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