Search in sources :

Example 1 with PropertyInstance

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

the class TransientBuilderInstance method newInstance.

@Override
public T newInstance() throws ConstructionException {
    // Set correct info's (immutable) on the state
    for (PropertyDescriptor propertyDescriptor : model.model().state().properties()) {
        ((PropertyInstance<Object>) state.propertyFor(propertyDescriptor.accessor())).setPropertyInfo((PropertyInfo) propertyDescriptor);
    }
    model.model().checkConstraints(state);
    CompositeInstance compositeInstance = model.model().newInstance(model.module(), uses, state);
    return compositeInstance.<T>proxy();
}
Also used : PropertyDescriptor(org.qi4j.api.property.PropertyDescriptor) CompositeInstance(org.qi4j.api.composite.CompositeInstance) PropertyInstance(org.qi4j.runtime.property.PropertyInstance)

Example 2 with PropertyInstance

use of org.qi4j.runtime.property.PropertyInstance 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);
}
Also used : NoSuchTransientException(org.qi4j.api.composite.NoSuchTransientException) TransientStateInstance(org.qi4j.runtime.composite.TransientStateInstance) TransientModel(org.qi4j.runtime.composite.TransientModel) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) PropertyModel(org.qi4j.runtime.property.PropertyModel) TransientBuilderInstance(org.qi4j.runtime.composite.TransientBuilderInstance) AccessibleObject(java.lang.reflect.AccessibleObject) PropertyInstance(org.qi4j.runtime.property.PropertyInstance) Property(org.qi4j.api.property.Property)

Example 3 with PropertyInstance

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

the class ServiceModel method newInstance.

public ServiceInstance newInstance(final ModuleInstance module) {
    Object[] mixins = mixinsModel.newMixinHolder();
    Map<AccessibleObject, Property<?>> properties = new HashMap<>();
    for (PropertyModel propertyModel : stateModel.properties()) {
        Object initialValue = propertyModel.initialValue(module);
        if (propertyModel.accessor().equals(identityMethod)) {
            initialValue = identity;
        }
        Property<?> property = new PropertyInstance<>(propertyModel, initialValue);
        properties.put(propertyModel.accessor(), property);
    }
    TransientStateInstance state = new TransientStateInstance(properties);
    ServiceInstance compositeInstance = new ServiceInstance(this, module, mixins, state);
    // Instantiate all mixins
    int i = 0;
    UsesInstance uses = UsesInstance.EMPTY_USES.use(this);
    InjectionContext injectionContext = new InjectionContext(compositeInstance, uses, state);
    for (MixinModel mixinModel : mixinsModel.mixinModels()) {
        mixins[i++] = mixinModel.newInstance(injectionContext);
    }
    return compositeInstance;
}
Also used : UsesInstance(org.qi4j.runtime.composite.UsesInstance) MixinModel(org.qi4j.runtime.composite.MixinModel) HashMap(java.util.HashMap) PropertyModel(org.qi4j.runtime.property.PropertyModel) PropertyInstance(org.qi4j.runtime.property.PropertyInstance) InjectionContext(org.qi4j.runtime.injection.InjectionContext) TransientStateInstance(org.qi4j.runtime.composite.TransientStateInstance) AccessibleObject(java.lang.reflect.AccessibleObject) AccessibleObject(java.lang.reflect.AccessibleObject) Property(org.qi4j.api.property.Property)

Example 4 with PropertyInstance

use of org.qi4j.runtime.property.PropertyInstance 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 5 with PropertyInstance

use of org.qi4j.runtime.property.PropertyInstance 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

PropertyInstance (org.qi4j.runtime.property.PropertyInstance)5 PropertyModel (org.qi4j.runtime.property.PropertyModel)4 AccessibleObject (java.lang.reflect.AccessibleObject)2 HashMap (java.util.HashMap)2 Property (org.qi4j.api.property.Property)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 CompositeInstance (org.qi4j.api.composite.CompositeInstance)1 NoSuchTransientException (org.qi4j.api.composite.NoSuchTransientException)1 PropertyDescriptor (org.qi4j.api.property.PropertyDescriptor)1 MixinModel (org.qi4j.runtime.composite.MixinModel)1 TransientBuilderInstance (org.qi4j.runtime.composite.TransientBuilderInstance)1 TransientModel (org.qi4j.runtime.composite.TransientModel)1 UsesInstance (org.qi4j.runtime.composite.UsesInstance)1 InjectionContext (org.qi4j.runtime.injection.InjectionContext)1