Search in sources :

Example 1 with NamedAssociationModel

use of org.qi4j.runtime.association.NamedAssociationModel in project qi4j-sdk by Qi4j.

the class EntityStateInstance method namedAssociationFor.

@Override
@SuppressWarnings("unchecked")
public <T> NamedAssociation<T> namedAssociationFor(AccessibleObject accessor) {
    Map<AccessibleObject, Object> state = state();
    NamedAssociation<T> namedAssociation = (NamedAssociation<T>) state.get(accessor);
    if (namedAssociation == null) {
        NamedAssociationModel associationModel = stateModel.getNamedAssociation(accessor);
        namedAssociation = new NamedAssociationInstance<>(entityState instanceof BuilderEntityState ? associationModel.getBuilderInfo() : associationModel, entityFunction, entityState.namedAssociationValueOf(associationModel.qualifiedName()));
        state.put(accessor, namedAssociation);
    }
    return namedAssociation;
}
Also used : NamedAssociation(org.qi4j.api.association.NamedAssociation) NamedAssociationModel(org.qi4j.runtime.association.NamedAssociationModel) AccessibleObject(java.lang.reflect.AccessibleObject) AccessibleObject(java.lang.reflect.AccessibleObject) BuilderEntityState(org.qi4j.runtime.unitofwork.BuilderEntityState)

Example 2 with NamedAssociationModel

use of org.qi4j.runtime.association.NamedAssociationModel in project qi4j-sdk by Qi4j.

the class EntityAssemblyImpl method newNamedAssociationModel.

public NamedAssociationModel newNamedAssociationModel(AccessibleObject accessor, Iterable<Class<? extends Constraint<?, ?>>> constraintClasses) {
    Iterable<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn(accessor);
    boolean optional = first(filter(isType(Optional.class), annotations)) != null;
    // Constraints for entities in NamedAssociation
    ValueConstraintsModel valueConstraintsModel = constraintsFor(annotations, GenericAssociationInfo.associationTypeOf(accessor), ((Member) accessor).getName(), optional, constraintClasses, accessor);
    ValueConstraintsInstance valueConstraintsInstance = null;
    if (valueConstraintsModel.isConstrained()) {
        valueConstraintsInstance = valueConstraintsModel.newInstance();
    }
    // Constraints for the NamedAssociation itself
    valueConstraintsModel = constraintsFor(annotations, NamedAssociation.class, ((Member) accessor).getName(), optional, constraintClasses, accessor);
    ValueConstraintsInstance namedValueConstraintsInstance = null;
    if (valueConstraintsModel.isConstrained()) {
        namedValueConstraintsInstance = valueConstraintsModel.newInstance();
    }
    MetaInfo metaInfo = namedAssociationDeclarations.metaInfoFor(accessor);
    NamedAssociationModel associationModel = new NamedAssociationModel(accessor, valueConstraintsInstance, namedValueConstraintsInstance, metaInfo);
    return associationModel;
}
Also used : Optional(org.qi4j.api.common.Optional) NamedAssociation(org.qi4j.api.association.NamedAssociation) MetaInfo(org.qi4j.api.common.MetaInfo) ValueConstraintsModel(org.qi4j.runtime.composite.ValueConstraintsModel) NamedAssociationModel(org.qi4j.runtime.association.NamedAssociationModel) ValueConstraintsInstance(org.qi4j.runtime.composite.ValueConstraintsInstance) Member(java.lang.reflect.Member) Annotation(java.lang.annotation.Annotation)

Example 3 with NamedAssociationModel

use of org.qi4j.runtime.association.NamedAssociationModel in project qi4j-sdk by Qi4j.

the class ValueAssemblyImpl method newNamedAssociationModel.

public NamedAssociationModel newNamedAssociationModel(AccessibleObject accessor, Iterable<Class<? extends Constraint<?, ?>>> constraintClasses) {
    Iterable<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn(accessor);
    boolean optional = first(filter(isType(Optional.class), annotations)) != null;
    // Constraints for entities in NamedAssociation
    ValueConstraintsModel valueConstraintsModel = constraintsFor(annotations, GenericAssociationInfo.associationTypeOf(accessor), ((Member) accessor).getName(), optional, constraintClasses, accessor);
    ValueConstraintsInstance valueConstraintsInstance = null;
    if (valueConstraintsModel.isConstrained()) {
        valueConstraintsInstance = valueConstraintsModel.newInstance();
    }
    // Constraints for the NamedAssociation itself
    valueConstraintsModel = constraintsFor(annotations, NamedAssociation.class, ((Member) accessor).getName(), optional, constraintClasses, accessor);
    ValueConstraintsInstance namedValueConstraintsInstance = null;
    if (valueConstraintsModel.isConstrained()) {
        namedValueConstraintsInstance = valueConstraintsModel.newInstance();
    }
    MetaInfo metaInfo = stateDeclarations.metaInfoFor(accessor);
    NamedAssociationModel associationModel = new NamedAssociationModel(accessor, valueConstraintsInstance, namedValueConstraintsInstance, metaInfo);
    return associationModel;
}
Also used : Optional(org.qi4j.api.common.Optional) NamedAssociation(org.qi4j.api.association.NamedAssociation) MetaInfo(org.qi4j.api.common.MetaInfo) ValueConstraintsModel(org.qi4j.runtime.composite.ValueConstraintsModel) NamedAssociationModel(org.qi4j.runtime.association.NamedAssociationModel) ValueConstraintsInstance(org.qi4j.runtime.composite.ValueConstraintsInstance) Member(java.lang.reflect.Member) Annotation(java.lang.annotation.Annotation)

Aggregations

NamedAssociation (org.qi4j.api.association.NamedAssociation)3 NamedAssociationModel (org.qi4j.runtime.association.NamedAssociationModel)3 Annotation (java.lang.annotation.Annotation)2 Member (java.lang.reflect.Member)2 MetaInfo (org.qi4j.api.common.MetaInfo)2 Optional (org.qi4j.api.common.Optional)2 ValueConstraintsInstance (org.qi4j.runtime.composite.ValueConstraintsInstance)2 ValueConstraintsModel (org.qi4j.runtime.composite.ValueConstraintsModel)2 AccessibleObject (java.lang.reflect.AccessibleObject)1 BuilderEntityState (org.qi4j.runtime.unitofwork.BuilderEntityState)1