Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2008, Red Hat, Inc., and individual contributors
   * by the @authors tag. See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
  * http://www.apache.org/licenses/LICENSE-2.0
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.jboss.weld.bootstrap.events;
 
 import static org.jboss.weld.util.Observers.validateObserverMethod;
 import static org.jboss.weld.util.reflection.Reflections.cast;
 
 import java.util.List;
 import java.util.Set;
 
 
 
 
     private static final String TYPE_ARGUMENT_NAME = "type";
 
     public static void fire(BeanManagerImpl beanManagerDeployment deploymentBeanDeploymentArchiveMapping bdaMappingCollection<ContextHolder<? extends Context>> contexts) {
         final AfterBeanDiscoveryImpl event = new AfterBeanDiscoveryImpl(beanManagerdeploymentbdaMappingcontexts);
         event.fire();
         event.finish();
     }
 
     private AfterBeanDiscoveryImpl(BeanManagerImpl beanManagerDeployment deploymentBeanDeploymentArchiveMapping bdaMappingCollection<ContextHolder<? extends Context>> contexts) {
         super(beanManagerAfterBeanDiscovery.classbdaMappingdeploymentcontexts);
         this. = beanManager.getServices().get(SlimAnnotatedTypeStore.class);
         this. = beanManager.getServices().get(ContainerLifecycleEvents.class);
     }
 
     private final List<Bean<?>> additionalBeans = new LinkedList<Bean<?>>();
     private final List<ObserverMethod<?>> additionalObservers = new LinkedList<ObserverMethod<?>>();
 
     @Override
     public void addBean(Bean<?> bean) {
         Preconditions.checkArgumentNotNull(bean"bean");
         ExternalBeanAttributesFactory.validateBeanAttributes(beangetBeanManager());
         validateBean(bean);
         .add(bean);
     }
 
     protected <T> void processBean(Bean<T> bean) {
         BeanManagerImpl beanManager = getOrCreateBeanDeployment(bean.getBeanClass()).getBeanManager();
         if (bean instanceof Interceptor<?>) {
             beanManager.addInterceptor((Interceptor<?>) bean);
         } else if (bean instanceof Decorator<?>) {
             beanManager.addDecorator(CustomDecoratorWrapper.of((Decorator<?>) beanbeanManager));
         } else {
             beanManager.addBean(bean);
         }
         .fireProcessBean(beanManagerbean);
     }
 
     private void validateBean(Bean<?> bean) {
         if (bean.getBeanClass() == null) {
             throw ..beanMethodReturnsNull("getBeanClass"bean);
        }
        if (bean.getInjectionPoints() == null) {
            throw ..beanMethodReturnsNull("getInjectionPoints"bean);
        }
        if (bean instanceof PassivationCapable) {
            PassivationCapable passivationCapable = (PassivationCapablebean;
            if (passivationCapable.getId() == null) {
                throw ..passivationCapableBeanHasNullId(bean);
            }
        }
        if (bean instanceof Interceptor<?>) {
            validateInterceptor((Interceptor<?>) bean);
        } else if (bean instanceof Decorator<?>) {
            validateDecorator((Decorator<?>) bean);
        }
    }
    private void validateInterceptor(Interceptor<?> interceptor) {
        Set<Annotationbindings = interceptor.getInterceptorBindings();
        if (bindings == null) {
            throw ..nullInterceptorBindings(interceptor);
        }
        for (Annotation annotation : bindings) {
            if (!getBeanManager().isInterceptorBinding(annotation.annotationType())) {
                throw ..notAnInterceptorBinding(annotationinterceptor);
            }
        }
    }
    private void validateDecorator(Decorator<?> decorator) {
        Set<Annotationqualifiers = decorator.getDelegateQualifiers();
        if (decorator.getDelegateType() == null) {
            throw ..decoratorMethodReturnsNull("getDelegateType"decorator);
        }
        Bindings.validateQualifiers(qualifiersgetBeanManager(), decorator"Decorator.getDelegateQualifiers");
        if (decorator.getDecoratedTypes() == null) {
            throw ..decoratorMethodReturnsNull("getDecoratedTypes"decorator);
        }
    }
    @Override
    public void addContext(Context context) {
        Preconditions.checkArgumentNotNull(context"context");
        Class<? extends Annotationscope = context.getScope();
        if (scope == null) {
            throw ..contextHasNullScope(context);
        }
        if (!getBeanManager().isScope(scope)) {
            ..contextGetScopeIsNotAScope(scopecontext);
        }
        if (scope == ApplicationScoped.class || scope == Dependent.class) {
            throw ..cannotRegisterContext(scopecontext);
        }
        getBeanManager().addContext(context);
    }
    @Override
    public void addObserverMethod(ObserverMethod<?> observerMethod) {
        Preconditions.checkArgumentNotNull(observerMethod"observerMethod");
        validateObserverMethod(observerMethodgetBeanManager());
        .add(observerMethod);
    }
    @Override
    public <T> AnnotatedType<T> getAnnotatedType(Class<T> typeString id) {
        Preconditions.checkArgumentNotNull(type);
        return .get(typeid);
    }
    @Override
    public <T> Iterable<AnnotatedType<T>> getAnnotatedTypes(Class<T> type) {
        Preconditions.checkArgumentNotNull(type);
        return cast(.get(type));
    }

    
Bean and observer registration is delayed until after all javax.enterprise.inject.spi.AfterBeanDiscovery observers are notified.
    private void finish() {
        try {
            for (Bean<?> bean : ) {
                processBean(bean);
            }
            for (ObserverMethod<?> observer : ) {
                BeanManagerImpl manager = getOrCreateBeanDeployment(observer.getBeanClass()).getBeanManager();
                if (Observers.isObserverMethodEnabled(observermanager)) {
                    ProcessObserverMethodImpl.fire(managerobserver);
                    manager.addObserver(observer);
                }
            }
        } catch (Exception e) {
            throw new DefinitionException(e);
        }
    }
New to GrepCode? Check out our FAQ X