Search in sources :

Example 1 with BeanIdentifierIndex

use of org.jboss.weld.serialization.BeanIdentifierIndex in project core by weld.

the class BeanIdentifierIndexTest method testGetIndex.

@Test
public void testGetIndex() {
    BeanIdentifierIndex index = new BeanIdentifierIndex();
    index.build(Collections.<Bean<?>>emptySet());
    try {
        index.getIndex(null);
    } catch (IllegalArgumentException e) {
    // Expected
    }
    assertNull(index.getIndex(new StringBeanIdentifier("foo")));
}
Also used : StringBeanIdentifier(org.jboss.weld.bean.StringBeanIdentifier) BeanIdentifierIndex(org.jboss.weld.serialization.BeanIdentifierIndex) Test(org.junit.Test)

Example 2 with BeanIdentifierIndex

use of org.jboss.weld.serialization.BeanIdentifierIndex in project core by weld.

the class BeanIdentifierIndexTest method testGetDebugInfo.

@Test
public void testGetDebugInfo() {
    BeanIdentifierIndex index = new BeanIdentifierIndex();
    Set<Bean<?>> beans = new HashSet<Bean<?>>();
    for (int i = 0; i < 3; i++) {
        beans.add(DummyBean.of(i + ".foo"));
    }
    index.build(beans);
    assertEquals("BeanIdentifierIndex [hash=-1733773048, indexed=3] \n     0: 0.foo\n     1: 1.foo\n     2: 2.foo\n", index.getDebugInfo());
}
Also used : InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) BeanIdentifierIndex(org.jboss.weld.serialization.BeanIdentifierIndex) CommonBean(org.jboss.weld.bean.CommonBean) Bean(javax.enterprise.inject.spi.Bean) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with BeanIdentifierIndex

use of org.jboss.weld.serialization.BeanIdentifierIndex in project core by weld.

the class WeldStartup method createContexts.

