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);
}
}
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;
}
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);
}
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);
}
}
Aggregations