Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.jboss.resteasy.cdi.injection.reverse;
  
  import static org.jboss.resteasy.cdi.injection.reverse.ReverseInjectionResource.NON_CONTEXTUAL;
  
  import java.util.HashMap;
  
 import  javax.enterprise.context.ApplicationScoped;
 

Author(s):
Ron Sigal
Version:
$Revision: 1.1 $ Copyright May 24, 2012
 
 @ApplicationScoped
 {
    private static HashMap<StringHashMap<String,Object>> store = new HashMap<StringHashMap<String,Object>>();
    private static int constructions;
    private static int destructions;
    
    @Inject int secret;
    
    static public int getConstructions()
    {
       return ;
    }
    
    static public int getDestructions()
    {
       return ;
    }
    
    public void postConstruct()
    {
       ++;
       .info(this + " secret: " + );
    }
    
    @PreDestroy
    public void preDestroy()
    {
       ++;
    }
    
    @Inject private Logger log;
    @Inject private BookResource resource;
    @Inject private BookReader reader;
    @Inject private BookWriter writer;
    
    @Override
    public void setUp(String key)
    {
       .info("entering StatefulApplicationScopedEJBwithJaxRsComponents.setUp()");
       HashMap<StringObjectsubstore = new HashMap<StringObject>();
       substore.put("secret".theSecret());
       substore.put(.);
       substore.put(.);
       .put(keysubstore);
    }
   
   
This is an SFSB. See discussion in EJBHolder.test(). If NON_CONTEXTUAL.equals(key), then this bean was obtained from JNDI, and it is not a CDI contextual object. It follows that it is not dependency scoped, which means it will not be recreated, with new injections, upon a second invocation. Otherwise, it will be recreated, and CDI will redo the injections.
 
    @Override
    public boolean test(String key)
    {
       .info("entering StatefulApplicationScopedEJBwithJaxRsComponents.test(" + key + ")");
       HashMap<StringObjectsubstore = .get(key);
       int savedSecret = Integer.class.cast(substore.get("secret"));
       .info("stored resource secret = resource secret: " + (savedSecret == .theSecret()));
       .info("stored reader = reader:                   " + (substore.get(.) == ));
       .info("stored writer = writer:                   " + (substore.get(.) == ));
 
       boolean result = true;
       result &=  == substore.get(.); // application scoped
       result &=  == substore.get(.); // application scoped
       if (.equals(key))
       {
          result &= .theSecret() == savedSecret;           // request scope not applicable
      }
      else
      {
         result &= .theSecret() != savedSecret;           // request scoped
      }
      return result;
   }
   
   public Class<?> theClass()
   {
   }
   
   public boolean theSame(EJBInterface ejb)
   {
      if (ejb == nullreturn false;
      Class<?> c = ejb.theClass();
      {
         .info(ejb + " not instanceof StatefulApplicationScopedEJBwithJaxRsComponents: " + c);
         return false;
      }
      .info(this. + " " + ejb.theSecret());
      return this. == ejb.theSecret();
   }
   
   public int theSecret()
   {
      return ;
   }
New to GrepCode? Check out our FAQ X