Search in sources :

Example 11 with ValueConstraintsModel

use of org.qi4j.runtime.composite.ValueConstraintsModel in project qi4j-sdk by Qi4j.

the class ValueAssemblyImpl method newPropertyModel.

@Override
protected PropertyModel newPropertyModel(AccessibleObject accessor, Iterable<Class<? extends Constraint<?, ?>>> constraintClasses) {
    Iterable<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn(accessor);
    boolean optional = first(filter(isType(Optional.class), annotations)) != null;
    ValueConstraintsModel valueConstraintsModel = constraintsFor(annotations, GenericPropertyInfo.propertyTypeOf(accessor), ((Member) accessor).getName(), optional, constraintClasses, accessor);
    ValueConstraintsInstance valueConstraintsInstance = null;
    if (valueConstraintsModel.isConstrained()) {
        valueConstraintsInstance = valueConstraintsModel.newInstance();
    }
    MetaInfo metaInfo = stateDeclarations.metaInfoFor(accessor);
    boolean useDefaults = metaInfo.get(UseDefaults.class) != null || stateDeclarations.useDefaults(accessor);
    Object initialValue = stateDeclarations.initialValueOf(accessor);
    return new PropertyModel(accessor, true, useDefaults, valueConstraintsInstance, metaInfo, initialValue);
}
Also used : Optional(org.qi4j.api.common.Optional) MetaInfo(org.qi4j.api.common.MetaInfo) PropertyModel(org.qi4j.runtime.property.PropertyModel) ValueConstraintsModel(org.qi4j.runtime.composite.ValueConstraintsModel) AccessibleObject(java.lang.reflect.AccessibleObject) ValueConstraintsInstance(org.qi4j.runtime.composite.ValueConstraintsInstance) Annotation(java.lang.annotation.Annotation)

Aggregations

Annotation (java.lang.annotation.Annotation)11 ValueConstraintsModel (org.qi4j.runtime.composite.ValueConstraintsModel)11 Optional (org.qi4j.api.common.Optional)10 MetaInfo (org.qi4j.api.common.MetaInfo)9 ValueConstraintsInstance (org.qi4j.runtime.composite.ValueConstraintsInstance)9 Member (java.lang.reflect.Member)6 ManyAssociation (org.qi4j.api.association.ManyAssociation)4 NamedAssociation (org.qi4j.api.association.NamedAssociation)4 ManyAssociationModel (org.qi4j.runtime.association.ManyAssociationModel)4 NamedAssociationModel (org.qi4j.runtime.association.NamedAssociationModel)4 AccessibleObject (java.lang.reflect.AccessibleObject)3 Annotations.hasAnnotation (org.qi4j.api.util.Annotations.hasAnnotation)3 PropertyModel (org.qi4j.runtime.property.PropertyModel)3 Association (org.qi4j.api.association.Association)2 Constraint (org.qi4j.api.constraint.Constraint)2 AssociationModel (org.qi4j.runtime.association.AssociationModel)2 Type (java.lang.reflect.Type)1 ArrayList (java.util.ArrayList)1 QualifiedName (org.qi4j.api.common.QualifiedName)1 InvalidCompositeException (org.qi4j.api.composite.InvalidCompositeException)1