Java Code Examples for javax.enterprise.context.ApplicationScoped

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project camelpe, under directory /impl/src/main/java/net/camelpe/extension/.

Source file: CdiCamelContext.java

  20 
vote

static Bean<CdiCamelContext> cdiBean(final BeanManager beanManager){
  final AnnotatedType<CdiCamelContext> annotatedType=beanManager.createAnnotatedType(CdiCamelContext.class);
  final InjectionTarget<CdiCamelContext> injectionTarget=beanManager.createInjectionTarget(annotatedType);
  return new BeanBuilder<CdiCamelContext>(beanManager).name("cdiCamelContext").readFromType(annotatedType).scope(ApplicationScoped.class).addQualifiers(DefaultLiteral.INSTANCE,AnyLiteral.INSTANCE).addTypes(CdiCamelContext.class,CamelContext.class,Object.class).alternative(false).nullable(false).injectionPoints(injectionTarget.getInjectionPoints()).beanLifecycle(new ContextualLifecycle<CdiCamelContext>(){
    @Override public void destroy(    final Bean<CdiCamelContext> bean,    final CdiCamelContext instance,    final CreationalContext<CdiCamelContext> creationalContext){
      try {
        injectionTarget.preDestroy(instance);
        instance.stop();
        injectionTarget.dispose(instance);
        creationalContext.release();
      }
 catch (      final Exception e) {
        throw new ContextException("Failed to destroy CamelContext [" + instance + "]: "+ e.getMessage(),e);
      }
    }
    @Override public CdiCamelContext create(    final Bean<CdiCamelContext> bean,    final CreationalContext<CdiCamelContext> creationalContext){
      final CdiCamelContext instance=injectionTarget.produce(creationalContext);
      injectionTarget.inject(instance,creationalContext);
      injectionTarget.postConstruct(instance);
      return instance;
    }
  }
).create();
}
 

Example 2

From project capedwarf-green, under directory /server-api/src/main/java/org/jboss/capedwarf/server/api/persistence/.

Source file: EMF.java

  19 
vote

@Produces @ApplicationScoped public EntityManagerFactory produceFactory(EMFInfo info){
  produceEvent.select(new BeforeImpl()).fire(new EMFNotification(null));
  EntityManagerFactory entityManagerFactory=getFactory(info);
  produceEvent.select(new AfterImpl()).fire(new EMFNotification(entityManagerFactory));
  return entityManagerFactory;
}
 

Example 3

From project capedwarf-green, under directory /server-gae/src/main/java/org/jboss/capedwarf/server/gae/validation/.

Source file: CdiValidationFactoryProvider.java

  19 
vote

@Produces @ApplicationScoped public ValidatorFactory createFactory(){
  SimpleValidatorFactory factory=new SimpleValidatorFactory();
  factory.put(BlobSize.class,BlobSizeValidator.class);
  factory.put(JpaEmail.class,JpaEmailValidator.class);
  return factory;
}
 

Example 4

From project framework, under directory /impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/context/.

Source file: ContextsTest.java

  19 
vote

@Test public void testClear(){
  List<ThreadLocalContext> list=new ArrayList<ThreadLocalContext>();
  list.add(new ThreadLocalContext(SessionScoped.class));
  list.add(new ThreadLocalContext(SessionScoped.class));
  list.add(new ThreadLocalContext(ApplicationScoped.class));
  for (  ThreadLocalContext context : list) {
    Contexts.add(context,event);
  }
  Contexts.clear();
  assertEquals(0,Contexts.getActiveContexts().size());
  assertEquals(0,Contexts.getInactiveContexts().size());
  for (  ThreadLocalContext context : list) {
    assertFalse(context.isActive());
  }
}
 

Example 5

From project incubator-deltaspike, under directory /deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/.

Source file: OpenWebBeansContextControl.java

  19 
vote

@Override public void startContext(Class<? extends Annotation> scopeClass){
  if (scopeClass.isAssignableFrom(ApplicationScoped.class)) {
    startApplicationScope();
  }
 else   if (scopeClass.isAssignableFrom(SessionScoped.class)) {
    startSessionScope();
  }
 else   if (scopeClass.isAssignableFrom(RequestScoped.class)) {
    startRequestScope();
  }
 else   if (scopeClass.isAssignableFrom(ConversationScoped.class)) {
    startConversationScope();
  }
}
 

Example 6

From project incubator-deltaspike, under directory /deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/.

Source file: OpenWebBeansContextControl.java

  19 
vote

public void stopContext(Class<? extends Annotation> scopeClass){
  if (scopeClass.isAssignableFrom(ApplicationScoped.class)) {
    stopApplicationScope();
  }
 else   if (scopeClass.isAssignableFrom(SessionScoped.class)) {
    stopSessionScope();
  }
 else   if (scopeClass.isAssignableFrom(RequestScoped.class)) {
    stopRequestScope();
  }
 else   if (scopeClass.isAssignableFrom(ConversationScoped.class)) {
    stopConversationScope();
  }
}
 

Example 7

From project incubator-deltaspike, under directory /deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/.

Source file: OpenWebBeansContextControl.java

  19 
vote

private void startApplicationScope(){
  ContextsService contextsService=getContextsService();
  Object mockServletContext=null;
  if (isServletApiAvailable()) {
    mockServletContext=OwbHelper.getMockServletContext();
  }
  contextsService.startContext(ApplicationScoped.class,mockServletContext);
}
 

