Search in sources :

Example 1 with PropertiesModel

use of org.qi4j.runtime.property.PropertiesModel in project qi4j-sdk by Qi4j.

the class CompositeAssemblyImpl method buildComposite.

protected void buildComposite(AssemblyHelper helper, StateDeclarations stateDeclarations) {
    this.stateDeclarations = stateDeclarations;
    this.helper = helper;
    for (Class<?> compositeType : types) {
        metaInfo = new MetaInfo(metaInfo).withAnnotations(compositeType);
        addAnnotationsMetaInfo(compositeType, metaInfo);
    }
    immutable = metaInfo.get(Immutable.class) != null;
    propertiesModel = new PropertiesModel();
    stateModel = createStateModel();
    mixinsModel = createMixinsModel();
    compositeMethodsModel = new CompositeMethodsModel(mixinsModel);
    // Implement composite methods
    ArrayList<Type> allTypes = getTypes(this.types);
    Iterable<Class<? extends Constraint<?, ?>>> constraintClasses = constraintDeclarations(getTypes(this.types));
    Iterable<Class<?>> concernClasses = flatten(concerns, concernDeclarations(allTypes));
    Iterable<Class<?>> sideEffectClasses = flatten(sideEffects, sideEffectDeclarations(allTypes));
    Iterable<Class<?>> mixinClasses = flatten(mixins, mixinDeclarations(this.types));
    implementMixinType(types, constraintClasses, concernClasses, sideEffectClasses, mixinClasses);
    // Add state from methods and fields
    addState(constraintClasses);
}
Also used : Annotations.isType(org.qi4j.api.util.Annotations.isType) Type(java.lang.reflect.Type) CompositeMethodsModel(org.qi4j.runtime.composite.CompositeMethodsModel) Constraint(org.qi4j.api.constraint.Constraint) MetaInfo(org.qi4j.api.common.MetaInfo) Classes.wrapperClass(org.qi4j.api.util.Classes.wrapperClass) PropertiesModel(org.qi4j.runtime.property.PropertiesModel)

Example 2 with PropertiesModel

use of org.qi4j.runtime.property.PropertiesModel in project qi4j-sdk by Qi4j.

the class ValueTypeFactory method newValueType.

