/** Produces a new bean instance */ private T produce(X factory, CreationalContextImpl<T> env) { try { // InjectManager inject = getBeanManager(); Object[] args; if (_producesArgs.length > 0) { args = new Object[_producesArgs.length]; for (int i = 0; i < args.length; i++) { if (_producesArgs[i] instanceof InjectionPointArg<?>) args[i] = env.findInjectionPoint(); else args[i] = _producesArgs[i].eval((CreationalContext) env); } } else args = NULL_ARGS; Method method = _producesMethod.getJavaMember(); if (factory instanceof ScopeProxy && !Modifier.isPublic(method.getModifiers())) { // ioc/0714 ScopeProxy proxy = (ScopeProxy) factory; factory = (X) proxy.__caucho_getDelegate(); } T value = (T) method.invoke(factory, args); env.push(value); if (value != null) return value; if (Dependent.class.equals(getScope())) return null; throw new IllegalProductException( L.l("producer {0} returned null, which is not allowed by the CDI spec.", this)); } catch (RuntimeException e) { throw e; } catch (InvocationTargetException e) { if (e.getCause() instanceof RuntimeException) throw (RuntimeException) e.getCause(); else throw new CreationException(e.getCause()); } catch (Exception e) { throw new CreationException(e); } }