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.
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.webbeans.container;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.el.ELResolver;
import javax.el.ExpressionFactory;
import javax.enterprise.context.ContextNotActiveException;
import javax.enterprise.context.Dependent;
import javax.enterprise.context.NormalScope;
import javax.enterprise.context.spi.AlterableContext;
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.Default;
import javax.enterprise.inject.InjectionException;
import javax.enterprise.inject.Instance;
import javax.enterprise.inject.Stereotype;
import javax.enterprise.inject.Vetoed;
import javax.enterprise.inject.spi.*;
import javax.inject.Scope;
import javax.interceptor.InterceptorBinding;
import javax.naming.NamingException;
import javax.naming.Reference;
import javax.naming.Referenceable;
import javax.naming.StringRefAddr;
import org.apache.webbeans.annotation.AnyLiteral;
import org.apache.webbeans.annotation.DefaultLiteral;
import org.apache.webbeans.component.AbstractOwbBean;
import org.apache.webbeans.component.AbstractProducerBean;
import org.apache.webbeans.component.CdiInterceptorBean;
import org.apache.webbeans.component.DecoratorBean;
import org.apache.webbeans.component.EnterpriseBeanMarker;
import org.apache.webbeans.component.InjectionTargetBean;
import org.apache.webbeans.component.JmsBeanMarker;
import org.apache.webbeans.component.ManagedBean;
import org.apache.webbeans.component.NewBean;
import org.apache.webbeans.component.OwbBean;
import org.apache.webbeans.component.ProducerAwareInjectionTargetBean;
import org.apache.webbeans.component.WebBeansType;
import org.apache.webbeans.component.creation.BeanAttributesBuilder;
import org.apache.webbeans.component.creation.CdiInterceptorBeanBuilder;
import org.apache.webbeans.component.creation.DecoratorBeanBuilder;
import org.apache.webbeans.component.creation.FieldProducerFactory;
import org.apache.webbeans.component.creation.MethodProducerFactory;
import org.apache.webbeans.component.third.PassivationCapableThirdpartyBeanImpl;
import org.apache.webbeans.component.third.ThirdpartyBeanImpl;
import org.apache.webbeans.config.WebBeansContext;
import org.apache.webbeans.context.CustomAlterablePassivatingContextImpl;
import org.apache.webbeans.context.CustomPassivatingContextImpl;
import org.apache.webbeans.context.creational.CreationalContextImpl;
import org.apache.webbeans.decorator.DecoratorComparator;
import org.apache.webbeans.event.EventImpl;
import org.apache.webbeans.event.EventMetadataImpl;
import org.apache.webbeans.exception.WebBeansConfigurationException;
import org.apache.webbeans.exception.DuplicateDefinitionException;
import org.apache.webbeans.intercept.InterceptorUtil;
import org.apache.webbeans.plugins.OpenWebBeansJmsPlugin;
import org.apache.webbeans.portable.AnnotatedElementFactory;
import org.apache.webbeans.portable.InjectionTargetImpl;
import org.apache.webbeans.portable.LazyInterceptorDefinedInjectionTarget;
import org.apache.webbeans.portable.events.discovery.ErrorStack;
import org.apache.webbeans.portable.events.generics.GProcessInjectionPoint;
import org.apache.webbeans.portable.events.generics.GProcessInjectionTarget;
import org.apache.webbeans.spi.adaptor.ELAdaptor;
import org.apache.webbeans.spi.plugins.OpenWebBeansEjbPlugin;
import org.apache.webbeans.util.AnnotationUtil;
import org.apache.webbeans.util.Asserts;
import org.apache.webbeans.util.ClassUtil;
import org.apache.webbeans.util.GenericsUtil;
import org.apache.webbeans.util.WebBeansUtil;
/**
* Implementation of the {@link BeanManager} contract of the web beans
* container.
*
*
* It is written as thread-safe.
*
*
* @version $Rev$ $Date$
* @see BeanManager
*/
@SuppressWarnings("unchecked")
public class BeanManagerImpl implements BeanManager, Referenceable
{
private static final long serialVersionUID = 2L;
/**
* Holds the non-standard contexts with key = scope type
* This will get used if more than 1 scope exists.
* Since the contexts will only get added through the
* {@link org.apache.webbeans.portable.events.discovery.AfterBeanDiscoveryImpl}
* we don't even need a ConcurrentHashMap.
* @see #singleContextMap
*/
private Map, List> contextMap = new HashMap<>();
/**
* This will hold non-standard contexts where only one Context implementation got registered
* for the given key = scope type
* Since the contexts will only get added through the
* {@link org.apache.webbeans.portable.events.discovery.AfterBeanDiscoveryImpl}
* we don't even need a ConcurrentHashMap.
* @see #contextMap
*/
private Map, Context> singleContextMap = new HashMap<>();
/**Deployment archive beans*/
private Set> deploymentBeans = new HashSet<>();
/**Normal scoped cache proxies*/
private Map, Object> cacheProxies = new ConcurrentHashMap<>();
/**Injection resolver instance*/
private InjectionResolver injectionResolver;
/**
* This list contains additional qualifiers which got set via the
* {@link javax.enterprise.inject.spi.BeforeBeanDiscovery#addQualifier(Class)}
* event function.
*/
private List> additionalQualifiers = new ArrayList<>();
private Map, AnnotatedType extends Annotation>> additionalAnnotatedTypeQualifiers = new HashMap<>();
/**
* This list contains additional scopes which got set via the
* {@link javax.enterprise.inject.spi.BeforeBeanDiscovery#addScope(Class, boolean, boolean)} event function.
*/
private List additionalScopes = new ArrayList<>();
/** quick detection if an annotation is a scope-annotation */
private Set> scopeAnnotations = new HashSet<>();
/** quick detection if an annotation is NOT a scope-annotation */
private Set> nonscopeAnnotations = new HashSet<>();
private ConcurrentMap, ConcurrentMap>> additionalAnnotatedTypes = new ConcurrentHashMap<>();
private ErrorStack errorStack = new ErrorStack();
/**
* This map stores all beans along with their unique {@link javax.enterprise.inject.spi.PassivationCapable} id.
* This is used as a reference for serialization.
*/
private ConcurrentMap> passivationBeans = new ConcurrentHashMap<>();
/**InjectionTargets for Java EE component instances that supports injections*/
private Map, Producer>> producersForJavaEeComponents =
new ConcurrentHashMap<>();
private AnnotatedElementFactory annotatedElementFactory;
private final WebBeansContext webBeansContext;
/**
* This flag will get set to true if a custom bean
* (all non-internal beans like {@link org.apache.webbeans.component.BeanManagerBean;} etc)
* gets set.
*/
private boolean inUse;
/**
* This flag will get set to handle lifecyle around
* {@link javax.enterprise.inject.spi.AfterBeanDiscovery}
*/
private LifecycleState beanDiscoveryState = LifecycleState.BEFORE_DISCOVERY;
/**
* This flag will get set to {@code true} after the
* {@link javax.enterprise.inject.spi.AfterDeploymentValidation} gets fired
*/
private boolean afterDeploymentValidationFired;
/**
* we cache results of calls to {@link #isNormalScope(Class)} because
* this doesn't change at runtime.
* We don't need to take special care about classloader
* hierarchies, because each cl has other classes.
*/
private static Map, Boolean> isScopeTypeNormalCache =
new ConcurrentHashMap<>();
/**
* Map to be able to lookup always 3rd party beans when user does lookups with custom beans.
*/
private Map, Bean>> thirdPartyMapping = new HashMap<>();
/**
* Creates a new {@link BeanManager} instance.
* Called by the system. Do not use outside of the
* system.
*/
public BeanManagerImpl(WebBeansContext webBeansContext)
{
this.webBeansContext = webBeansContext;
injectionResolver = new InjectionResolver(webBeansContext);
annotatedElementFactory = webBeansContext.getAnnotatedElementFactory();
}
public WebBeansContext getWebBeansContext()
{
return webBeansContext;
}
public void putProducerForJavaEeComponent(Class javaEeComponentClass, Producer wrapper)
{
Asserts.assertNotNull(javaEeComponentClass);
Asserts.assertNotNull(wrapper);
producersForJavaEeComponents.put(javaEeComponentClass, wrapper);
}
public Producer getProducerForJavaEeComponent(Class javaEeComponentClass)
{
Asserts.assertNotNull(javaEeComponentClass);
return (Producer) producersForJavaEeComponents.get(javaEeComponentClass);
}
public ErrorStack getErrorStack()
{
return errorStack;
}
/**
* Gets injection resolver.
*
* @return injection resolver
*/
public InjectionResolver getInjectionResolver()
{
return injectionResolver;
}
/**
* Gets the active context for the given scope type.
*
* @param scopeType scope type of the context
* @throws ContextNotActiveException if no active context
* @throws IllegalStateException if more than one active context
*/
@Override
public Context getContext(Class extends Annotation> scopeType)
{
Asserts.assertNotNull(scopeType, "scopeType");
Context standardContext = webBeansContext.getContextsService().getCurrentContext(scopeType);
if(standardContext != null && standardContext.isActive())
{
return standardContext;
}
// this is by far the most case
Context singleContext = singleContextMap.get(scopeType);
if (singleContext != null)
{
if (!singleContext.isActive())
{
throw new ContextNotActiveException("WebBeans context with scope type annotation @"
+ scopeType.getSimpleName()
+ " does not exist within current thread");
}
return singleContext;
}
// the spec also allows for multiple contexts existing for the same scope type
// but in this case only one must be active at a time (for the current thread)
List others = contextMap.get(scopeType);
Context found = null;
if(others != null)
{
for(Context otherContext : others)
{
if(otherContext.isActive())
{
if (found != null)
{
throw new IllegalStateException("More than one active context exists with scope type annotation @"
+ scopeType.getSimpleName());
}
found = otherContext;
}
}
}
if (found == null)
{
throw new ContextNotActiveException("WebBeans context with scope type annotation @"
+ scopeType.getSimpleName() + " does not exist within current thread");
}
return found;
}
@Override
public Instance