Search in sources :

Example 6 with PropertyModel

use of org.qi4j.runtime.property.PropertyModel in project qi4j-sdk by Qi4j.

the class EntityStateInstance method propertyFor.

@Override
@SuppressWarnings("unchecked")
public <T> Property<T> propertyFor(AccessibleObject accessor) throws IllegalArgumentException {
    Map<AccessibleObject, Object> state = state();
    Property<T> property = (Property<T>) state.get(accessor);
    if (property == null) {
        PropertyModel entityPropertyModel = stateModel.propertyModelFor(accessor);
        property = new EntityPropertyInstance<>(entityState instanceof BuilderEntityState ? entityPropertyModel.getBuilderInfo() : entityPropertyModel, entityState);
        state.put(accessor, property);
    }
    return property;
}
Also used : PropertyModel(org.qi4j.runtime.property.PropertyModel) AccessibleObject(java.lang.reflect.AccessibleObject) AccessibleObject(java.lang.reflect.AccessibleObject) BuilderEntityState(org.qi4j.runtime.unitofwork.BuilderEntityState) Property(org.qi4j.api.property.Property)

Example 7 with PropertyModel

use of org.qi4j.runtime.property.PropertyModel in project qi4j-sdk by Qi4j.

the class ValueAssemblyImpl method newPropertyModel.

@Override
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);
    boolean useDefaults = metaInfo.get(UseDefaults.class) != null || stateDeclarations.useDefaults(accessor);
    Object initialValue = stateDeclarations.initialValueOf(accessor);
    return new PropertyModel(accessor, true, useDefaults, valueConstraintsInstance, metaInfo, initialValue);
}
Also used : Optional(org.qi4j.api.common.Optional) MetaInfo(org.qi4j.api.common.MetaInfo) PropertyModel(org.qi4j.runtime.property.PropertyModel) ValueConstraintsModel(org.qi4j.runtime.composite.ValueConstraintsModel) AccessibleObject(java.lang.reflect.AccessibleObject) ValueConstraintsInstance(org.qi4j.runtime.composite.ValueConstraintsInstance) Annotation(java.lang.annotation.Annotation)

Example 8 with PropertyModel

use of org.qi4j.runtime.property.PropertyModel 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);
    }
}
Also used : PropertyModel(org.qi4j.runtime.property.PropertyModel) ManyAssociationModel(org.qi4j.runtime.association.ManyAssociationModel) PropertyInstance(org.qi4j.runtime.property.PropertyInstance) AssociationModel(org.qi4j.runtime.association.AssociationModel) ManyAssociationModel(org.qi4j.runtime.association.ManyAssociationModel)

Example 9 with PropertyModel

use of org.qi4j.runtime.property.PropertyModel 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());
    }
}
Also used : PropertyModel(org.qi4j.runtime.property.PropertyModel) ManyAssociationModel(org.qi4j.runtime.association.ManyAssociationModel) PropertyInstance(org.qi4j.runtime.property.PropertyInstance) AssociationModel(org.qi4j.runtime.association.AssociationModel) ManyAssociationModel(org.qi4j.runtime.association.ManyAssociationModel)

Aggregations

PropertyModel (org.qi4j.runtime.property.PropertyModel)9 AccessibleObject (java.lang.reflect.AccessibleObject)6 PropertyInstance (org.qi4j.runtime.property.PropertyInstance)4 Annotation (java.lang.annotation.Annotation)3 MetaInfo (org.qi4j.api.common.MetaInfo)3 Optional (org.qi4j.api.common.Optional)3 Property (org.qi4j.api.property.Property)3 ValueConstraintsInstance (org.qi4j.runtime.composite.ValueConstraintsInstance)3 ValueConstraintsModel (org.qi4j.runtime.composite.ValueConstraintsModel)3 HashMap (java.util.HashMap)2 AssociationModel (org.qi4j.runtime.association.AssociationModel)2 ManyAssociationModel (org.qi4j.runtime.association.ManyAssociationModel)2 TransientStateInstance (org.qi4j.runtime.composite.TransientStateInstance)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 NoSuchTransientException (org.qi4j.api.composite.NoSuchTransientException)1 IdentityGenerator (org.qi4j.api.entity.IdentityGenerator)1 NoSuchServiceException (org.qi4j.api.service.NoSuchServiceException)1 EntityTypeNotFoundException (org.qi4j.api.unitofwork.EntityTypeNotFoundException)1 Annotations.hasAnnotation (org.qi4j.api.util.Annotations.hasAnnotation)1 FunctionStateResolver (org.qi4j.runtime.composite.FunctionStateResolver)1