Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.manager;
import static org.jboss.weld.annotated.AnnotatedTypeValidator.validateAnnotatedType;
import static org.jboss.weld.util.collections.Iterables.flatMap;
import static org.jboss.weld.util.reflection.Reflections.cast;
import static org.jboss.weld.util.reflection.Reflections.isCacheable;
import java.io.ObjectStreamException;
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Member;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.atomic.AtomicInteger;
import javax.el.ELResolver;
import javax.el.ExpressionFactory;
import javax.enterprise.context.Dependent;
import javax.enterprise.context.spi.Context;
import javax.enterprise.context.spi.Contextual;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.event.Event;
import javax.enterprise.inject.Instance;
import javax.enterprise.inject.spi.Annotated;
import javax.enterprise.inject.spi.AnnotatedField;
import javax.enterprise.inject.spi.AnnotatedMember;
import javax.enterprise.inject.spi.AnnotatedMethod;
import javax.enterprise.inject.spi.AnnotatedParameter;
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanAttributes;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.Decorator;
import javax.enterprise.inject.spi.EventMetadata;
import javax.enterprise.inject.spi.Extension;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.enterprise.inject.spi.InjectionTarget;
import javax.enterprise.inject.spi.InjectionTargetFactory;
import javax.enterprise.inject.spi.InterceptionType;
import javax.enterprise.inject.spi.Interceptor;
import javax.enterprise.inject.spi.ObserverMethod;
import javax.enterprise.inject.spi.PassivationCapable;
import javax.enterprise.inject.spi.ProducerFactory;
import javax.enterprise.util.TypeLiteral;
import org.jboss.weld.Container;
import org.jboss.weld.annotated.AnnotatedTypeValidator;
import org.jboss.weld.annotated.enhanced.EnhancedAnnotatedField;
import org.jboss.weld.annotated.enhanced.EnhancedAnnotatedMember;
import org.jboss.weld.annotated.enhanced.EnhancedAnnotatedParameter;
import org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType;
import org.jboss.weld.annotated.slim.SlimAnnotatedType;
import org.jboss.weld.bean.AbstractProducerBean;
import org.jboss.weld.bean.ContextualInstance;
import org.jboss.weld.bean.NewBean;
import org.jboss.weld.bean.RIBean;
import org.jboss.weld.bean.SessionBean;
import org.jboss.weld.bean.SyntheticBeanFactory;
import org.jboss.weld.bean.attributes.BeanAttributesFactory;
import org.jboss.weld.bean.builtin.AbstractBuiltInBean;
import org.jboss.weld.bean.builtin.ExtensionBean;
import org.jboss.weld.bean.builtin.InstanceImpl;
import org.jboss.weld.bean.proxy.ClientProxyProvider;
import org.jboss.weld.bean.proxy.DecorationHelper;
import org.jboss.weld.bootstrap.SpecializationAndEnablementRegistry;
import org.jboss.weld.bootstrap.Validator;
import org.jboss.weld.bootstrap.api.Environment;
import org.jboss.weld.bootstrap.api.ServiceRegistry;
import org.jboss.weld.bootstrap.enablement.ModuleEnablement;
import org.jboss.weld.bootstrap.events.ContainerLifecycleEvents;
import org.jboss.weld.bootstrap.spi.CDI11Deployment;
import org.jboss.weld.config.ConfigurationKey;
import org.jboss.weld.config.WeldConfiguration;
import org.jboss.weld.context.CreationalContextImpl;
import org.jboss.weld.context.PassivatingContextWrapper;
import org.jboss.weld.context.WeldCreationalContext;
import org.jboss.weld.ejb.EjbDescriptors;
import org.jboss.weld.ejb.InternalEjbDescriptor;
import org.jboss.weld.ejb.spi.EjbDescriptor;
import org.jboss.weld.el.WeldELResolver;
import org.jboss.weld.el.WeldExpressionFactory;
import org.jboss.weld.event.EventImpl;
import org.jboss.weld.event.EventMetadataImpl;
import org.jboss.weld.event.FastEvent;
import org.jboss.weld.event.GlobalObserverNotifierService;
import org.jboss.weld.event.ObserverNotifier;
import org.jboss.weld.events.WeldEvent;
import org.jboss.weld.exceptions.DefinitionException;
import org.jboss.weld.exceptions.DeploymentException;
import org.jboss.weld.exceptions.IllegalArgumentException;
import org.jboss.weld.exceptions.IllegalStateException;
import org.jboss.weld.exceptions.InjectionException;
import org.jboss.weld.inject.WeldInstance;
import org.jboss.weld.injection.CurrentInjectionPoint;
import org.jboss.weld.injection.EmptyInjectionPoint;
import org.jboss.weld.injection.ThreadLocalStack.ThreadLocalStackReference;
import org.jboss.weld.injection.attributes.FieldInjectionPointAttributes;
import org.jboss.weld.injection.attributes.InferringFieldInjectionPointAttributes;
import org.jboss.weld.injection.attributes.InferringParameterInjectionPointAttributes;
import org.jboss.weld.injection.attributes.ParameterInjectionPointAttributes;
import org.jboss.weld.injection.producer.WeldInjectionTargetBuilderImpl;
import org.jboss.weld.interceptor.reader.InterceptorMetadataReader;
import org.jboss.weld.interceptor.spi.model.InterceptionModel;
import org.jboss.weld.literal.DestroyedLiteral;
import org.jboss.weld.literal.InitializedLiteral;
import org.jboss.weld.logging.BeanManagerLogger;
import org.jboss.weld.logging.BootstrapLogger;
import org.jboss.weld.manager.api.WeldInjectionTargetBuilder;
import org.jboss.weld.manager.api.WeldInjectionTargetFactory;
import org.jboss.weld.manager.api.WeldManager;
import org.jboss.weld.metadata.cache.InterceptorBindingModel;
import org.jboss.weld.metadata.cache.MetaAnnotationStore;
import org.jboss.weld.metadata.cache.ScopeModel;
import org.jboss.weld.metadata.cache.StereotypeModel;
import org.jboss.weld.resolution.BeanTypeAssignabilityRules;
import org.jboss.weld.resolution.DecoratorResolvableBuilder;
import org.jboss.weld.resolution.InterceptorResolvable;
import org.jboss.weld.resolution.InterceptorResolvableBuilder;
import org.jboss.weld.resolution.NameBasedResolver;
import org.jboss.weld.resolution.QualifierInstance;
import org.jboss.weld.resolution.Resolvable;
import org.jboss.weld.resolution.ResolvableBuilder;
import org.jboss.weld.resolution.TypeSafeBeanResolver;
import org.jboss.weld.resolution.TypeSafeDecoratorResolver;
import org.jboss.weld.resolution.TypeSafeInterceptorResolver;
import org.jboss.weld.resolution.TypeSafeObserverResolver;
import org.jboss.weld.resources.ClassTransformer;
import org.jboss.weld.resources.MemberTransformer;
import org.jboss.weld.serialization.spi.BeanIdentifier;
import org.jboss.weld.serialization.spi.ContextualStore;
import org.jboss.weld.util.Beans;
import org.jboss.weld.util.BiConsumer;
import org.jboss.weld.util.Bindings;
import org.jboss.weld.util.ForwardingBeanManager;
import org.jboss.weld.util.Function;
import org.jboss.weld.util.InjectionPoints;
import org.jboss.weld.util.Interceptors;
import org.jboss.weld.util.LazyValueHolder;
import org.jboss.weld.util.Preconditions;
import org.jboss.weld.util.Types;
import org.jboss.weld.util.collections.Iterables;
import org.jboss.weld.util.collections.WeldCollections;
import org.jboss.weld.util.reflection.Reflections;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
/**
* Implementation of the Bean Manager.
*
* Essentially a singleton for registering Beans, Contexts, Observers,
* Interceptors etc. as well as providing resolution
*
* @author Pete Muir
* @author Marius Bogoevici
* @author Ales Justin
* @author Jozef Hartinger
*/
public class BeanManagerImpl implements WeldManager, Serializable {
private static final long serialVersionUID = 3021562879133838561L;
private static final String CREATIONAL_CONTEXT = "creationalContext";
/*
* Application scoped services
* ***************************
*/
private final transient ServiceRegistry services;
/*
* Application scoped data structures
* ***********************************
*/
// Contexts are shared across the application
private final transient Map, List> contexts;
// Client proxies can be used application wide
private final transient ClientProxyProvider clientProxyProvider;
// TODO review this structure
private final transient Map, SessionBean>> enterpriseBeans;
/*
* Archive scoped data structures
* ******************************
*/
/* These data structures are all non-transitive in terms of bean deployment
* archive accessibility, and the configuration for this bean deployment
* archive
*/
private transient volatile ModuleEnablement enabled;
private final transient Set currentActivities;
/*
* Activity scoped services
* *************************
*/
/* These services are scoped to this activity only, but use data
* structures that are transitive accessible from other bean deployment
* archives
*/
private final transient TypeSafeBeanResolver beanResolver;
private final transient TypeSafeDecoratorResolver decoratorResolver;
private final transient TypeSafeInterceptorResolver interceptorResolver;
private final transient NameBasedResolver nameBasedResolver;
private final transient ELResolver weldELResolver;
/*
* Lenient instances do not perform event type checking - this is required for firing container lifecycle events.
* Strict instances do perform event type checking and are used for firing application an extension events.
*/
private final transient ObserverNotifier accessibleLenientObserverNotifier;
private final transient ObserverNotifier globalLenientObserverNotifier;
private final transient ObserverNotifier globalStrictObserverNotifier;
/*
* Activity scoped data structures
* ********************************
*/
/* These data structures are scoped to this bean deployment archive activity
* only and represent the beans, decorators, interceptors, namespaces and
* observers deployed in this bean deployment archive activity
*/
private final transient List> enabledBeans;
// shared beans are accessible from other bean archives (generally all beans except for built-in beans and @New beans)
private final transient List> sharedBeans;
private final transient List> decorators;
private final transient List> interceptors;
private final transient List namespaces;
private final transient List> observers;
/*
* set that is only used to make sure that no duplicate beans are added
*/
private transient Set> beanSet = Collections.synchronizedSet(new HashSet>());
/*
* Data structure representing all managers *accessible* from this bean
* deployment archive activity
*/
private final transient Set managers;
/*
* These data structures represent the managers *accessible* from this bean
* deployment archive activity
*/
private final transient HashSet accessibleManagers;
/*
* This data structures represents child activities for this activity, it is
* not transitively accessible
*/
private final transient Set childActivities;
private final transient AtomicInteger childIds;
private final String id;
private final String contextId;
/**
* Interception model
*/
private final transient ConcurrentMap, InterceptionModel> interceptorModelRegistry = new ConcurrentHashMap, InterceptionModel>();
private final transient InterceptorMetadataReader interceptorMetadataReader = new InterceptorMetadataReader(this);
private final transient ContainerLifecycleEvents containerLifecycleEvents;
private final transient SpecializationAndEnablementRegistry registry;
/*
* Stuff that is used often thus we cache it here to reduce service lookups
*/
private final transient CurrentInjectionPoint currentInjectionPoint;
private final transient boolean clientProxyOptimization;
private final transient List> validationFailureCallbacks;
/**
* Request context lifecycle events
*/
private final transient LazyValueHolder> requestInitializedEvent;
private final transient LazyValueHolder> requestDestroyedEvent;
/**
* Create a new, root, manager
*
* @param serviceRegistry
* @return
*/
public static BeanManagerImpl newRootManager(String contextId, String id, ServiceRegistry serviceRegistry) {
Map, List> contexts = new ConcurrentHashMap, List>();
return new BeanManagerImpl(
serviceRegistry,
new CopyOnWriteArrayList>(),
new CopyOnWriteArrayList>(),
new CopyOnWriteArrayList>(),
new CopyOnWriteArrayList>(),
new CopyOnWriteArrayList>(),
new CopyOnWriteArrayList(),
new ConcurrentHashMap, SessionBean>>(),
new ClientProxyProvider(contextId),
contexts,
new CopyOnWriteArraySet(),
ModuleEnablement.EMPTY_ENABLEMENT,
id,
new AtomicInteger(),
new HashSet(),
contextId);
}
public static BeanManagerImpl newManager(BeanManagerImpl rootManager, String id, ServiceRegistry services) {
return new BeanManagerImpl(
services,
new CopyOnWriteArrayList>(),
new CopyOnWriteArrayList>(),
new CopyOnWriteArrayList>(),
new CopyOnWriteArrayList>(),
new CopyOnWriteArrayList>(),
new CopyOnWriteArrayList(),
rootManager.getEnterpriseBeans(),
rootManager.getClientProxyProvider(),
rootManager.getContexts(),
new CopyOnWriteArraySet(),
ModuleEnablement.EMPTY_ENABLEMENT,
id,
new AtomicInteger(),
rootManager.managers,
rootManager.contextId);
}
/**
* Create a new child manager
*
* @param parentManager the parent manager
* @return new child manager
*/
public static BeanManagerImpl newChildActivityManager(BeanManagerImpl parentManager) {
List> beans = new CopyOnWriteArrayList>();
beans.addAll(parentManager.getBeans());
List> transitiveBeans = new CopyOnWriteArrayList>();
beans.addAll(parentManager.getSharedBeans());
List> registeredObservers = new CopyOnWriteArrayList>();
registeredObservers.addAll(parentManager.getObservers());
List namespaces = new CopyOnWriteArrayList();
namespaces.addAll(parentManager.getNamespaces());
return new BeanManagerImpl(
parentManager.getServices(),
beans,
transitiveBeans,
parentManager.getDecorators(),
parentManager.getInterceptors(),
registeredObservers,
namespaces,
parentManager.getEnterpriseBeans(),
parentManager.getClientProxyProvider(),
parentManager.getContexts(),
parentManager.getCurrentActivities(),
parentManager.getEnabled(),
new StringBuilder().append(parentManager.getChildIds().incrementAndGet()).toString(),
parentManager.getChildIds(),
parentManager.managers,
parentManager.contextId);
}
private BeanManagerImpl(
ServiceRegistry serviceRegistry,
List> beans,
List> transitiveBeans,
List> decorators,
List> interceptors,
List> observers,
List namespaces,
Map, SessionBean>> enterpriseBeans,
ClientProxyProvider clientProxyProvider,
Map, List> contexts,
Set currentActivities,
ModuleEnablement enabled,
String id,
AtomicInteger childIds,
Set managers,
String contextId) {
this.services = serviceRegistry;
this.enabledBeans = beans;
this.sharedBeans = transitiveBeans;
this.decorators = decorators;
this.interceptors = interceptors;
this.enterpriseBeans = enterpriseBeans;
this.clientProxyProvider = clientProxyProvider;
this.contexts = contexts;
this.currentActivities = currentActivities;
this.observers = observers;
this.enabled = enabled;
this.namespaces = namespaces;
this.id = id;
this.childIds = new AtomicInteger();
this.managers = managers;
this.contextId = contextId;
managers.add(this);
// Set up the structure to store accessible managers in
this.accessibleManagers = new HashSet();
// TODO Currently we build the accessible bean list on the fly, we need to set it in stone once bootstrap is finished...
Transform> beanTransform = new BeanTransform(this);
this.beanResolver = new TypeSafeBeanResolver(this, createDynamicAccessibleIterable(beanTransform));
this.decoratorResolver = new TypeSafeDecoratorResolver(this, createDynamicGlobalIterable(Transform.DECORATOR));
this.interceptorResolver = new TypeSafeInterceptorResolver(this, createDynamicGlobalIterable(Transform.INTERCEPTOR));
this.nameBasedResolver = new NameBasedResolver(this, createDynamicAccessibleIterable(beanTransform));
this.weldELResolver = new WeldELResolver(this);
this.childActivities = new CopyOnWriteArraySet();
TypeSafeObserverResolver accessibleObserverResolver = new TypeSafeObserverResolver(getServices().get(MetaAnnotationStore.class),
createDynamicAccessibleIterable(Transform.OBSERVER), getServices().get(WeldConfiguration.class));
this.accessibleLenientObserverNotifier = ObserverNotifier.of(contextId, accessibleObserverResolver, getServices(), false);
GlobalObserverNotifierService globalObserverNotifierService = services.get(GlobalObserverNotifierService.class);
this.globalLenientObserverNotifier = globalObserverNotifierService.getGlobalLenientObserverNotifier();
this.globalStrictObserverNotifier = globalObserverNotifierService.getGlobalStrictObserverNotifier();
globalObserverNotifierService.registerBeanManager(this);
this.containerLifecycleEvents = serviceRegistry.get(ContainerLifecycleEvents.class);
this.registry = getServices().get(SpecializationAndEnablementRegistry.class);
this.currentInjectionPoint = getServices().get(CurrentInjectionPoint.class);
this.clientProxyOptimization = getServices().get(WeldConfiguration.class).getBooleanProperty(ConfigurationKey.INJECTABLE_REFERENCE_OPTIMIZATION);
this.requestInitializedEvent = new LazyValueHolder>() {
@Override
protected FastEvent