Search in sources :

Example 1 with InvalidValueCompositeException

use of org.qi4j.api.composite.InvalidValueCompositeException in project qi4j-sdk by Qi4j.

the class InjectionProviderFactoryStrategy method newInjectionProvider.

@Override
public InjectionProvider newInjectionProvider(Resolution resolution, DependencyModel dependencyModel) throws InvalidInjectionException {
    Class<? extends Annotation> injectionAnnotationType = dependencyModel.injectionAnnotation().annotationType();
    InjectionProviderFactory factory1 = generalProviderFactories.get(injectionAnnotationType);
    InjectionProviderFactory factory2 = valuesProviderFactories.get(injectionAnnotationType);
    if (factory1 == null && factory2 == null) {
        InjectionProviderFactory factory = metaInfo.get(InjectionProviderFactory.class);
        if (factory != null) {
            return factory.newInjectionProvider(resolution, dependencyModel);
        } else {
            throw new InvalidInjectionException("Unknown injection annotation @" + injectionAnnotationType.getSimpleName());
        }
    }
    ModelDescriptor composite = resolution.model();
    Class<?> compositeType = first(composite.types());
    if (factory1 != null && ValueComposite.class.isAssignableFrom(compositeType)) {
        throw new InvalidValueCompositeException("@" + injectionAnnotationType.getSimpleName() + " is not allowed in ValueComposites: " + compositeType);
    }
    InjectionProviderFactory factory;
    if (factory1 == null) {
        factory = factory2;
    } else {
        factory = factory1;
    }
    return factory.newInjectionProvider(resolution, dependencyModel);
}
Also used : InvalidValueCompositeException(org.qi4j.api.composite.InvalidValueCompositeException) InvalidInjectionException(org.qi4j.bootstrap.InvalidInjectionException) ModelDescriptor(org.qi4j.api.composite.ModelDescriptor) ValueComposite(org.qi4j.api.value.ValueComposite) InjectionProviderFactory(org.qi4j.runtime.injection.InjectionProviderFactory)

Aggregations

InvalidValueCompositeException (org.qi4j.api.composite.InvalidValueCompositeException)1 ModelDescriptor (org.qi4j.api.composite.ModelDescriptor)1 ValueComposite (org.qi4j.api.value.ValueComposite)1 InvalidInjectionException (org.qi4j.bootstrap.InvalidInjectionException)1 InjectionProviderFactory (org.qi4j.runtime.injection.InjectionProviderFactory)1