Search in sources :

Example 1 with UsesInstance

use of org.qi4j.runtime.composite.UsesInstance 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<AccessibleObject, Property<?>>();
    for (PropertyModel propertyModel : stateModel.properties()) {
        Object initialValue = propertyModel.initialValue(module);
        if (propertyModel.accessor().equals(identityMethod)) {
            initialValue = identity;
        }
        Property property = new PropertyInstance<Object>(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)

Aggregations

AccessibleObject (java.lang.reflect.AccessibleObject)1 HashMap (java.util.HashMap)1 Property (org.qi4j.api.property.Property)1 MixinModel (org.qi4j.runtime.composite.MixinModel)1 TransientStateInstance (org.qi4j.runtime.composite.TransientStateInstance)1 UsesInstance (org.qi4j.runtime.composite.UsesInstance)1 InjectionContext (org.qi4j.runtime.injection.InjectionContext)1 PropertyInstance (org.qi4j.runtime.property.PropertyInstance)1 PropertyModel (org.qi4j.runtime.property.PropertyModel)1