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;
 
 import static org.jboss.weld.util.cache.LoadingCacheUtils.getCacheValue;
 
 import java.util.List;
 import java.util.Set;
 
 
 

Author(s):
Pete Muir
Jozef Hartinger
alesj
Marko Luksa
 
 
     private final ResourceLoader resourceLoader;
     private final SlimAnnotatedTypeStore annotatedTypeStore;
     private final AnnotationApiAbstraction annotationApi;
     private final ClassFileServices classFileServices;
 
     public BeanDeployer(BeanManagerImpl managerEjbDescriptors ejbDescriptorsServiceRegistry services) {
         this(managerejbDescriptorsservices, BeanDeployerEnvironmentFactory.newEnvironment(ejbDescriptorsmanager));
     }
 
     public BeanDeployer(BeanManagerImpl managerEjbDescriptors ejbDescriptorsServiceRegistry servicesBeanDeployerEnvironment environment) {
         super(managerservicesenvironment);
         this. = manager.getServices().get(ResourceLoader.class);
         this. = manager.getServices().get(SlimAnnotatedTypeStore.class);
         this. = manager.getServices().get(GlobalEnablementBuilder.class);
         this. = manager.getServices().get(AnnotationApiAbstraction.class);
         this. = manager.getServices().get(ClassFileServices.class);
     }

    
