Package javax.enterprise.inject.spi

Examples of javax.enterprise.inject.spi.Bean


        }

        Method[] interceptedMethods = methods.toArray(new Method[methods.size()]);
        Method[] nonInterceptedMethods = null;

        Bean dummyBean = new DummyBean();

        Class<ExtendedSpecificClass> proxyClass = pf.createProxyClass(dummyBean, classLoader, ExtendedSpecificClass.class, interceptedMethods, nonInterceptedMethods);
        Assert.assertNotNull(proxyClass);

        ExtendedSpecificClass internalInstance = new ExtendedSpecificClass();
View Full Code Here


        Annotation[] qualifiers = new Annotation[injectionPoint.getQualifiers().size()];
        qualifiers = injectionPoint.getQualifiers().toArray(qualifiers);

        // OWB-890 some 3rd party InjectionPoints return null in getBean();
        Class<?> injectionPointClass = Object.class; // the fallback
        Bean injectionPointBean = injectionPoint.getBean();
        if (injectionPointBean != null)
        {
            injectionPointClass = injectionPointBean.getBeanClass();
        }
        if (injectionPointClass == null && type instanceof Class)
        {
            injectionPointClass = (Class) type;
        }
View Full Code Here

            } else {
                throw new RuntimeException("Multiple beans of class " + beanType + " found: " + beans + ".");
            }
        }

        Bean myBean = (Bean) beans.iterator().next();

        return manager.getReference(myBean, beanType, manager.createCreationalContext(myBean));
    }
View Full Code Here

    }

    public static <T> T getContextualReferenceByName(BeanManager beanManager, String beanName, Class<T> targetClass) {
        T result = null;
        // CodiUtils.getContextualReferenceByName() isn't working on WLS in some cases as WLS only stores the type of the actual class and not all superclasses
        Bean bean = beanManager.getBeans(beanName).iterator().next();
        CreationalContext ctx = beanManager.createCreationalContext(bean);
        Object o = beanManager.getReference(bean, Object.class, ctx);
        if (targetClass.isAssignableFrom(o.getClass())) {
            result = (T)o;
        }
View Full Code Here

            } catch (ClassNotFoundException e) {
                throw new OpenEJBRuntimeException(e);
            }

            // cdi can be off so init with null bean in this case
            final Bean bean;
            final BeanManager bm;
            if (wc == null) {
                bm = null;
                bean = null;
            } else {
                bm = wc.getBeanManagerImpl();
                final Set<Bean<?>> beans = bm.getBeans(clazz);
                bean = bm.resolve(beans);
            }

            // create the MBean instance with cdi if possible or manually otherwise
            final Object instance;
            final CreationalContext creationalContext;
            if (bean == null) {
                try {
                    instance = clazz.newInstance();
                } catch (InstantiationException e) {
                    logger.error("the mbean " + mbeanClass + " can't be registered because it can't be instantiated", e);
                    return;
                } catch (IllegalAccessException e) {
                    logger.error("the mbean " + mbeanClass + " can't be registered because it can't be accessed", e);
                    return;
                }
                creationalContext = null;
            } else {
                creationalContext = bm.createCreationalContext(bean);
                instance = bm.getReference(bean, clazz, creationalContext);
            }

            final MBeanServer server = LocalMBeanServer.get();
            try {
                final ObjectName leaf = new ObjectNameBuilder("openejb.user.mbeans")
                                            .set("application", id)
                                            .set("group", clazz.getPackage().getName())
                                            .set("name", clazz.getSimpleName())
                                            .build();

                server.registerMBean(new DynamicMBeanWrapper(wc, instance), leaf);
                appMbeans.put(mbeanClass, leaf.getCanonicalName());
                if (creationalContext != null && (bean.getScope() == null || Dependent.class.equals(bean.getScope()))) {
                    creationalContextForAppMbeans.put(leaf, creationalContext);
                }
                logger.info("Deployed MBean(" + leaf.getCanonicalName() + ")");
            } catch (Exception e) {
                logger.error("the mbean " + mbeanClass + " can't be registered", e);
View Full Code Here

  public static Object lookup(String name, BeanManager bm) {
    Iterator<Bean< ? >> iter = bm.getBeans(name).iterator();
    if (!iter.hasNext()) {
      throw new IllegalStateException("CDI BeanManager cannot find an instance of requested type '" + name + "'");
    }
    Bean bean = iter.next();
    CreationalContext ctx = bm.createCreationalContext(bean);
    // select one beantype randomly. A bean has a non-empty set of beantypes.
    Type type = (Type) bean.getTypes().iterator().next();
    return bm.getReference(bean, type, ctx);
  }
View Full Code Here

        BeanManager bm = getBeanManager();
        Set<Bean<?>> beans = getBeanManager().getBeans(PersonalDataBean.class);
        Assert.assertNotNull(beans);
        Assert.assertTrue(beans.size() == 1);
        Bean pdbBean = beans.iterator().next();
        CreationalContext<PersonalDataBean> pdbCreational = bm.createCreationalContext(pdbBean);
        Assert.assertNotNull(pdbCreational);

        // oki, now let's serializeBean the CreationalContext
        byte[] serial = serializeObject(pdbCreational);
View Full Code Here

                cs.startContext(RequestScoped.class, null);

                Set<Bean<?>> beans = bm.getBeans(LongInitApplicationBean.class);
                Assert.assertNotNull(beans);
                Assert.assertTrue(beans.size() == 1);
                Bean lrBean = beans.iterator().next();
                CreationalContext<LongInitApplicationBean> lrCreational = bm.createCreationalContext(lrBean);
                Assert.assertNotNull(lrCreational);

                longInitBean = (LongInitApplicationBean) bm.getReference(lrBean, LongInitApplicationBean.class, lrCreational);
                int i = longInitBean.getI();
View Full Code Here

        //Bootstrap WELD container
        StartMain startMain = new StartMain( new String[ 0 ] );
        beanManager = startMain.go().getBeanManager();

        //Instantiate Paths used in tests for Path conversion
        final Bean pathsBean = (Bean) beanManager.getBeans( Paths.class ).iterator().next();
        final CreationalContext cc = beanManager.createCreationalContext( pathsBean );
        paths = (Paths) beanManager.getReference( pathsBean,
                                                  Paths.class,
                                                  cc );
View Full Code Here

    }

    @Test
    public void testProjectServiceInstantiation() throws Exception {

        final Bean projectServiceBean = (Bean) beanManager.getBeans( ProjectService.class ).iterator().next();
        final CreationalContext cc = beanManager.createCreationalContext( projectServiceBean );
        final ProjectService projectService = (ProjectService) beanManager.getReference( projectServiceBean,
                                                                                         ProjectService.class,
                                                                                         cc );
        assertNotNull( projectService );
View Full Code Here

TOP

Related Classes of javax.enterprise.inject.spi.Bean

Copyright © 2018 www.massapicom. 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.