try {
Class<? extends IOCExtensionConfigurator> configuratorClass = clazz.asSubclass(IOCExtensionConfigurator.class);
configuratorClass.newInstance().configure(procContext, injectFactory, procFactory);
}
catch (Exception e) {
throw new ErraiBootstrapFailure("unable to load IOC Extension Configurator: " + e.getMessage(), e);
}
}
/**
* CodeDecorator.class
*/
Set<Class<?>> decorators = scanner.getTypesAnnotatedWith(CodeDecorator.class);
for (Class<?> clazz : decorators) {
try {
Class<? extends Decorator> decoratorClass = clazz.asSubclass(Decorator.class);
Class<? extends Annotation> annoType = null;
Type t = decoratorClass.getGenericSuperclass();
if (!(t instanceof ParameterizedType)) {
throw new ErraiBootstrapFailure("code decorator must extend Decorator<@AnnotationType>");
}
ParameterizedType pType = (ParameterizedType) t;
if (Decorator.class.equals(pType.getRawType())) {
if (pType.getActualTypeArguments().length == 0 || !Annotation.class.isAssignableFrom((Class) pType.getActualTypeArguments()[0])) {
throw new ErraiBootstrapFailure("code decorator must extend Decorator<@AnnotationType>");
}
annoType = ((Class) pType.getActualTypeArguments()[0]).asSubclass(Annotation.class);
}
injectFactory.getInjectionContext().registerDecorator(decoratorClass.getConstructor(new Class[]{Class.class}).newInstance(annoType));
}
catch (Exception e) {
throw new ErraiBootstrapFailure("unable to load code decorator: " + e.getMessage(), e);
}
}
/**
* Provider.class
*/
Set<Class<?>> providers = scanner.getTypesAnnotatedWith(Provider.class);
for (Class<?> clazz : providers) {
JClassType bindType = null;
JClassType type = loadType(typeOracle, clazz);
boolean contextual = false;
for (JClassType iface : type.getImplementedInterfaces()) {
if (iface.getQualifiedSourceName().equals(ContextualTypeProvider.class.getName())) {
contextual = true;
JParameterizedType pType = iface.isParameterized();
if (pType == null) {
throw new InjectionFailure("could not determine the bind type for the Provider class: " + type.getQualifiedSourceName());
}
bindType = pType.getTypeArgs()[0];
break;
}
}
if (bindType == null) {
for (JClassType iface : type.getImplementedInterfaces()) {
if (!typeProviderCls.isAssignableFrom(iface)) {
continue;
}
JParameterizedType pType = iface.isParameterized();
if (pType == null) {
throw new InjectionFailure("could not determine the bind type for the Provider class: " + type.getQualifiedSourceName());
}
bindType = pType.getTypeArgs()[0];
}
}
if (bindType == null) {
throw new InjectionFailure("the annotated provider class does not appear to implement " +
TypeProvider.class.getName() + ": " + type.getQualifiedSourceName());
}
final JClassType finalBindType = bindType;
if (contextual) {
injectFactory.addInjector(new ContextualProviderInjector(finalBindType, type));
} else {
injectFactory.addInjector(new ProviderInjector(finalBindType, type));
}
}
/**
* GeneratedBy.class
*/
Set<Class<?>> generatedBys = scanner.getTypesAnnotatedWith(GeneratedBy.class);
for (Class<?> clazz : generatedBys) {
JClassType type = loadType(typeOracle, clazz);
GeneratedBy anno = type.getAnnotation(GeneratedBy.class);
Class<? extends ContextualTypeProvider> injectorClass = anno.value();
try {
injectFactory.addInjector(new ContextualProviderInjector(type, getJClassType(injectorClass)));
}
catch (Exception e) {
throw new ErraiBootstrapFailure("could not load injector: " + e.getMessage(), e);
}
}
}