use of java.lang.reflect.AccessibleObject in project qi4j-sdk by Qi4j.
the class ModuleInstance method newTransientBuilder.
// Implementation of TransientBuilderFactory
@Override
public <T> TransientBuilder<T> newTransientBuilder(Class<T> mixinType) throws NoSuchTransientException {
NullArgumentException.validateNotNull("mixinType", mixinType);
ModelModule<TransientModel> modelModule = typeLookup.lookupTransientModel(mixinType);
if (modelModule == null) {
throw new NoSuchTransientException(mixinType.getName(), name());
}
Map<AccessibleObject, Property<?>> properties = new HashMap<>();
for (PropertyModel propertyModel : modelModule.model().state().properties()) {
Property<?> property = new PropertyInstance<>(propertyModel.getBuilderInfo(), propertyModel.initialValue(modelModule.module()));
properties.put(propertyModel.accessor(), property);
}
TransientStateInstance state = new TransientStateInstance(properties);
return new TransientBuilderInstance<>(modelModule, state, UsesInstance.EMPTY_USES);
}
use of java.lang.reflect.AccessibleObject 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 java.lang.reflect.AccessibleObject 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 java.lang.reflect.AccessibleObject in project qi4j-sdk by Qi4j.
the class EntityStateInstance method associationFor.
@Override
@SuppressWarnings("unchecked")
public <T> Association<T> associationFor(AccessibleObject accessor) throws IllegalArgumentException {
Map<AccessibleObject, Object> state = state();
Association<T> association = (Association<T>) state.get(accessor);
if (association == null) {
final AssociationModel associationModel = stateModel.getAssociation(accessor);
association = new AssociationInstance<>(entityState instanceof BuilderEntityState ? associationModel.getBuilderInfo() : associationModel, entityFunction, new Property<EntityReference>() {
@Override
public EntityReference get() {
return entityState.associationValueOf(associationModel.qualifiedName());
}
@Override
public void set(EntityReference newValue) throws IllegalArgumentException, IllegalStateException {
entityState.setAssociationValue(associationModel.qualifiedName(), newValue);
}
});
state.put(accessor, association);
}
return association;
}
use of java.lang.reflect.AccessibleObject 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;
}
Aggregations