Example 8

From project jms, under directory /api/src/main/java/org/jboss/seam/jms/inject/.

Source file: JmsConnectionFactoryProducer.java

  19 
vote

@Produces @ApplicationScoped @JmsDefault("connectionFactory") public ConnectionFactory produceConnectionFactory(){
  try {
    return (ConnectionFactory)context.lookup(connectionFactoryJNDILocation);
  }
 catch (  NamingException e) {
    logger.info("Unable to look up " + connectionFactoryJNDILocation + " in JNDI",e);
    return null;
  }
}
 

Example 9

From project jms, under directory /api/src/main/java/org/jboss/seam/jms/inject/.

Source file: JmsConnectionProducer.java

  19 
vote

@Produces @ApplicationScoped public Connection getConnection(@JmsDefault("connectionFactory") ConnectionFactory connectionFactory) throws Exception {
  logger.debug("Creating a new connection.");
  Connection conn=connectionFactory.createConnection();
  conn.start();
  return conn;
}
 

Example 10

From project openknowledge-cdi-extensions, under directory /openknowledge-cdi-job/src/main/java/de/openknowledge/cdi/job/.

Source file: CdiSchedulerFactory.java

  19 
vote

@Produces @ApplicationScoped public Scheduler createScheduler(){
  try {
    Scheduler scheduler=super.getScheduler();
    scheduler.start();
    LOG.debug("Providing scheduler " + scheduler);
    return scheduler;
  }
 catch (  SchedulerException e) {
    throw new IllegalArgumentException(e);
  }
}
 

Example 11

From project openwebbeans, under directory /webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/interceptor/.

Source file: OpenWebBeansEjbInterceptor.java

  19 
vote

/** 
 * Deacitvate context.
 * @param destroy if destroy context
 * @param scopeType scope type
 */
private void deActivateContexts(boolean destroy,Class<? extends Annotation> scopeType){
  ContextFactory contextFactory=webBeansContext.getContextFactory();
  if (scopeType == ApplicationScoped.class) {
    if (destroy) {
      contextFactory.destroyApplicationContext(null);
    }
 else {
      contextFactory.deActivateContext(ApplicationScoped.class);
    }
  }
 else {
    if (destroy) {
      contextFactory.destroyRequestContext(null);
    }
 else {
      contextFactory.deActivateContext(RequestScoped.class);
    }
  }
}
 

Example 12

From project openwebbeans, under directory /webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/.

Source file: EjbValidator.java

  19 
vote

/** 
 * Validates session bean's scope.
 * @param ejbBean ejb bean
 */
public static void validateEjbScopeType(BaseEjbBean<?> ejbBean){
  Asserts.assertNotNull(ejbBean,"Session Bean can not be null");
  if (ejbBean.getScope() == null) {
    throw new NullPointerException("Session Bean scope can not be null");
  }
  if (ejbBean.getEjbType() == null) {
    throw new NullPointerException("Session Bean type can not be null. It must be one of @Stateless, @Stateful, @Singleton");
  }
  if (ejbBean.getEjbType().equals(SessionBeanType.STATELESS)) {
    if (!ejbBean.getScope().equals(Dependent.class)) {
      throw new WebBeansConfigurationException("Stateless Session Bean class : " + ejbBean.getReturnType() + " "+ "can not define scope other than @Dependent");
    }
  }
 else   if (ejbBean.getEjbType().equals(SessionBeanType.SINGLETON)) {
    if (!ejbBean.getScope().equals(Dependent.class) && !ejbBean.getScope().equals(ApplicationScoped.class)) {
      throw new WebBeansConfigurationException("Singleton Session Bean class : " + ejbBean.getReturnType() + " "+ "can not define scope other than @Dependent or @ApplicationScoped");
    }
  }
}
 

Example 13

From project openwebbeans, under directory /webbeans-impl/src/main/java/org/apache/webbeans/context/.

Source file: ContextFactory.java

  19 
vote

public void initApplicationContext(Object parameter){
  try {
    ContextsService contextService=getContextsService();
    contextService.startContext(ApplicationScoped.class,parameter);
  }
 catch (  Exception e) {
    logger.log(Level.SEVERE,e.getMessage(),e);
  }
}
 

Example 14

From project solder, under directory /impl/src/test/java/org/jboss/solder/test/reflection/annotated/.

Source file: AnnotatedTypeBuilderTest.java

  19 
vote

/** 
 * @see <a href="https://issues.jboss.org/browse/SOLDER-103">SOLDER-103</a>
 */
@Test public void testTypeLevelAnnotationRedefinition(){
  AnnotatedTypeBuilder<Cat> builder=new AnnotatedTypeBuilder<Cat>();
  builder.readFromType(Cat.class);
  builder.redefine(Named.class,new NamedAnnotationRedefiner());
  AnnotatedType<Cat> cat=builder.create();
  assertEquals(3,cat.getAnnotations().size());
  assertTrue(cat.isAnnotationPresent(Named.class));
  assertTrue(cat.isAnnotationPresent(Alternative.class));
  assertTrue(cat.isAnnotationPresent(ApplicationScoped.class));
  assertEquals("tomcat",cat.getAnnotation(Named.class).value());
}