@SuppressWarnings({ "raw", "unchecked" })
public ValueType newValueType(Type type, Class declaringClass, Class compositeType, LayerModel layer, ModuleModel module) {
    ValueType valueType = null;
    if (CollectionType.isCollection(type)) {
        if (type instanceof ParameterizedType) {
            ParameterizedType pt = (ParameterizedType) type;
            Type collectionType = pt.getActualTypeArguments()[0];
            if (collectionType instanceof TypeVariable) {
                TypeVariable collectionTypeVariable = (TypeVariable) collectionType;
                collectionType = Classes.resolveTypeVariable(collectionTypeVariable, declaringClass, compositeType);
            }
            ValueType collectedType = newValueType(collectionType, declaringClass, compositeType, layer, module);
            valueType = new CollectionType(Classes.RAW_CLASS.map(type), collectedType);
        } else {
            valueType = new CollectionType(Classes.RAW_CLASS.map(type), newValueType(Object.class, declaringClass, compositeType, layer, module));
        }
    } else if (MapType.isMap(type)) {
        if (type instanceof ParameterizedType) {
            ParameterizedType pt = (ParameterizedType) type;
            Type keyType = pt.getActualTypeArguments()[0];
            if (keyType instanceof TypeVariable) {
                TypeVariable keyTypeVariable = (TypeVariable) keyType;
                keyType = Classes.resolveTypeVariable(keyTypeVariable, declaringClass, compositeType);
            }
            ValueType keyedType = newValueType(keyType, declaringClass, compositeType, layer, module);
            Type valType = pt.getActualTypeArguments()[1];
            if (valType instanceof TypeVariable) {
                TypeVariable valueTypeVariable = (TypeVariable) valType;
                valType = Classes.resolveTypeVariable(valueTypeVariable, declaringClass, compositeType);
            }
            ValueType valuedType = newValueType(valType, declaringClass, compositeType, layer, module);
            valueType = new MapType(Classes.RAW_CLASS.map(type), keyedType, valuedType);
        } else {
            valueType = new MapType(Classes.RAW_CLASS.map(type), newValueType(Object.class, declaringClass, compositeType, layer, module), newValueType(Object.class, declaringClass, compositeType, layer, module));
        }
    } else if (ValueCompositeType.isValueComposite(type)) {
        // Find ValueModel in module/layer/used layers
        ValueModel model = new ValueFinder(layer, module, Classes.RAW_CLASS.map(type)).getFoundModel();
        if (model == null) {
            if (type.equals(ValueComposite.class)) {
                // Create default model
                MixinsModel mixinsModel = new MixinsModel();
                Iterable valueComposite = (Iterable) Iterables.iterable(ValueComposite.class);
                ValueStateModel valueStateModel = new ValueStateModel(new PropertiesModel(), new AssociationsModel(), new ManyAssociationsModel(), new NamedAssociationsModel());
                model = new ValueModel(valueComposite, Visibility.application, new MetaInfo(), mixinsModel, valueStateModel, new CompositeMethodsModel(mixinsModel));
            } else {
                throw new InvalidApplicationException("[" + module.name() + "] Could not find ValueComposite of type " + type);
            }
        }
        return model.valueType();
    } else if (EnumType.isEnum(type)) {
        valueType = new EnumType(Classes.RAW_CLASS.map(type));
    } else {
        valueType = new ValueType(Classes.RAW_CLASS.map(type));
    }
    return valueType;
}
Also used : MixinsModel(org.qi4j.runtime.composite.MixinsModel) ValueModel(org.qi4j.runtime.value.ValueModel) ValueType(org.qi4j.api.type.ValueType) NamedAssociationsModel(org.qi4j.runtime.association.NamedAssociationsModel) MetaInfo(org.qi4j.api.common.MetaInfo) ValueComposite(org.qi4j.api.value.ValueComposite) MapType(org.qi4j.api.type.MapType) ParameterizedType(java.lang.reflect.ParameterizedType) ManyAssociationsModel(org.qi4j.runtime.association.ManyAssociationsModel) ValueCompositeType(org.qi4j.api.type.ValueCompositeType) EnumType(org.qi4j.api.type.EnumType) MapType(org.qi4j.api.type.MapType) CollectionType(org.qi4j.api.type.CollectionType) ValueType(org.qi4j.api.type.ValueType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) CompositeMethodsModel(org.qi4j.runtime.composite.CompositeMethodsModel) TypeVariable(java.lang.reflect.TypeVariable) EnumType(org.qi4j.api.type.EnumType) CollectionType(org.qi4j.api.type.CollectionType) InvalidApplicationException(org.qi4j.api.common.InvalidApplicationException) ValueStateModel(org.qi4j.runtime.value.ValueStateModel) PropertiesModel(org.qi4j.runtime.property.PropertiesModel) ManyAssociationsModel(org.qi4j.runtime.association.ManyAssociationsModel) AssociationsModel(org.qi4j.runtime.association.AssociationsModel) NamedAssociationsModel(org.qi4j.runtime.association.NamedAssociationsModel)

Aggregations

Type (java.lang.reflect.Type)2 MetaInfo (org.qi4j.api.common.MetaInfo)2 CompositeMethodsModel (org.qi4j.runtime.composite.CompositeMethodsModel)2 PropertiesModel (org.qi4j.runtime.property.PropertiesModel)2 ParameterizedType (java.lang.reflect.ParameterizedType)1 TypeVariable (java.lang.reflect.TypeVariable)1 InvalidApplicationException (org.qi4j.api.common.InvalidApplicationException)1 Constraint (org.qi4j.api.constraint.Constraint)1 CollectionType (org.qi4j.api.type.CollectionType)1 EnumType (org.qi4j.api.type.EnumType)1 MapType (org.qi4j.api.type.MapType)1 ValueCompositeType (org.qi4j.api.type.ValueCompositeType)1 ValueType (org.qi4j.api.type.ValueType)1 Annotations.isType (org.qi4j.api.util.Annotations.isType)1 Classes.wrapperClass (org.qi4j.api.util.Classes.wrapperClass)1 ValueComposite (org.qi4j.api.value.ValueComposite)1 AssociationsModel (org.qi4j.runtime.association.AssociationsModel)1 ManyAssociationsModel (org.qi4j.runtime.association.ManyAssociationsModel)1 NamedAssociationsModel (org.qi4j.runtime.association.NamedAssociationsModel)1 MixinsModel (org.qi4j.runtime.composite.MixinsModel)1