Loads a given class, creates a org.jboss.weld.annotated.slim.SlimAnnotatedTypeContext for it and stores it in BeanDeployerEnvironment.
 
     public BeanDeployer addClass(String classNameAnnotatedTypeLoader loader) {
         SlimAnnotatedTypeContext<?> ctx = loader.loadAnnotatedType(classNamegetManager().getId());
         if (ctx != null) {
             getEnvironment().addAnnotatedType(ctx);
        }
        return this;
    }
    private void processPriority(AnnotatedType<?> type) {
        Object priority = type.getAnnotation(.);
        if (priority != null) {
            Integer value = .getPriority(priority);
            if (value != null) {
                if (type.isAnnotationPresent(Interceptor.class)) {
                    .addInterceptor(type.getJavaClass(), value);
                } else if (type.isAnnotationPresent(Decorator.class)) {
                    .addDecorator(type.getJavaClass(), value);
                } else {
                    /*
                     * An alternative may be given a priority for the application by placing the @Priority annotation on the bean
                     * class that declares the producer method, field or resource.
                     */
                    .addAlternative(type.getJavaClass(), value);
                }
            }
        }
    }
    public <T> BeanDeployer addSyntheticClass(AnnotatedType<T> sourceExtension extensionString suffix) {
        if (suffix == null) {
            suffix = AnnotatedTypes.createTypeId(source);
        }
        return this;
    }
    public BeanDeployer addClasses(Iterable<Stringclasses) {
        AnnotatedTypeLoader loader = createAnnotatedTypeLoader();
        for (String className : classes) {
            addClass(classNameloader);
        }
        return this;
    }
        if ( != null) {
            // Since FastProcessAnnotatedTypeResolver is installed after BeanDeployers are created, we need to query deploymentManager's services instead of the manager of this deployer
            if (resolver != null) {
                return new FastAnnotatedTypeLoader(getManager(), resolver);
            }
        }
        // if FastProcessAnnotatedTypeResolver is not available, fall back to AnnotatedTypeLoader
    }
    public void processAnnotatedTypes() {
        Set<SlimAnnotatedTypeContext<?>> classesToBeAdded = new HashSet<SlimAnnotatedTypeContext<?>>();
        Set<SlimAnnotatedTypeContext<?>> classesToBeRemoved = new HashSet<SlimAnnotatedTypeContext<?>>();
        for (SlimAnnotatedTypeContext<?> annotatedTypeContext : getEnvironment().getAnnotatedTypes()) {
            SlimAnnotatedType<?> annotatedType = annotatedTypeContext.getAnnotatedType();
            final ProcessAnnotatedTypeImpl<?> event = .fireProcessAnnotatedType(getManager(), annotatedTypeContext);
            // process the result
            if (event != null) {
                if (event.isVeto()) {
                    getEnvironment().vetoJavaClass(annotatedType.getJavaClass());
                    classesToBeRemoved.add(annotatedTypeContext);
                } else {
                    boolean dirty = event.isDirty();
                    if (dirty) {
                        classesToBeRemoved.add(annotatedTypeContext); // remove the original class
                        classesToBeAdded.add(SlimAnnotatedTypeContext.of(event.getResultingAnnotatedType(), annotatedTypeContext.getExtension()));
                    }
                    processPriority(event.getResultingAnnotatedType());
                }
            } else {
                processPriority(annotatedType);
            }
        }
        getEnvironment().removeAnnotatedTypes(classesToBeRemoved);
        getEnvironment().addAnnotatedTypes(classesToBeAdded);
    }
    public void registerAnnotatedTypes() {
        for (SlimAnnotatedTypeContext<?> ctx : getEnvironment().getAnnotatedTypes()) {
            .put(ctx.getAnnotatedType());
        }
    }
    public void createClassBeans() {
        LoadingCache<Class<?>, Set<SlimAnnotatedType<?>>> otherWeldClasses = Multimaps.newConcurrentSetMultimap();
        for (SlimAnnotatedTypeContext<?> ctx : getEnvironment().getAnnotatedTypes()) {
            createClassBean(ctx.getAnnotatedType(), otherWeldClasses);
        }
        // create session beans
        for (InternalEjbDescriptor<?> ejbDescriptor : getEnvironment().getEjbDescriptors()) {
            if (getEnvironment().isVetoed(ejbDescriptor.getBeanClass()) || Beans.isVetoed(ejbDescriptor.getBeanClass())) {
                continue;
            }
            if (ejbDescriptor.isSingleton() || ejbDescriptor.isStateful() || ejbDescriptor.isStateless()) {
                if (otherWeldClasses.getIfPresent(ejbDescriptor.getBeanClass()) != null) {
                    for (SlimAnnotatedType<?> annotatedType : getCacheValue(otherWeldClassesejbDescriptor.getBeanClass())) {
                        EnhancedAnnotatedType<?> weldClass = .getEnhancedAnnotatedType(annotatedType);
                        createSessionBean(ejbDescriptor, Reflections.<EnhancedAnnotatedTypecast(weldClass));
                    }
                } else {
                    createSessionBean(ejbDescriptor);
                }
            }
        }
    }
    protected void createClassBean(SlimAnnotatedType<?> annotatedType,
            LoadingCache<Class<?>, Set<SlimAnnotatedType<?>>> otherWeldClasses) {
        boolean managedBeanOrDecorator = !getEnvironment().getEjbDescriptors().contains(annotatedType.getJavaClass()) && Beans.isTypeManagedBeanOrDecoratorOrInterceptor(annotatedType);
        if (managedBeanOrDecorator) {
            EnhancedAnnotatedType<?> weldClass = .getEnhancedAnnotatedType(annotatedType);
            if (weldClass.isAnnotationPresent(Decorator.class)) {
                .preloadProcessBean(ProcessBean.classannotatedType.getJavaClass());
                validateDecorator(weldClass);
                createDecorator(weldClass);
            } else if (weldClass.isAnnotationPresent(Interceptor.class)) {
                .preloadProcessBean(ProcessBean.classannotatedType.getJavaClass());
                validateInterceptor(weldClass);
                createInterceptor(weldClass);
            } else if (!weldClass.isAbstract()) {
                .preloadProcessBean(ProcessManagedBean.classannotatedType.getJavaClass());
                createManagedBean(weldClass);
            }
        } else {
            getCacheValue(otherWeldClassesannotatedType.getJavaClass()).add(annotatedType);
        }
    }

    
