Package javax.enterprise.inject.spi

Examples of javax.enterprise.inject.spi.BeanManager.createCreationalContext()


                requestContext.deactivate();
                requestContext.dissociate(requestContexts.get());

                final Bean<BoundConversationContext> conversationContextBean = (Bean<BoundConversationContext>) manager
                        .resolve(manager.getBeans(BoundConversationContext.class, BoundLiteral.INSTANCE));
                ctx = manager.createCreationalContext(conversationContextBean);
                final BoundConversationContext conversationContext = (BoundConversationContext) manager.getReference(
                        conversationContextBean, BoundConversationContext.class, ctx);
                conversationContext.deactivate();
                conversationContext.dissociate(boundRequests.get());
            }
View Full Code Here


    }

    public <T> T injectFields(T instance)
    {
        BeanManager beanManager = getBeanManager();
        CreationalContext creationalContext = beanManager.createCreationalContext(null);

        AnnotatedType annotatedType = beanManager.createAnnotatedType(instance.getClass());
        InjectionTarget injectionTarget = beanManager.createInjectionTarget(annotatedType);
        injectionTarget.inject(instance, creationalContext);
        return instance;
View Full Code Here

     */
    public <TYPE> TYPE lookup(Class<TYPE> clazz) throws BeanLocationException {
        BeanManager beanManager = jndiLookup("java:comp/BeanManager", BeanManager.class);

        Bean<TYPE> handlerBean = (Bean<TYPE>) beanManager.getBeans(clazz).iterator().next();
        CreationalContext<TYPE> ctx = beanManager.createCreationalContext(handlerBean);
        return (TYPE) beanManager.getReference(handlerBean, clazz, ctx);

    }

    /**
 
View Full Code Here

        Set<Bean<?>> beans  = bm.getBeans(name);
        if (beans.isEmpty()) throw new IllegalArgumentException("Bean not found by name: " + name);

        // Get the first bean found for the given name
        Bean bean = beans.iterator().next();
        CreationalContext ctx = bm.createCreationalContext(bean);
        Object o = bm.getReference(bean, bean.getBeanClass(), ctx);
        return o;
    }

    public static <T> T getBeanByType(Class<T> type) {
View Full Code Here

        if (beans.isEmpty()) throw new IllegalArgumentException("Bean not found by type: " + type.getName());

        // Get the bean that matches exactly the given class.
        for (Bean<?> bean : beans) {
            if (bean.getBeanClass().equals(type)) {
                CreationalContext ctx = bm.createCreationalContext(bean);
                Object o = bm.getReference(bean, bean.getBeanClass(), ctx);
                return type.cast(o);
            }
        }
        // Get the first bean found that implements the given type.
View Full Code Here

                return type.cast(o);
            }
        }
        // Get the first bean found that implements the given type.
        Bean bean = beans.iterator().next();
        CreationalContext ctx = bm.createCreationalContext(bean);
        Object o = bm.getReference(bean, bean.getBeanClass(), ctx);
        return type.cast(o);
    }

    public static Object getBeanByType(String type) {
View Full Code Here

            Set<Bean<?>> beans = manager.getBeans(clazz);

            for (Bean<?> bean : beans) {

                CreationalContext<?> cc = manager.createCreationalContext(bean);

                Object reference = manager.getReference(bean, clazz, cc);
                result.add((T) reference);

            }
View Full Code Here

  public ErraiService locateService() {
    BeanManager beanManager = Util.lookupBeanManager();

    Set<Bean<?>> beans = beanManager.getBeans(ErraiService.class);
    Bean<?> bean = beanManager.resolve(beans);
    CreationalContext<?> context = beanManager.createCreationalContext(bean);

    return (ErraiService) beanManager.getReference(bean, ErraiService.class, context);

  }
}
View Full Code Here

    }

    public static Object getBeanByName(String name) {
        BeanManager bm = getBeanManager();
        Bean bean = bm.getBeans(name).iterator().next();
        CreationalContext ctx = bm.createCreationalContext(bean);
        Object o = bm.getReference(bean, bean.getBeanClass(), ctx);
        return o;
    }

    public static Object getBeanByType(Class type) {
View Full Code Here

    }

    public static Object getBeanByType(Class type) {
        BeanManager bm = getBeanManager();
        Bean bean = bm.getBeans(type).iterator().next();
        CreationalContext ctx = bm.createCreationalContext(bean);
        Object o = bm.getReference(bean, bean.getBeanClass(), ctx);
        return o;
    }   
}
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.