Search in sources :

Example 6 with Association

use of org.qi4j.api.association.Association in project qi4j-sdk by Qi4j.

the class EntityAssemblyImpl method newAssociationModel.

public AssociationModel newAssociationModel(AccessibleObject accessor, Iterable<Class<? extends Constraint<?, ?>>> constraintClasses) {
    Iterable<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn(accessor);
    boolean optional = first(filter(isType(Optional.class), annotations)) != null;
    // Constraints for Association references
    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 Association itself
    valueConstraintsModel = constraintsFor(annotations, Association.class, ((Member) accessor).getName(), optional, constraintClasses, accessor);
    ValueConstraintsInstance associationValueConstraintsInstance = null;
    if (valueConstraintsModel.isConstrained()) {
        associationValueConstraintsInstance = valueConstraintsModel.newInstance();
    }
    MetaInfo metaInfo = associationDeclarations.metaInfoFor(accessor);
    AssociationModel associationModel = new AssociationModel(accessor, valueConstraintsInstance, associationValueConstraintsInstance, metaInfo);
    return associationModel;
}
Also used : Association(org.qi4j.api.association.Association) ManyAssociation(org.qi4j.api.association.ManyAssociation) NamedAssociation(org.qi4j.api.association.NamedAssociation) Optional(org.qi4j.api.common.Optional) MetaInfo(org.qi4j.api.common.MetaInfo) ValueConstraintsModel(org.qi4j.runtime.composite.ValueConstraintsModel) ValueConstraintsInstance(org.qi4j.runtime.composite.ValueConstraintsInstance) Member(java.lang.reflect.Member) Annotation(java.lang.annotation.Annotation) NamedAssociationModel(org.qi4j.runtime.association.NamedAssociationModel) AssociationModel(org.qi4j.runtime.association.AssociationModel) ManyAssociationModel(org.qi4j.runtime.association.ManyAssociationModel)

Example 7 with Association

use of org.qi4j.api.association.Association in project qi4j-sdk by Qi4j.

the class StateInjectionProviderFactory method newInjectionProvider.

@Override
public InjectionProvider newInjectionProvider(Resolution resolution, DependencyModel dependencyModel) throws InvalidInjectionException {
    if (StateHolder.class.isAssignableFrom(dependencyModel.rawInjectionType())) {
        // @State StateHolder properties;
        return new StateInjectionProvider();
    } else if (UnitOfWork.class.isAssignableFrom(dependencyModel.rawInjectionType())) {
        if (!(resolution.model() instanceof EntityDescriptor)) {
            throw new InvalidInjectionException("Only EntityComposites can be injected with '@State UnitOfWork'");
        }
        return new UnitOfWorkInjectionProvider();
    } else if (Property.class.isAssignableFrom(dependencyModel.rawInjectionType())) {
        // @State Property<String> name;
        StateDescriptor descriptor;
        descriptor = ((StatefulCompositeDescriptor) resolution.model()).state();
        State annotation = (State) dependencyModel.injectionAnnotation();
        String name;
        if (annotation.value().isEmpty()) {
            name = resolution.field().getName();
        } else {
            name = annotation.value();
        }
        PropertyDescriptor propertyDescriptor = descriptor.findPropertyModelByName(name);
        return new PropertyInjectionProvider(propertyDescriptor);
    } else if (Association.class.isAssignableFrom(dependencyModel.rawInjectionType())) {
        // @State Association<MyEntity> name;
        AssociationStateDescriptor descriptor = ((EntityDescriptor) resolution.model()).state();
        State annotation = (State) dependencyModel.injectionAnnotation();
        String name;
        if (annotation.value().isEmpty()) {
            name = resolution.field().getName();
        } else {
            name = annotation.value();
        }
        AssociationDescriptor model = descriptor.getAssociationByName(name);
        return new AssociationInjectionProvider(model);
    } else if (ManyAssociation.class.isAssignableFrom(dependencyModel.rawInjectionType())) {
        // @State ManyAssociation<MyEntity> name;
        AssociationStateDescriptor descriptor = ((EntityDescriptor) resolution.model()).state();
        State annotation = (State) dependencyModel.injectionAnnotation();
        String name;
        if (annotation.value().isEmpty()) {
            name = resolution.field().getName();
        } else {
            name = annotation.value();
        }
        AssociationDescriptor model = descriptor.getManyAssociationByName(name);
        return new ManyAssociationInjectionProvider(model);
    } else if (NamedAssociation.class.isAssignableFrom(dependencyModel.rawInjectionType())) {
        // @State NamedAssociation<MyEntity> name;
        AssociationStateDescriptor descriptor = ((EntityDescriptor) resolution.model()).state();
        State annotation = (State) dependencyModel.injectionAnnotation();
        String name;
        if (annotation.value().isEmpty()) {
            name = resolution.field().getName();
        } else {
            name = annotation.value();
        }
        AssociationDescriptor model = descriptor.getNamedAssociationByName(name);
        return new NamedAssociationInjectionProvider(model);
    }
    throw new InjectionProviderException("Injected value has invalid type");
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) PropertyDescriptor(org.qi4j.api.property.PropertyDescriptor) NamedAssociation(org.qi4j.api.association.NamedAssociation) AssociationDescriptor(org.qi4j.api.association.AssociationDescriptor) AssociationStateDescriptor(org.qi4j.api.association.AssociationStateDescriptor) EntityDescriptor(org.qi4j.api.entity.EntityDescriptor) ManyAssociation(org.qi4j.api.association.ManyAssociation) AbstractAssociation(org.qi4j.api.association.AbstractAssociation) Association(org.qi4j.api.association.Association) NamedAssociation(org.qi4j.api.association.NamedAssociation) State(org.qi4j.api.injection.scope.State) InvalidInjectionException(org.qi4j.bootstrap.InvalidInjectionException) StateDescriptor(org.qi4j.api.composite.StateDescriptor) AssociationStateDescriptor(org.qi4j.api.association.AssociationStateDescriptor)

