private static Interceptor<?> readInterceptor(String id, BeanManager beanManager) throws IOException { if (id.startsWith(SELF_KEY)) { Bean<?> bean = beanManager.getPassivationCapableBean(id.substring(SELF_KEY.length())); if (InjectionTargetBean.class.isInstance(bean)) { InjectionTarget<?> it = InjectionTargetBean.class.cast(bean).getInjectionTarget(); if (InjectionTargetImpl.class.isInstance(it)) { InterceptorResolutionService.BeanInterceptorInfo info = InjectionTargetImpl.class.cast(it) .getInterceptorInfo(); return info.getSelfInterceptorBean(); } else { throw new NotSerializableException("Can't find self interceptor"); } } else { throw new NotSerializableException("Can't find self interceptor"); } } return (Interceptor<?>) beanManager.getPassivationCapableBean(id); }
public Object inject(final Object o) throws OpenEJBException { try { final WebBeansContext webBeansContext = getWebBeansContext(); // Create bean instance final Context initialContext = (Context) new InitialContext().lookup("java:"); final Context unwrap = InjectionProcessor.unwrap(initialContext); final InjectionProcessor injectionProcessor = new InjectionProcessor(o, injections, unwrap); final Object beanInstance = injectionProcessor.createInstance(); if (webBeansContext != null) { final ConstructorInjectionBean<Object> beanDefinition = getConstructorInjectionBean(o.getClass(), webBeansContext); final CreationalContext<Object> creationalContext = webBeansContext.getBeanManagerImpl().createCreationalContext(beanDefinition); final InjectionTargetBean<Object> bean = InjectionTargetBean.class.cast(beanDefinition); bean.getInjectionTarget().inject(beanInstance, creationalContext); // if the bean is dependent simply cleanup the creational context once it is created final Class<? extends Annotation> scope = beanDefinition.getScope(); if (scope == null || Dependent.class.equals(scope)) { creatonalContexts.put(beanInstance, creationalContext); } } return beanInstance; } catch (final NamingException e) { throw new OpenEJBException(e); } }
@SuppressWarnings("unchecked") public <T> void inject(final T instance, CreationalContext<T> ctx) { final WebBeansContext webBeansContext = getWebBeansContext(); if (webBeansContext == null) { return; } InjectionTargetBean<T> beanDefinition = get(CdiEjbBean.class); if (beanDefinition == null) { beanDefinition = InjectionTargetBean.class.cast(createConstructorInjectionBean(webBeansContext)); } if (!(ctx instanceof CreationalContextImpl)) { ctx = webBeansContext.getCreationalContextFactory().wrappedCreationalContext(ctx, beanDefinition); } beanDefinition.getInjectionTarget().inject(instance, ctx); }
@SuppressWarnings("unchecked") public <T> void inject(final T instance, CreationalContext<T> ctx) { final WebBeansContext webBeansContext = getWebBeansContext(); if (webBeansContext == null) { return; } InjectionTargetBean<T> beanDefinition = get(CdiEjbBean.class); if (beanDefinition == null) { beanDefinition = InjectionTargetBean.class.cast(createConstructorInjectionBean(webBeansContext)); } if (!(ctx instanceof CreationalContextImpl)) { ctx = webBeansContext.getCreationalContextFactory().wrappedCreationalContext(ctx, beanDefinition); } beanDefinition.getInjectionTarget().inject(instance, ctx); }
public Object inject(final Object o) throws OpenEJBException { try { final WebBeansContext webBeansContext = getWebBeansContext(); // Create bean instance final Context initialContext = (Context) new InitialContext().lookup("java:"); final Context unwrap = InjectionProcessor.unwrap(initialContext); final InjectionProcessor injectionProcessor = new InjectionProcessor(o, injections, unwrap); final Object beanInstance = injectionProcessor.createInstance(); if (webBeansContext != null) { final ConstructorInjectionBean<Object> beanDefinition = getConstructorInjectionBean(o.getClass(), webBeansContext); final CreationalContext<Object> creationalContext = webBeansContext.getBeanManagerImpl().createCreationalContext(beanDefinition); final InjectionTargetBean<Object> bean = InjectionTargetBean.class.cast(beanDefinition); bean.getInjectionTarget().inject(beanInstance, creationalContext); if (shouldBeReleased(beanDefinition.getScope())) { creationalContexts.put(beanInstance, creationalContext); } } return beanInstance; } catch (final NamingException | OpenEJBException e) { throw new OpenEJBException(e); } }
public Object newInstance(final Class beanClass) throws OpenEJBException { final WebBeansContext webBeansContext = getWebBeansContext(); final ConstructorInjectionBean<Object> beanDefinition = getConstructorInjectionBean(beanClass, webBeansContext); final CreationalContext<Object> creationalContext; final Object o; if (webBeansContext == null) { creationalContext = null; try { o = beanClass.newInstance(); } catch (final InstantiationException e) { throw new OpenEJBException(e); } catch (final IllegalAccessException e) { throw new OpenEJBException(e); } } else { creationalContext = webBeansContext.getBeanManagerImpl().createCreationalContext(beanDefinition); o = beanDefinition.create(creationalContext); } // Create bean instance final Context unwrap = InjectionProcessor.unwrap(getInitialContext()); final InjectionProcessor injectionProcessor = new InjectionProcessor(o, injections, unwrap); final Object beanInstance = injectionProcessor.createInstance(); if (webBeansContext != null) { final InjectionTargetBean<Object> bean = InjectionTargetBean.class.cast(beanDefinition); bean.getInjectionTarget().inject(beanInstance, creationalContext); creatonalContexts.put(beanInstance, creationalContext); } return beanInstance; }
private void findContexts(final Class<?> clazz) { if (bean instanceof InjectionTargetBean<?>) { final InterceptorResolutionService.BeanInterceptorInfo info = InjectionTargetImpl.class.cast(InjectionTargetBean.class.cast(bean).getInjectionTarget()).getInterceptorInfo(); for (final Interceptor<?> interceptor : info.getCdiInterceptors()) { if (interceptor == null || interceptor.getBeanClass() == null) { continue; } Contexts.findContextFields(interceptor.getBeanClass(), contextTypes); } for (final Interceptor<?> interceptor : info.getEjbInterceptors()) { if (interceptor == null || interceptor.getBeanClass() == null) { continue; } Contexts.findContextFields(interceptor.getBeanClass(), contextTypes); } for (final Decorator<?> decorator : info.getDecorators()) { if (decorator == null || decorator.getBeanClass() == null) { continue; } Contexts.findContextFields(decorator.getBeanClass(), contextTypes); } } Contexts.findContextFields(clazz, contextTypes); // for the class itself }
bean.getInjectionTarget().inject(beanInstance, creationalContext); if (shouldBeReleased(bean.getScope())) { creationalContexts.put(beanInstance, creationalContext);