protected Collection<ContextHolder<? extends Context>> createContexts(ServiceRegistry services) {
    List<ContextHolder<? extends Context>> contexts = new ArrayList<ContextHolder<? extends Context>>();
    BeanIdentifierIndex beanIdentifierIndex = services.get(BeanIdentifierIndex.class);
    /*
        * Register a full set of bound and unbound contexts. Although we may not use all of
        * these (e.g. if we are running in a servlet environment) they may be
        * useful for an application.
        */
    Set<Annotation> boundQualifires = ImmutableSet.<Annotation>builder().addAll(Bindings.DEFAULT_QUALIFIERS).add(BoundLiteral.INSTANCE).build();
    Set<Annotation> unboundQualifiers = ImmutableSet.<Annotation>builder().addAll(Bindings.DEFAULT_QUALIFIERS).add(UnboundLiteral.INSTANCE).build();
    contexts.add(new ContextHolder<ApplicationContext>(new ApplicationContextImpl(contextId), ApplicationContext.class, unboundQualifiers));
    contexts.add(new ContextHolder<SingletonContext>(new SingletonContextImpl(contextId), SingletonContext.class, unboundQualifiers));
    contexts.add(new ContextHolder<BoundSessionContext>(new BoundSessionContextImpl(contextId, beanIdentifierIndex), BoundSessionContext.class, boundQualifires));
    contexts.add(new ContextHolder<BoundConversationContext>(new BoundConversationContextImpl(contextId, services), BoundConversationContext.class, boundQualifires));
    contexts.add(new ContextHolder<BoundRequestContext>(new BoundRequestContextImpl(contextId), BoundRequestContext.class, boundQualifires));
    contexts.add(new ContextHolder<RequestContext>(new RequestContextImpl(contextId), RequestContext.class, unboundQualifiers));
    contexts.add(new ContextHolder<DependentContext>(new DependentContextImpl(services.get(ContextualStore.class)), DependentContext.class, unboundQualifiers));
    services.get(WeldModules.class).postContextRegistration(contextId, services, contexts);
    /*
        * Register the contexts with the bean manager and add the beans to the
        * deployment manager so that they are easily accessible (contexts are app
        * scoped)
        */
    for (ContextHolder<? extends Context> context : contexts) {
        deploymentManager.addContext(context.getContext());
        deploymentManager.addBean(ContextBean.of(context, deploymentManager));
    }
    return contexts;
}
Also used : ArrayList(java.util.ArrayList) BoundRequestContextImpl(org.jboss.weld.contexts.bound.BoundRequestContextImpl) RequestContextImpl(org.jboss.weld.contexts.unbound.RequestContextImpl) BoundConversationContext(org.jboss.weld.context.bound.BoundConversationContext) BeanIdentifierIndex(org.jboss.weld.serialization.BeanIdentifierIndex) BoundRequestContextImpl(org.jboss.weld.contexts.bound.BoundRequestContextImpl) BoundRequestContext(org.jboss.weld.context.bound.BoundRequestContext) ApplicationContext(org.jboss.weld.context.ApplicationContext) SingletonContext(org.jboss.weld.context.SingletonContext) BoundRequestContext(org.jboss.weld.context.bound.BoundRequestContext) RequestContext(org.jboss.weld.context.RequestContext) DependentContext(org.jboss.weld.context.DependentContext) DependentContext(org.jboss.weld.context.DependentContext) BoundRequestContext(org.jboss.weld.context.bound.BoundRequestContext) SingletonContext(org.jboss.weld.context.SingletonContext) ApplicationContext(org.jboss.weld.context.ApplicationContext) Context(javax.enterprise.context.spi.Context) BoundSessionContext(org.jboss.weld.context.bound.BoundSessionContext) BoundConversationContext(org.jboss.weld.context.bound.BoundConversationContext) RequestContext(org.jboss.weld.context.RequestContext) SingletonContextImpl(org.jboss.weld.contexts.unbound.SingletonContextImpl) BoundSessionContext(org.jboss.weld.context.bound.BoundSessionContext) WeldModules(org.jboss.weld.module.WeldModules) Annotation(java.lang.annotation.Annotation) DependentContextImpl(org.jboss.weld.contexts.unbound.DependentContextImpl) ContextualStore(org.jboss.weld.serialization.spi.ContextualStore) ApplicationContextImpl(org.jboss.weld.contexts.unbound.ApplicationContextImpl) BoundSessionContextImpl(org.jboss.weld.contexts.bound.BoundSessionContextImpl) BoundConversationContextImpl(org.jboss.weld.contexts.bound.BoundConversationContextImpl)

Example 4 with BeanIdentifierIndex

use of org.jboss.weld.serialization.BeanIdentifierIndex in project core by weld.

the class WeldWebModule method postContextRegistration.

