use of org.qi4j.api.common.Optional 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.common.Optional 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.common.Optional in project qi4j-sdk by Qi4j.
the class CompositeAssemblyImpl method newPropertyModel.
protected PropertyModel newPropertyModel(AccessibleObject accessor, Iterable<Class<? extends Constraint<?, ?>>> constraintClasses) {
Iterable<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn(accessor);
boolean optional = first(filter(isType(Optional.class), annotations)) != null;
ValueConstraintsModel valueConstraintsModel = constraintsFor(annotations, GenericPropertyInfo.propertyTypeOf(accessor), ((Member) accessor).getName(), optional, constraintClasses, accessor);
ValueConstraintsInstance valueConstraintsInstance = null;
if (valueConstraintsModel.isConstrained()) {
valueConstraintsInstance = valueConstraintsModel.newInstance();
}
MetaInfo metaInfo = stateDeclarations.metaInfoFor(accessor);
Object initialValue = stateDeclarations.initialValueOf(accessor);
boolean useDefaults = metaInfo.get(UseDefaults.class) != null || stateDeclarations.useDefaults(accessor);
boolean immutable = this.immutable || metaInfo.get(Immutable.class) != null;
PropertyModel propertyModel = new PropertyModel(accessor, immutable, useDefaults, valueConstraintsInstance, metaInfo, initialValue);
return propertyModel;
}
use of org.qi4j.api.common.Optional in project qi4j-sdk by Qi4j.
the class CompositeAssemblyImpl method constraintsFor.
// Model
private ConstraintsModel constraintsFor(Method method, Iterable<Class<? extends Constraint<?, ?>>> constraintClasses) {
List<ValueConstraintsModel> parameterConstraintModels = Collections.emptyList();
Annotation[][] parameterAnnotations = method.getParameterAnnotations();
Type[] parameterTypes = method.getGenericParameterTypes();
boolean constrained = false;
for (int i = 0; i < parameterAnnotations.length; i++) {
Annotation[] parameterAnnotation = parameterAnnotations[i];
Name nameAnnotation = (Name) first(filter(isType(Name.class), iterable(parameterAnnotation)));
String name = nameAnnotation == null ? "param" + (i + 1) : nameAnnotation.value();
boolean optional = first(filter(isType(Optional.class), iterable(parameterAnnotation))) != null;
ValueConstraintsModel parameterConstraintsModel = constraintsFor(asList(parameterAnnotation), parameterTypes[i], name, optional, constraintClasses, method);
if (parameterConstraintsModel.isConstrained()) {
constrained = true;
}
if (parameterConstraintModels.isEmpty()) {
parameterConstraintModels = new ArrayList<>();
}
parameterConstraintModels.add(parameterConstraintsModel);
}
if (!constrained) {
return new ConstraintsModel(Collections.<ValueConstraintsModel>emptyList());
} else {
return new ConstraintsModel(parameterConstraintModels);
}
}
use of org.qi4j.api.common.Optional 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;
}
Aggregations