Refine search
private <U extends T> WeldInstance<U> selectInstance(Type subtype, Annotation[] newQualifiers) { InjectionPoint modifiedInjectionPoint = new FacadeInjectionPoint(getBeanManager(), getInjectionPoint(), Instance.class, subtype, getQualifiers(), newQualifiers); return new InstanceImpl<U>(modifiedInjectionPoint, getCreationalContext(), getBeanManager()); }
@Override public boolean isResolvable() { return allBeans().size() == 1; }
public T get() { checkBeanResolved(); return getBeanInstance(bean); }
private T getBeanInstance(Bean<?> bean) { final ThreadLocalStackReference<InjectionPoint> stack = currentInjectionPoint.pushConditionally(ip, isRegisterableInjectionPoint()); try { return Reflections.<T> cast(getBeanManager().getReference(bean, getType(), getCreationalContext(), false)); } finally { stack.pop(); } }
private void checkBeanResolved() { if (bean != null) { return; } else if (isUnsatisfied()) { throw BeanManagerLogger.LOG.injectionPointHasUnsatisfiedDependencies(Formats.formatAnnotations(ip.getQualifiers()), Formats.formatInjectionPointType(ip.getType()), InjectionPoints.getUnsatisfiedDependenciesAdditionalInfo(ip, getBeanManager())); } else { throw BeanManagerLogger.LOG.injectionPointHasAmbiguousDependencies(Formats.formatAnnotations(ip.getQualifiers()), Formats.formatInjectionPointType(ip.getType()), WeldCollections.toMultiRowString(allBeans())); } }
private BeanIterator(Set<Bean<?>> beans) { this.delegate = beans.iterator(); }
private Set<Bean<?>> resolveBeans() { // Perform typesafe resolution, and possibly attempt to resolve the ambiguity Resolvable resolvable = new ResolvableBuilder(getType(), getBeanManager()).addQualifiers(getQualifiers()) .setDeclaringBean(getInjectionPoint().getBean()).create(); TypeSafeBeanResolver beanResolver = getBeanManager().getBeanResolver(); return beanResolver.resolve(beanResolver.resolve(resolvable, Reflections.isCacheable(getQualifiers()))); }
@Override public void destroy(T instance) { checkNotNull(instance); // Attempt to destroy instance which is either a client proxy or a dependent session bean proxy if (instance instanceof ProxyObject) { ProxyObject proxy = (ProxyObject) instance; if (proxy.weld_getHandler() instanceof ProxyMethodHandler) { ProxyMethodHandler handler = (ProxyMethodHandler) proxy.weld_getHandler(); Bean<?> bean = handler.getBean(); if (isSessionBeanProxy(instance) && Dependent.class.equals(bean.getScope())) { // Destroy internal reference to a dependent session bean destroyDependentInstance(instance); return; } else { // Destroy contextual instance of a normal-scoped bean Context context = getBeanManager().getContext(bean.getScope()); if (context instanceof AlterableContext) { AlterableContext alterableContext = (AlterableContext) context; alterableContext.destroy(bean); return; } else { throw BeanLogger.LOG.destroyUnsupported(context); } } } } // Attempt to destroy dependent instance which is neither a client proxy nor a dependent session bean proxy destroyDependentInstance(instance); }
private void destroyDependentInstance(T instance) { CreationalContext<? super T> ctx = getCreationalContext(); if (ctx instanceof WeldCreationalContext<?>) { WeldCreationalContext<? super T> weldCtx = cast(ctx); weldCtx.destroyDependentInstance(instance); } }
@Override public Comparator<Handler<?>> getPriorityComparator() { return new PriorityComparator(getBeanManager().getServices().get(AnnotationApiAbstraction.class)); }
/** * Gets a string representation * * @return A string representation */ @Override public String toString() { return Formats.formatAnnotations(getQualifiers()) + " Instance<" + Formats.formatType(getType()) + ">"; }
@Override @SuppressWarnings("unchecked") public <X> WeldInstance<X> select(Type subtype, Annotation... qualifiers) { // verify if this was invoked on WeldInstance<Object> if (!this.getType().equals(Object.class)) { throw BeanLogger.LOG.selectByTypeOnlyWorksOnObject(); } // This cast should be safe, we make sure that this method is only invoked on WeldInstance<Object> // and any type X will always extend Object return (WeldInstance<X>)selectInstance(subtype, qualifiers); }
@Override public void destroy(T instance) { Preconditions.checkNotNull(instance); // Attempt to destroy instance which is either a client proxy or a dependent session bean proxy if (instance instanceof ProxyObject) { ProxyObject proxy = (ProxyObject) instance; if (proxy.getHandler() instanceof ProxyMethodHandler) { ProxyMethodHandler handler = (ProxyMethodHandler) proxy.getHandler(); Bean<?> bean = handler.getBean(); if (instance instanceof EnterpriseBeanInstance && Dependent.class.equals(bean.getScope())) { // Destroy internal reference to a dependent session bean destroyDependentInstance(instance); return; } else { // Destroy contextual instance of a normal-scoped bean Context context = getBeanManager().getContext(bean.getScope()); if (context instanceof AlterableContext) { AlterableContext alterableContext = (AlterableContext) context; alterableContext.destroy(bean); return; } else { throw BeanLogger.LOG.destroyUnsupported(context); } } } } // Attempt to destroy dependent instance which is neither a client proxy nor a dependent session bean proxy destroyDependentInstance(instance); }
public static <I> Instance<I> of(InjectionPoint injectionPoint, CreationalContext<I> creationalContext, BeanManagerImpl beanManager) { return new InstanceImpl<I>(injectionPoint, creationalContext, beanManager); }
@Override public Handler<T> getHandler() { checkBeanResolved(); return new HandlerImpl<T>(new Supplier<T>() { @Override public T get() { return getBeanInstance(bean); } }, this, bean); }
private void checkBeanResolved() { if (bean != null) { return; } else if (isUnsatisfied()) { throw BeanManagerLogger.LOG.injectionPointHasUnsatisfiedDependencies(Formats.formatAnnotations(ip.getQualifiers()), Formats.formatInjectionPointType(ip.getType()), InjectionPoints.getUnsatisfiedDependenciesAdditionalInfo(ip, getBeanManager())); } else { throw BeanManagerLogger.LOG.injectionPointHasAmbiguousDependencies(Formats.formatAnnotations(ip.getQualifiers()), Formats.formatInjectionPointType(ip.getType()), WeldCollections.toMultiRowString(allBeans())); } }
private BeanIterator(Set<Bean<?>> beans) { this.delegate = beans.iterator(); }
private Set<Bean<?>> resolveBeans() { // Perform typesafe resolution, and possibly attempt to resolve the ambiguity Resolvable resolvable = new ResolvableBuilder(getType(), getBeanManager()).addQualifiers(getQualifiers()) .setDeclaringBean(getInjectionPoint().getBean()).create(); TypeSafeBeanResolver beanResolver = getBeanManager().getBeanResolver(); return beanResolver.resolve(beanResolver.resolve(resolvable, Reflections.isCacheable(getQualifiers()))); }
private T getBeanInstance(Bean<?> bean) { final ThreadLocalStackReference<InjectionPoint> stack = currentInjectionPoint.pushConditionally(ip, isRegisterableInjectionPoint()); try { return Reflections.<T> cast(getBeanManager().getReference(bean, getType(), getCreationalContext(), false)); } finally { stack.pop(); } }
@Override public void destroy(T instance) { checkNotNull(instance); // Attempt to destroy instance which is either a client proxy or a dependent session bean proxy if (instance instanceof ProxyObject) { ProxyObject proxy = (ProxyObject) instance; if (proxy.weld_getHandler() instanceof ProxyMethodHandler) { ProxyMethodHandler handler = (ProxyMethodHandler) proxy.weld_getHandler(); Bean<?> bean = handler.getBean(); if (isSessionBeanProxy(instance) && Dependent.class.equals(bean.getScope())) { // Destroy internal reference to a dependent session bean destroyDependentInstance(instance); return; } else { // Destroy contextual instance of a normal-scoped bean Context context = getBeanManager().getContext(bean.getScope()); if (context instanceof AlterableContext) { AlterableContext alterableContext = (AlterableContext) context; alterableContext.destroy(bean); return; } else { throw BeanLogger.LOG.destroyUnsupported(context); } } } } // Attempt to destroy dependent instance which is neither a client proxy nor a dependent session bean proxy destroyDependentInstance(instance); }