FieldInjectProgram(Field field, InjectionPoint ip) { _field = field; _field.setAccessible(true); _ip = ip; InjectManager beanManager = getBeanManager(); try { _fieldFactory = beanManager.getReferenceFactory(_ip); } catch (AmbiguousResolutionException e) { String loc = getLocation(field); throw new AmbiguousResolutionException(loc + e.getMessage(), e); } catch (UnsatisfiedResolutionException e) { String loc = getLocation(field); throw new UnsatisfiedResolutionException(loc + e.getMessage(), e); } catch (IllegalProductException e) { String loc = getLocation(field); throw new IllegalProductException(loc + e.getMessage(), e); } catch (InjectionException e) { String loc = getLocation(field); throw new InjectionException(loc + e.getMessage(), e); } }
private void introspectInjectClass( AnnotatedType<X> type, ArrayList<ConfigProgram> injectProgramList) { InjectManager cdiManager = getBeanManager(); for (Annotation ann : type.getAnnotations()) { Class<? extends Annotation> annType = ann.annotationType(); InjectionPointHandler handler = cdiManager.getInjectionPointHandler(annType); if (handler != null) { injectProgramList.add(new ClassHandlerProgram(ann, handler)); } } // ioc/123i for (Class<?> parentClass = type.getJavaClass().getSuperclass(); parentClass != null; parentClass = parentClass.getSuperclass()) { for (Annotation ann : parentClass.getAnnotations()) { Class<? extends Annotation> annType = ann.annotationType(); InjectionPointHandler handler = cdiManager.getInjectionPointHandler(annType); if (handler != null) { injectProgramList.add(new ClassHandlerProgram(ann, handler)); } } } }
protected Object getInstance() { Bean<X> bean = getParentBean(); Class<?> type = bean.getBeanClass(); if (_isIfExists) { Class scopeType = bean.getScope(); Context context = _beanManager.getContext(scopeType); if (context != null) return context.get(bean); else return null; } CreationalContext env = _beanManager.createCreationalContext(getParentBean()); return _beanManager.getReference(getParentBean(), type, env); }
private void introspect() { List<AnnotatedParameter<X>> parameters = _method.getParameters(); /* if (parameters.size() == 1) { if (parameters.get(0).isAnnotationPresent(IfExists.class)) { _isIfExists = true; } return; } */ _args = new BeanArg[parameters.size()]; for (int i = 0; i < _args.length; i++) { AnnotatedParameter<?> param = parameters.get(i); Observes observes = param.getAnnotation(Observes.class); if (observes != null) { _isIfExists = observes.notifyObserver() == Reception.IF_EXISTS; } else { _args[i] = new BeanArg(param.getBaseType(), _beanManager.getQualifiers(param.getAnnotations())); } } }
protected Object[] getEventArguments(Object event) { if (_args == null) return new Object[] {event}; Object[] args = new Object[_args.length]; CreationalContext<?> env = _beanManager.createCreationalContext(getParentBean()); for (int i = 0; i < _args.length; i++) { BeanArg arg = _args[i]; if (arg != null) args[i] = arg.eval(env); else args[i] = event; } return args; }
private void introspectInject(AnnotatedType<X> type, ArrayList<ConfigProgram> injectProgramList) { Class<?> rawType = (Class<?>) type.getBaseType(); if (rawType == null || Object.class.equals(rawType)) return; // Class<?> parentClass = rawType.getSuperclass(); // configureClassResources(injectList, type); introspectInjectClass(type, injectProgramList); introspectInjectField(type, injectProgramList); introspectInjectMethod(type, injectProgramList); ResourceProgramManager resourceManager = _cdiManager.getResourceManager(); resourceManager.buildInject(rawType, injectProgramList); }