private BeanManagerImpl getBeanManager() { final BeanManager beanManager = this.beanManager; return beanManager == null ? null : BeanManagerProxy.unwrap(beanManager); }
static void containerInitialized(Container container, BeanManagerImpl rootBeanManager, WeldDeployment deployment) { containers.put(container, new WeldProvider.CdiImpl(container, new BeanManagerProxy(rootBeanManager), deployment)); }
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 Handler<T> getHandler() { checkBeanResolved(); return new HandlerImpl<T>(() -> getBeanInstance(bean), this, bean); }
@Override public Handler<T> getHandler() { checkBeanResolved(); return new HandlerImpl<T>(new Supplier<T>() { @Override public T get() { return getBeanInstance(bean); } }, this, bean); }
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 String toString() { return "Weld instance for deployment " + BeanManagerProxy.unwrap(rootBeanManager).getContextId(); }
@Override public Handler<T> getHandler() { checkBeanResolved(); return new HandlerImpl<T>(() -> getBeanInstance(bean), this, bean); }
@Override public void start(final StartContext context) throws StartException { beanManager = new BeanManagerProxy(weldContainerSupplier.get().getBeanManager(beanDeploymentArchiveId)); beanManagerConsumer.accept(beanManager); }
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 protected BeanManagerImpl getBeanManager() { // get the reference to the bean manager on the first invocation if (beanManager == null) { beanManager = BeanManagerProxy.unwrap((BeanManager)currentServiceContainer().getRequiredService(beanManagerServiceName).getValue()); } return beanManager; }
@Override public Handler<T> getHandler() { checkBeanResolved(); return new HandlerImpl<T>(() -> getBeanInstance(bean), this, bean); }
@Override public BeanManager getBeanManager() { checkContainerState(container); final String callerName = getCallingClassName(); if(callerName.startsWith("org.glassfish.soteria")) { //the Java EE Security RI uses CDI.current() to perform bean lookup, however //as it is part of the container its bean archive does not have visibility to deployment beans //we use this code path to enable it to get the bean manager of the current module //so it can look up the deployment beans it needs to work try { BeanManager bm = (BeanManager) new InitialContext().lookup("java:comp/BeanManager"); if(bm != null) { return bm; } } catch (NamingException e) { //ignore } } final ClassLoader tccl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged(); final Class<?> callerClass = Reflections.loadClass(callerName, tccl); if (callerClass != null) { final BeanDeploymentArchive bda = deployment.getBeanDeploymentArchive(callerClass); if (bda != null) { return new BeanManagerProxy(container.beanDeploymentArchives().get(bda)); } } // fallback for cases when we are unable to load the class or no BeanManager exists yet for the given BDA return rootBeanManager; }
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()); }
private InjectionTarget getInjectionTarget(Class<?> clazz) { InjectionTarget<?> target = injectionTargets.get(clazz); if (target != null) { return target; } final BeanManagerImpl beanManager = BeanManagerProxy.unwrap(beanManagerSupplier.get()); Bean<?> bean = null; Set<Bean<?>> beans = new HashSet<>(beanManager.getBeans(clazz, Any.Literal.INSTANCE)); Iterator<Bean<?>> it = beans.iterator(); //we may have resolved some sub-classes //go through and remove them from the bean set while (it.hasNext()) { Bean<?> b = it.next(); if(b.getBeanClass() != clazz) { it.remove(); } } if(beans.size() == 1) { bean = beans.iterator().next(); } InjectionTarget<?> newTarget = InjectionTargets.createInjectionTarget(clazz, bean, beanManager, true); target = injectionTargets.putIfAbsent(clazz, newTarget); if (target == null) { return newTarget; } else { return target; } }
@Override public Handler<T> getHandler() { checkBeanResolved(); return new HandlerImpl<T>(() -> getBeanInstance(bean), this, bean); }
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()); }
beanManager = ((BeanManagerImpl) CDI.current().getBeanManager()).unwrap(); } else { beanManager = ((BeanManagerProxy) CDI.current().getBeanManager()).unwrap();
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()); }
/** * Registers an instance supplier and its provided value as {@link JerseyBean}s into {@link BeanManager}. * * @param binding object containing {@link javax.enterprise.inject.spi.BeanAttributes} information. * @param abd {@link AfterBeanDiscovery} event. * @param <T> type of the instance which is registered. */ public static <T> void registerSupplier(SupplierInstanceBinding<T> binding, AfterBeanDiscovery abd, BeanManager beanManager) { BeanManagerImpl manager; if (beanManager instanceof BeanManagerProxy) { manager = ((BeanManagerProxy) beanManager).unwrap(); } else { manager = (BeanManagerImpl) beanManager; } /* * CDI does not provide sufficient support for ThreadScoped Supplier */ if (binding.getScope() == PerThread.class) { abd.addBean(new SupplierThreadScopeBean(binding, manager)); } else { abd.addBean(new SupplierInstanceBean<>(binding)); abd.addBean(new SupplierInstanceBeanBridge<>(binding)); } }