Fires javax.enterprise.inject.spi.ProcessBeanAttributes for each enabled bean and updates the environment based on the events.
    public void processClassBeanAttributes() {
        // now that we know that the bean won't be vetoed, it's the right time to register @New injection points
    }
    private void preInitializeBeans(Iterable<? extends AbstractBean<?, ?>> beans) {
        for (AbstractBean<?, ?> bean : beans) {
            bean.preInitialize();
        }
    }
    protected void processBeanAttributes(Iterable<? extends AbstractBean<?, ?>> beans) {
            return;
        }
        if (!beans.iterator().hasNext()) {
            return// exit recursion
        }
        Collection<AbstractBean<?, ?>> vetoedBeans = new HashSet<AbstractBean<?, ?>>();
        Collection<AbstractBean<?, ?>> previouslySpecializedBeans = new HashSet<AbstractBean<?, ?>>();
        for (AbstractBean<?, ?> bean : beans) {
            // fire ProcessBeanAttributes for class beans
            boolean vetoed = fireProcessBeanAttributes(bean);
            if (vetoed) {
                vetoedBeans.add(bean);
            }
        }
        // remove vetoed class beans
        for (AbstractBean<?, ?> bean : vetoedBeans) {
            if (bean.isSpecializing()) {
                previouslySpecializedBeans.addAll(.resolveSpecializedBeans(bean));
                .vetoSpecializingBean(bean);
            }
            getEnvironment().vetoBean(bean);
        }
        // if a specializing bean was vetoed, let's process the specializing bean now
        processBeanAttributes(previouslySpecializedBeans);
    }
    protected void searchForNewBeanDeclarations(Iterable<? extends AbstractBean<?, ?>> beans) {
        for (AbstractBean<?, ?> bean : beans) {
            getEnvironment().addNewBeansFromInjectionPoints(bean);
        }
    }
    public void createProducersAndObservers() {
        for (AbstractClassBean<?> bean : getEnvironment().getClassBeans()) {
            createObserversProducersDisposers(bean);
        }
    }
    public void processProducerAttributes() {
        // process BeanAttributes for producer methods
    }
    public void createNewBeans() {
        for (EnhancedAnnotatedType<?> clazz : getEnvironment().getNewManagedBeanClasses()) {
            createNewManagedBean(clazz);
        }
            InternalEjbDescriptor<?> descriptor = entry.getKey();
            createNewSessionBean(descriptor, BeanAttributesFactory.forSessionBean(entry.getValue(), descriptorgetManager()), entry.getValue());
        }
    }
    public void deploy() {
        initializeBeans();
        fireBeanEvents();
        deployBeans();
        initializeObserverMethods();
        deployObserverMethods();
    }
    protected void validateInterceptor(EnhancedAnnotatedType<?> weldClass) {
        if (weldClass.isAnnotationPresent(Decorator.class)) {
            throw ..beanIsBothInterceptorAndDecorator(weldClass.getName());
        }
    }
    protected void validateDecorator(EnhancedAnnotatedType<?> weldClass) {
        if (weldClass.isAnnotationPresent(Interceptor.class)) {
            throw ..beanIsBothInterceptorAndDecorator(weldClass.getName());
        }
    }
    public void doAfterBeanDiscovery(List<? extends Bean<?>> beanList) {
        for (Bean<?> bean : beanList) {
            if (bean instanceof RIBean<?>) {
                ((RIBean<?>) bean).initializeAfterBeanDiscovery();
            }
        }
    }
        EjbServices ejbServices = getManager().getServices().get(EjbServices.class);
        for (InternalEjbDescriptor<?> descriptor : getEnvironment().getEjbDescriptors()) {
            if (descriptor.isMessageDriven()) {
                EnhancedAnnotatedType<?> type =  .getEnhancedAnnotatedType(descriptor.getBeanClass(), getManager().getId());
                if (!getManager().getInterceptorModelRegistry().containsKey(type.slim())) {
                    InterceptionModelInitializer.of(getManager(), typenull).init();
                }
                InterceptionModel model = getManager().getInterceptorModelRegistry().get(type.slim());
                if (model != null) {
                    ejbServices.registerInterceptors(descriptornew InterceptorBindingsAdapter(model));
                }
            }
        }
    }
    public ResourceLoader getResourceLoader() {
        return ;
    }
    public void cleanup() {
        getEnvironment().cleanup();
    }
New to GrepCode? Check out our FAQ X