use of org.qi4j.api.association.ManyAssociation in project qi4j-sdk by Qi4j.
the class EntityAssemblyImpl method newManyAssociationModel.
public ManyAssociationModel newManyAssociationModel(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 ManyAssociation
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 ManyAssociation itself
valueConstraintsModel = constraintsFor(annotations, ManyAssociation.class, ((Member) accessor).getName(), optional, constraintClasses, accessor);
ValueConstraintsInstance manyValueConstraintsInstance = null;
if (valueConstraintsModel.isConstrained()) {
manyValueConstraintsInstance = valueConstraintsModel.newInstance();
}
MetaInfo metaInfo = manyAssociationDeclarations.metaInfoFor(accessor);
ManyAssociationModel associationModel = new ManyAssociationModel(accessor, valueConstraintsInstance, manyValueConstraintsInstance, metaInfo);
return associationModel;
}
use of org.qi4j.api.association.ManyAssociation in project qi4j-sdk by Qi4j.
the class ValueAssemblyImpl method newManyAssociationModel.
public ManyAssociationModel newManyAssociationModel(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 ManyAssociation
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 ManyAssociation itself
valueConstraintsModel = constraintsFor(annotations, ManyAssociation.class, ((Member) accessor).getName(), optional, constraintClasses, accessor);
ValueConstraintsInstance manyValueConstraintsInstance = null;
if (valueConstraintsModel.isConstrained()) {
manyValueConstraintsInstance = valueConstraintsModel.newInstance();
}
MetaInfo metaInfo = stateDeclarations.metaInfoFor(accessor);
ManyAssociationModel associationModel = new ManyAssociationModel(accessor, valueConstraintsInstance, manyValueConstraintsInstance, metaInfo);
return associationModel;
}
use of org.qi4j.api.association.ManyAssociation in project qi4j-sdk by Qi4j.
the class EntityStateInstance method manyAssociationFor.
@Override
@SuppressWarnings("unchecked")
public <T> ManyAssociation<T> manyAssociationFor(AccessibleObject accessor) {
Map<AccessibleObject, Object> state = state();
ManyAssociation<T> manyAssociation = (ManyAssociation<T>) state.get(accessor);
if (manyAssociation == null) {
ManyAssociationModel associationModel = stateModel.getManyAssociation(accessor);
manyAssociation = new ManyAssociationInstance<>(entityState instanceof BuilderEntityState ? associationModel.getBuilderInfo() : associationModel, entityFunction, entityState.manyAssociationValueOf(associationModel.qualifiedName()));
state.put(accessor, manyAssociation);
}
return manyAssociation;
}
use of org.qi4j.api.association.ManyAssociation in project qi4j-sdk by Qi4j.
the class ManyAssociationInstance method equals.
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ManyAssociation<?> that = (ManyAssociation) o;
// Unwrap if needed
while (that instanceof ManyAssociationWrapper) {
that = ((ManyAssociationWrapper) that).next();
}
// Descriptor equality
ManyAssociationInstance<?> thatInstance = (ManyAssociationInstance) that;
AssociationDescriptor thatDescriptor = (AssociationDescriptor) thatInstance.associationInfo();
if (!associationInfo.equals(thatDescriptor)) {
return false;
}
// State equality
if (manyAssociationState.count() != thatInstance.manyAssociationState.count()) {
return false;
}
for (EntityReference ref : manyAssociationState) {
if (!thatInstance.manyAssociationState.contains(ref)) {
return false;
}
}
return true;
}
use of org.qi4j.api.association.ManyAssociation 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();
}
}
Aggregations