webBeansContext.registerService(ResourceInjectionService.class, new CdiResourceInjectionService(webBeansContext));
@Override public void injectJavaEEResources(final Object managedBeanInstance) { if (managedBeanInstance == null) { return; } final Class<?> managedBeanInstanceClass = managedBeanInstance.getClass(); if (ejbPlugin.isSessionBean(managedBeanInstanceClass)) { // already done return; } final ObjectRecipe receipe = PassthroughFactory.recipe(managedBeanInstance); receipe.allow(Option.FIELD_INJECTION); receipe.allow(Option.PRIVATE_PROPERTIES); receipe.allow(Option.IGNORE_MISSING_PROPERTIES); receipe.allow(Option.NAMED_PARAMETERS); fillInjectionProperties(receipe, managedBeanInstance); receipe.create(); }
@SuppressWarnings("unchecked") private void fillInjectionProperties(final ObjectRecipe objectRecipe, final Object managedBeanInstance) { final boolean usePrefix = true; final Class<?> clazz = managedBeanInstance.getClass(); for (final BeanContext beanContext : compContexts) { for (final Injection injection : beanContext.getInjections()) { if (injection.getTarget() == null) { continue; } if (!injection.getTarget().isAssignableFrom(clazz)) { continue; } try { final Object value = lookup(beanContext, injection); final String prefix; if (usePrefix) { prefix = injection.getTarget().getName() + "/"; } else { prefix = ""; } objectRecipe.setProperty(prefix + injection.getName(), value); } catch (final NamingException e) { logger.warning("Injection data not found in JNDI context: jndiName='" + injection.getJndiName() + "', target=" + injection.getTarget().getName() + "/" + injection.getName()); } } } }
public void stop() throws OpenEJBException { final ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); try { // Setting context class loader for cleaning Thread.currentThread().setContextClassLoader(classLoader); // Fire shut down webBeansContext.getBeanManagerImpl().fireEvent(new BeforeShutdownImpl()); // Destroys context this.contexsServices.destroy(null); // Free all plugin resources webBeansContext.getPluginLoader().shutDown(); // Clear extensions webBeansContext.getExtensionLoader().clear(); // Delete Resolutions Cache webBeansContext.getBeanManagerImpl().getInjectionResolver().clearCaches(); // Delete AnnotateTypeCache webBeansContext.getAnnotatedElementFactory().clear(); // Clear the resource injection service final CdiResourceInjectionService injectionServices = (CdiResourceInjectionService) webBeansContext.getService(ResourceInjectionService.class); injectionServices.clear(); // Clear singleton list WebBeansFinder.clearInstances(WebBeansUtil.getCurrentClassLoader()); } catch (final Exception e) { throw new OpenEJBException(e); } finally { Thread.currentThread().setContextClassLoader(oldCl); } }
injectionService.setAppContext(stuff.getAppContext());
public void stop() throws OpenEJBException { final ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); try { // Setting context class loader for cleaning Thread.currentThread().setContextClassLoader(classLoader); // Fire shut down webBeansContext.getBeanManagerImpl().fireEvent(new BeforeShutdownImpl()); // Destroys context webBeansContext.getContextsService().destroy(null); // Free all plugin resources webBeansContext.getPluginLoader().shutDown(); // Clear extensions webBeansContext.getExtensionLoader().clear(); // Delete Resolutions Cache webBeansContext.getBeanManagerImpl().getInjectionResolver().clearCaches(); // Delete AnnotateTypeCache webBeansContext.getAnnotatedElementFactory().clear(); // Clear the resource injection service final CdiResourceInjectionService injectionServices = (CdiResourceInjectionService) webBeansContext.getService(ResourceInjectionService.class); injectionServices.clear(); // Clear singleton list WebBeansFinder.clearInstances(WebBeansUtil.getCurrentClassLoader()); } catch (final Exception e) { throw new OpenEJBException(e); } finally { Thread.currentThread().setContextClassLoader(oldCl); } }
injectionService.setAppContext(stuff.getAppContext(), stuff.getBeanContexts() != null ? stuff.getBeanContexts() : Collections.<BeanContext>emptyList());
services.put(ResourceInjectionService.class, new CdiResourceInjectionService()); services.put(ScannerService.class, new CdiScanner()); WebBeansContext webBeansContext = new WebBeansContext(services, properties);
@Override public void injectJavaEEResources(final Object managedBeanInstance) { if (managedBeanInstance == null) { return; } final Class<?> managedBeanInstanceClass = managedBeanInstance.getClass(); if (ejbPlugin.isSessionBean(managedBeanInstanceClass)) { // already done return; } final ObjectRecipe receipe = PassthroughFactory.recipe(managedBeanInstance); receipe.allow(Option.FIELD_INJECTION); receipe.allow(Option.PRIVATE_PROPERTIES); receipe.allow(Option.IGNORE_MISSING_PROPERTIES); receipe.allow(Option.NAMED_PARAMETERS); fillInjectionProperties(receipe, managedBeanInstance); receipe.create(); }
final Object value = lookup(beanContext, injection);
services.put(ResourceInjectionService.class, new CdiResourceInjectionService(webBeansContext));