Search in sources :

Example 1 with Activator

use of org.qi4j.api.activation.Activator 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 Activator

use of org.qi4j.api.activation.Activator 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 Activator

use of org.qi4j.api.activation.Activator in project qi4j-sdk by Qi4j.

the class ServiceAssemblyImpl method activatorsDeclarations.

protected Iterable<Class<? extends Activator<?>>> activatorsDeclarations(Iterable<? extends Class<?>> typess) {
    // Find activator declarations
    ArrayList<Type> allTypes = new ArrayList<Type>();
    for (Class<?> type : typess) {
        Iterable<Type> types = Classes.typesOf(type);
        Iterables.addAll(allTypes, types);
    }
    // Find all activators and flattern them into an iterable
    Function<Type, Iterable<Class<? extends Activator<?>>>> function = new Function<Type, Iterable<Class<? extends Activator<?>>>>() {

        @Override
        public Iterable<Class<? extends Activator<?>>> map(Type type) {
            Activators activators = Annotations.annotationOn(type, Activators.class);
            if (activators == null) {
                return Iterables.empty();
            } else {
                return Iterables.iterable(activators.value());
            }
        }
    };
    Iterable<Class<? extends Activator<?>>> flatten = Iterables.flattenIterables(Iterables.map(function, allTypes));
    return Iterables.toList(flatten);
}
Also used : Function(org.qi4j.functional.Function) Type(java.lang.reflect.Type) Activators(org.qi4j.api.activation.Activators) Activator(org.qi4j.api.activation.Activator) ArrayList(java.util.ArrayList)

Example 4 with Activator

use of org.qi4j.api.activation.Activator in project qi4j-sdk by Qi4j.

the class ServiceAssemblyImpl method newServiceModel.

ServiceModel newServiceModel(StateDeclarations stateDeclarations, AssemblyHelper helper) {
    try {
        buildComposite(helper, stateDeclarations);
        List<Class<? extends Activator<?>>> activatorClasses = Iterables.toList(Iterables.<Class<? extends Activator<?>>>flatten(activators, activatorsDeclarations(types)));
        return new ServiceModel(types, visibility, metaInfo, new ActivatorsModel(activatorClasses), mixinsModel, stateModel, compositeMethodsModel, identity, instantiateOnStartup);
    } catch (Exception e) {
        throw new InvalidApplicationException("Could not register " + types, e);
    }
}
Also used : Activator(org.qi4j.api.activation.Activator) ServiceModel(org.qi4j.runtime.service.ServiceModel) ActivatorsModel(org.qi4j.runtime.activation.ActivatorsModel) InvalidApplicationException(org.qi4j.api.common.InvalidApplicationException) InvalidApplicationException(org.qi4j.api.common.InvalidApplicationException)

Aggregations

Activator (org.qi4j.api.activation.Activator)4 ArrayList (java.util.ArrayList)2 InjectionContext (org.qi4j.runtime.injection.InjectionContext)2 Type (java.lang.reflect.Type)1 Activators (org.qi4j.api.activation.Activators)1 ConstructionException (org.qi4j.api.common.ConstructionException)1 InvalidApplicationException (org.qi4j.api.common.InvalidApplicationException)1 Function (org.qi4j.functional.Function)1 ActivatorsModel (org.qi4j.runtime.activation.ActivatorsModel)1 ServiceModel (org.qi4j.runtime.service.ServiceModel)1