use of org.qi4j.runtime.association.ManyAssociationModel 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.runtime.association.ManyAssociationModel 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.runtime.association.ManyAssociationModel 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.runtime.association.ManyAssociationModel in project qi4j-sdk by Qi4j.
the class ValueInstance method prepareBuilderState.
/**
* When a ValueBuilder is finished and is about to instantiate a Value, call this to ensure that the state has correct
* settings, i.e. is immutable.
*/
public void prepareBuilderState() {
for (PropertyModel propertyDescriptor : descriptor().state().properties()) {
PropertyInstance<Object> propertyInstance = (PropertyInstance<Object>) state.propertyFor(propertyDescriptor.accessor());
propertyInstance.prepareBuilderState(propertyDescriptor);
}
for (AssociationModel associationDescriptor : descriptor().state().associations()) {
state().associationFor(associationDescriptor.accessor()).setAssociationInfo(associationDescriptor);
}
for (ManyAssociationModel associationDescriptor : descriptor().state().manyAssociations()) {
state().manyAssociationFor(associationDescriptor.accessor()).setAssociationInfo(associationDescriptor);
}
}
use of org.qi4j.runtime.association.ManyAssociationModel in project qi4j-sdk by Qi4j.
the class ValueInstance method prepareToBuild.
/**
* When a ValueBuilder is about to start, ensure that all state has builder infos, i.e. they are mutable.
*/
public void prepareToBuild() {
for (PropertyModel propertyDescriptor : descriptor().state().properties()) {
PropertyInstance<Object> propertyInstance = (PropertyInstance<Object>) state.propertyFor(propertyDescriptor.accessor());
propertyInstance.prepareToBuild(propertyDescriptor);
}
for (AssociationModel associationDescriptor : descriptor().state().associations()) {
state().associationFor(associationDescriptor.accessor()).setAssociationInfo(associationDescriptor.getBuilderInfo());
}
for (ManyAssociationModel associationDescriptor : descriptor().state().manyAssociations()) {
state().manyAssociationFor(associationDescriptor.accessor()).setAssociationInfo(associationDescriptor.getBuilderInfo());
}
}
Aggregations