Example 8 with Association

use of org.qi4j.api.association.Association in project qi4j-sdk by Qi4j.

the class ValueAssemblyImpl method newAssociationModel.

public AssociationModel newAssociationModel(AccessibleObject accessor, Iterable<Class<? extends Constraint<?, ?>>> constraintClasses) {
    Iterable<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn(accessor);
    boolean optional = first(filter(isType(Optional.class), annotations)) != null;
    // Constraints for Association references
    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 Association itself
    valueConstraintsModel = constraintsFor(annotations, Association.class, ((Member) accessor).getName(), optional, constraintClasses, accessor);
    ValueConstraintsInstance associationValueConstraintsInstance = null;
    if (valueConstraintsModel.isConstrained()) {
        associationValueConstraintsInstance = valueConstraintsModel.newInstance();
    }
    MetaInfo metaInfo = stateDeclarations.metaInfoFor(accessor);
    AssociationModel associationModel = new AssociationModel(accessor, valueConstraintsInstance, associationValueConstraintsInstance, metaInfo);
    return associationModel;
}
Also used : Association(org.qi4j.api.association.Association) ManyAssociation(org.qi4j.api.association.ManyAssociation) NamedAssociation(org.qi4j.api.association.NamedAssociation) Optional(org.qi4j.api.common.Optional) MetaInfo(org.qi4j.api.common.MetaInfo) ValueConstraintsModel(org.qi4j.runtime.composite.ValueConstraintsModel) ValueConstraintsInstance(org.qi4j.runtime.composite.ValueConstraintsInstance) Member(java.lang.reflect.Member) Annotation(java.lang.annotation.Annotation) NamedAssociationModel(org.qi4j.runtime.association.NamedAssociationModel) AssociationModel(org.qi4j.runtime.association.AssociationModel) ManyAssociationModel(org.qi4j.runtime.association.ManyAssociationModel)

Example 9 with Association

use of org.qi4j.api.association.Association in project qi4j-sdk by Qi4j.

the class MethodFinder method doFilter.

/**
     * Do the filter for method return type (Property, Association, ManyAssociation, NamedAssociation)
     * by removing the entry from the list.
     *
     * @param list list of CompositeMethodDetailDescriptor
     */
private void doFilter(List<CompositeMethodDetailDescriptor> list) {
    if (list.isEmpty()) {
        return;
    }
    Iterator<CompositeMethodDetailDescriptor> iter = list.iterator();
    while (iter.hasNext()) {
        CompositeMethodDetailDescriptor descriptor = iter.next();
        Method method = descriptor.descriptor().method();
        if (Property.class.isAssignableFrom(method.getReturnType())) {
            iter.remove();
        } else if (Association.class.isAssignableFrom(method.getReturnType())) {
            iter.remove();
        } else if (ManyAssociation.class.isAssignableFrom(method.getReturnType())) {
            iter.remove();
        } else if (NamedAssociation.class.isAssignableFrom(method.getReturnType())) {
            iter.remove();
        }
    }
}
Also used : Association(org.qi4j.api.association.Association) ManyAssociation(org.qi4j.api.association.ManyAssociation) NamedAssociation(org.qi4j.api.association.NamedAssociation) CompositeMethodDetailDescriptor(org.qi4j.tools.model.descriptor.CompositeMethodDetailDescriptor) NamedAssociation(org.qi4j.api.association.NamedAssociation) Method(java.lang.reflect.Method)

Aggregations

Association (org.qi4j.api.association.Association)9 ManyAssociation (org.qi4j.api.association.ManyAssociation)7 NamedAssociation (org.qi4j.api.association.NamedAssociation)7 Property (org.qi4j.api.property.Property)3 AssociationModel (org.qi4j.runtime.association.AssociationModel)3 ManyAssociationModel (org.qi4j.runtime.association.ManyAssociationModel)3 NamedAssociationModel (org.qi4j.runtime.association.NamedAssociationModel)3 Annotation (java.lang.annotation.Annotation)2 AccessibleObject (java.lang.reflect.AccessibleObject)2 Member (java.lang.reflect.Member)2 Method (java.lang.reflect.Method)2 AssociationDescriptor (org.qi4j.api.association.AssociationDescriptor)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 CompositeMethodDetailDescriptor (org.qi4j.tools.model.descriptor.CompositeMethodDetailDescriptor)2 Collection (java.util.Collection)1 OgnlContext (ognl.OgnlContext)1 OgnlException (ognl.OgnlException)1