@Override
 public void addContext(Context context) {
   checkWithinObserverNotification();
   Preconditions.checkArgumentNotNull(context, "context");
   Class<? extends Annotation> scope = context.getScope();
   if (scope == null) {
     throw ContextLogger.LOG.contextHasNullScope(context);
   }
   if (!getBeanManager().isScope(scope)) {
     MetadataLogger.LOG.contextGetScopeIsNotAScope(scope, context);
   }
   if (scope == ApplicationScoped.class || scope == Dependent.class) {
     throw ContextLogger.LOG.cannotRegisterContext(scope, context);
   }
   getBeanManager().addContext(context);
   BootstrapLogger.LOG.addContext(getReceiver(), context);
 }
Exemplo n.º 2
0
 public boolean associate(HttpServletRequest request) {
   // At this point the bean store should never be set - see also
   // HttpContextLifecycle#nestedInvocationGuard
   BoundBeanStore beanStore = getBeanStore();
   if (beanStore != null) {
     ContextLogger.LOG.beanStoreLeakDuringAssociation(this.getClass().getName(), request);
     if (ContextLogger.LOG.isDebugEnabled()) {
       ContextLogger.LOG.beanStoreLeakAffectedBeanIdentifiers(
           this.getClass().getName(), Iterables.toMultiRowString(beanStore));
     }
   }
   // We always associate a new bean store to avoid possible leaks (security threats)
   beanStore = new RequestBeanStore(request, namingScheme);
   setBeanStore(beanStore);
   beanStore.attach();
   return true;
 }