@Override
public void start(StartContext context) throws StartException {
final ClassLoader oldTCCL = SecurityActions.getContextClassLoader();
try {
SecurityActions.setContextClassLoader(classLoader);
final BeanManagerImpl bm = beanManager.getValue();
final ClassTransformer transformer = bm.getServices().get(ClassTransformer.class);
final List<Injection> injectionPoints = new ArrayList<Injection>();
//we do it this way to get changes introduced by extensions
WeldClass<?> weldClass = transformer.loadClass(componentClass);
for (AnnotatedField<?> field : weldClass.getFields()) {
if (field.isAnnotationPresent(Inject.class)) {
final Set<Annotation> qualifiers = new HashSet<Annotation>();
for (Annotation annotation : field.getAnnotations()) {
if (bm.isQualifier(annotation.annotationType())) {
qualifiers.add(annotation);
}
}
FieldInjectionPoint ip = new FieldInjectionPoint(field, qualifiers);
Set<Bean<?>> beans = bm.getBeans(ip);
if (beans.size() > 1) {
throw new StartException("Error resolving CDI injection point " + field + " on " + componentClass + ". Injection points is ambiguous " + beans);
} else if (beans.isEmpty()) {
throw new StartException("Error resolving CDI injection point " + field + " on " + componentClass + ". No bean satisfies the injection point.");
}
Bean<?> bean = bm.resolve(beans);
injectionPoints.add(new CDIFieldInjection(field.getJavaMember(), bean));
}
}
//now look for @Inject methods
for (AnnotatedMethod<?> method : weldClass.getMethods()) {
if (method.isAnnotationPresent(Inject.class)) {
final List<Bean<?>> parameterBeans = new ArrayList<Bean<?>>();
for (AnnotatedParameter<?> param : method.getParameters()) {
final Set<Annotation> qualifiers = new HashSet<Annotation>();
for (Annotation annotation : param.getAnnotations()) {
if (bm.isQualifier(annotation.annotationType())) {
qualifiers.add(annotation);
}
}
ParameterInjectionPoint ip = new ParameterInjectionPoint(param, qualifiers);
Set<Bean<?>> beans = bm.getBeans(ip);
if (beans.size() > 1) {
throw new StartException("Error resolving CDI injection point " + param + " on " + componentClass + ". Injection points is ambiguous " + beans);
} else if (beans.isEmpty()) {
throw new StartException("Error resolving CDI injection point " + param + " on " + componentClass + ". No bean satisfies the injection point.");
}
Bean<?> bean = bm.resolve(beans);
parameterBeans.add(bean);
}
injectionPoints.add(new CDIMethodInjection(method.getJavaMember(), parameterBeans));
}
}