use of org.qi4j.api.association.NamedAssociation 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;
}
use of org.qi4j.api.association.NamedAssociation in project qi4j-sdk by Qi4j.
the class StateFinder method doFilter.
/**
* Do the filter for method return type (Property, Association, ManyAssociation, NamedAssociation)
* by removing the entry from the list if not the above.
*
* @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()) || Association.class.isAssignableFrom(method.getReturnType()) || ManyAssociation.class.isAssignableFrom(method.getReturnType()) || NamedAssociation.class.isAssignableFrom(method.getReturnType())) {
continue;
}
iter.remove();
}
}
use of org.qi4j.api.association.NamedAssociation 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;
}
use of org.qi4j.api.association.NamedAssociation 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");
}
use of org.qi4j.api.association.NamedAssociation 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;
}
Aggregations