Search in sources :

Example 1 with InjectionContext

use of org.qi4j.runtime.injection.InjectionContext in project qi4j-sdk by Qi4j.

the class ActivatorModel method newInstance.

@SuppressWarnings("unchecked")
public Activator<ActivateeType> newInstance(InjectionContext injectionContext) {
    try {
        Activator<ActivateeType> instance = (Activator<ActivateeType>) constructorsModel.newInstance(injectionContext);
        injectionContext = new InjectionContext(injectionContext.module(), injectionContext.uses(), instance);
        inject(injectionContext, instance);
        return instance;
    } catch (Exception ex) {
        throw new ConstructionException("Could not instantiate " + activatorType.getName(), ex);
    }
}
Also used : Activator(org.qi4j.api.activation.Activator) ConstructionException(org.qi4j.api.common.ConstructionException) ConstructionException(org.qi4j.api.common.ConstructionException) InjectionContext(org.qi4j.runtime.injection.InjectionContext)

Example 2 with InjectionContext

use of org.qi4j.runtime.injection.InjectionContext in project qi4j-sdk by Qi4j.

the class ActivatorsModel method newInstances.

public Iterable<Activator<ActivateeType>> newInstances(Module module) throws ActivationException {
    List<Activator<ActivateeType>> activators = new ArrayList<>();
    for (ActivatorModel<ActivateeType> activatorModel : activatorModels) {
        InjectionContext injectionContext = new InjectionContext((ModuleInstance) module, UsesInstance.EMPTY_USES);
        activators.add(activatorModel.newInstance(injectionContext));
    }
    return activators;
}
Also used : Activator(org.qi4j.api.activation.Activator) ArrayList(java.util.ArrayList) InjectionContext(org.qi4j.runtime.injection.InjectionContext)

Example 3 with InjectionContext

use of org.qi4j.runtime.injection.InjectionContext in project qi4j-sdk by Qi4j.

the class ModuleInstance method newObject.

// Implementation of ObjectFactory
@Override
public <T> T newObject(Class<T> mixinType, Object... uses) throws NoSuchObjectException {
    NullArgumentException.validateNotNull("mixinType", mixinType);
    ModelModule<ObjectModel> modelModule = typeLookup.lookupObjectModel(mixinType);
    if (modelModule == null) {
        throw new NoSuchObjectException(mixinType.getName(), name());
    }
    InjectionContext injectionContext = new InjectionContext(modelModule.module(), UsesInstance.EMPTY_USES.use(uses));
    return mixinType.cast(modelModule.model().newInstance(injectionContext));
}
Also used : ObjectModel(org.qi4j.runtime.object.ObjectModel) NoSuchObjectException(org.qi4j.api.object.NoSuchObjectException) InjectionContext(org.qi4j.runtime.injection.InjectionContext)

Example 4 with InjectionContext

use of org.qi4j.runtime.injection.InjectionContext in project qi4j-sdk by Qi4j.

the class ModuleInstance method injectTo.

@Override
public void injectTo(Object instance, Object... uses) throws ConstructionException {
    NullArgumentException.validateNotNull("instance", instance);
    ModelModule<ObjectModel> modelModule = typeLookup.lookupObjectModel(instance.getClass());
    if (modelModule == null) {
        throw new NoSuchObjectException(instance.getClass().getName(), name());
    }
    InjectionContext injectionContext = new InjectionContext(modelModule.module(), UsesInstance.EMPTY_USES.use(uses));
    modelModule.model().inject(injectionContext, instance);
}
Also used : ObjectModel(org.qi4j.runtime.object.ObjectModel) NoSuchObjectException(org.qi4j.api.object.NoSuchObjectException) InjectionContext(org.qi4j.runtime.injection.InjectionContext)

Example 5 with InjectionContext

use of org.qi4j.runtime.injection.InjectionContext in project qi4j-sdk by Qi4j.

the class EntityMixinsModel method newMixin.

public Object newMixin(EntityInstance entityInstance, StateHolder state, Object[] mixins, Method method) {
    MixinModel model = methodImplementation.get(method);
    InjectionContext injectionContext = new InjectionContext(entityInstance, UsesInstance.EMPTY_USES, state);
    Object mixin = model.newInstance(injectionContext);
    mixins[methodIndex.get(method)] = mixin;
    return mixin;
}
Also used : MixinModel(org.qi4j.runtime.composite.MixinModel) InjectionContext(org.qi4j.runtime.injection.InjectionContext)

Aggregations

InjectionContext (org.qi4j.runtime.injection.InjectionContext)10 ConstructionException (org.qi4j.api.common.ConstructionException)3 MixinModel (org.qi4j.runtime.composite.MixinModel)3 Activator (org.qi4j.api.activation.Activator)2 NoSuchObjectException (org.qi4j.api.object.NoSuchObjectException)2 ObjectModel (org.qi4j.runtime.object.ObjectModel)2 AccessibleObject (java.lang.reflect.AccessibleObject)1 InvocationHandler (java.lang.reflect.InvocationHandler)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Initializable (org.qi4j.api.mixin.Initializable)1 InitializationException (org.qi4j.api.mixin.InitializationException)1 Property (org.qi4j.api.property.Property)1 TransientStateInstance (org.qi4j.runtime.composite.TransientStateInstance)1 UsesInstance (org.qi4j.runtime.composite.UsesInstance)1 PropertyInstance (org.qi4j.runtime.property.PropertyInstance)1 PropertyModel (org.qi4j.runtime.property.PropertyModel)1