@Override
public void postContextRegistration(PostContextRegistrationContext ctx) {
    final BeanIdentifierIndex index = ctx.getServices().get(BeanIdentifierIndex.class);
    final String contextId = ctx.getContextId();
    if (Reflections.isClassLoadable(ServletApiAbstraction.SERVLET_CONTEXT_CLASS_NAME, WeldClassLoaderResourceLoader.INSTANCE)) {
        // Register the Http contexts if not in
        Set<Annotation> httpQualifiers = ImmutableSet.<Annotation>builder().addAll(Bindings.DEFAULT_QUALIFIERS).add(HttpLiteral.INSTANCE).build();
        ctx.addContext(new ContextHolder<HttpSessionContext>(new HttpSessionContextImpl(contextId, index), HttpSessionContext.class, httpQualifiers));
        ctx.addContext(new ContextHolder<HttpSessionDestructionContext>(new HttpSessionDestructionContext(contextId, index), HttpSessionDestructionContext.class, httpQualifiers));
        ctx.addContext(new ContextHolder<HttpConversationContext>(new LazyHttpConversationContextImpl(contextId, ctx.getServices()), HttpConversationContext.class, httpQualifiers));
        ctx.addContext(new ContextHolder<HttpRequestContext>(new HttpRequestContextImpl(contextId), HttpRequestContext.class, httpQualifiers));
    }
}
Also used : HttpSessionDestructionContext(org.jboss.weld.module.web.context.http.HttpSessionDestructionContext) LazyHttpConversationContextImpl(org.jboss.weld.module.web.context.http.LazyHttpConversationContextImpl) Annotation(java.lang.annotation.Annotation) BeanIdentifierIndex(org.jboss.weld.serialization.BeanIdentifierIndex) HttpSessionContextImpl(org.jboss.weld.module.web.context.http.HttpSessionContextImpl) HttpSessionContext(org.jboss.weld.context.http.HttpSessionContext) HttpRequestContext(org.jboss.weld.context.http.HttpRequestContext) HttpRequestContextImpl(org.jboss.weld.module.web.context.http.HttpRequestContextImpl) HttpConversationContext(org.jboss.weld.context.http.HttpConversationContext)

Example 5 with BeanIdentifierIndex

use of org.jboss.weld.serialization.BeanIdentifierIndex in project core by weld.

the class BeanIdentifierIndexTest method testIndex.

@Test
public void testIndex() {
    BeanIdentifierIndex index = beanManager.getServices().get(BeanIdentifierIndex.class);
    // Index is enabled by default
    assertTrue(index.isBuilt());
    assertFalse(index.isEmpty());
    ManagedBean<?> indexedBean = (ManagedBean<?>) beanManager.resolve(beanManager.getBeans(Indexed.class));
    assertNotNull(index.getIndex(indexedBean.getIdentifier()));
    HttpSessionBean httpSessionBean = (HttpSessionBean) beanManager.resolve(beanManager.getBeans(HttpSession.class));
    // Built-in beans are not included
    assertNull(index.getIndex(httpSessionBean.getIdentifier()));
}
Also used : HttpSessionBean(org.jboss.weld.module.web.HttpSessionBean) ManagedBean(org.jboss.weld.bean.ManagedBean) BeanIdentifierIndex(org.jboss.weld.serialization.BeanIdentifierIndex) SerializationTest(org.jboss.weld.tests.serialization.noncontextual.SerializationTest) Test(org.junit.Test)

Aggregations

BeanIdentifierIndex (org.jboss.weld.serialization.BeanIdentifierIndex)11 Test (org.junit.Test)6 Annotation (java.lang.annotation.Annotation)2 HashSet (java.util.HashSet)2 Bean (javax.enterprise.inject.spi.Bean)2 CommonBean (org.jboss.weld.bean.CommonBean)2 WeldConfiguration (org.jboss.weld.config.WeldConfiguration)2 GlobalObserverNotifierService (org.jboss.weld.event.GlobalObserverNotifierService)2 ResourceInjectionFactory (org.jboss.weld.injection.ResourceInjectionFactory)2 MetaAnnotationStore (org.jboss.weld.metadata.cache.MetaAnnotationStore)2 WeldModules (org.jboss.weld.module.WeldModules)2 ClassTransformer (org.jboss.weld.resources.ClassTransformer)2 ContextualStoreImpl (org.jboss.weld.serialization.ContextualStoreImpl)2 ArrayList (java.util.ArrayList)1 Context (javax.enterprise.context.spi.Context)1 InjectionPoint (javax.enterprise.inject.spi.InjectionPoint)1 SlimAnnotatedTypeStoreImpl (org.jboss.weld.annotated.slim.SlimAnnotatedTypeStoreImpl)1 DecoratorImpl (org.jboss.weld.bean.DecoratorImpl)1 InterceptorImpl (org.jboss.weld.bean.InterceptorImpl)1 ManagedBean (org.jboss.weld.bean.ManagedBean)1