org.apache.webbeans.util
Class WebBeansUtil

java.lang.Object
  extended by org.apache.webbeans.util.WebBeansUtil

public final class WebBeansUtil
extends Object

Contains some utility methods used in the all project.


Constructor Summary
WebBeansUtil(WebBeansContext webBeansContext)
           
 
Method Summary
static void checkGenericType(Class<?> clazz, Class<? extends Annotation> scope)
          Checks the generic type requirements.
static void checkInjectionPointNamedQualifier(InjectionPoint injectionPoint)
           
 void checkManagedBean(Class<?> clazz)
          Returns true if this class can be candidate for simple web bean, false otherwise.
<X> void
checkManagedBeanCondition(AnnotatedType<X> type)
          Checks the implementation class for checking conditions.
 void checkManagedBeanCondition(Class<?> clazz)
           
static void checkNullInstance(Object instance, Class<?> scopeType, String errorMessage, Object... errorMessageArgs)
           
static boolean checkObtainsInjectionPointConditions(InjectionPoint injectionPoint)
          Returns true if instance injection point false otherwise.
static void checkProducerGenericType(Bean<?> bean, Member member)
          Check producer method/field bean return type.
 void checkSerializableScopeType(Class<? extends Annotation> scopeType, boolean isSerializable, String errorMessage, Object... errorMessageArgs)
           
protected  void configSpecializedProducerMethodBeans(List<ProducerMethodBean> sortedProducerBeans)
          Configure a list of producer method beans, which override the same method and the bean classes are directly extended each other.
 void configureProducerMethodSpecializations()
          Configure direct/indirect specialized producer method beans.
protected  void configureSpecializations(Class<?> specializedClass, List<Class<?>> beanClasses)
          Configures the bean specializations.
 void configureSpecializations(List<Class<?>> beanClasses)
           
<T> ExtensionBean<T>
createExtensionComponent(Class<T> clazz)
          Creates a new extension bean.
<T> Bean<T>
createNewComponent(Class<T> type)
           
<T> NewManagedBean<T>
createNewComponent(OwbBean<T> bean, Class<T> type)
          New WebBeans component class.
<T> ManagedBean<T>
defineManagedBean(AnnotatedType<T> type)
           
<T> ManagedBean<T>
defineManagedBeanWithoutFireEvents(AnnotatedType<T> type)
          This method will be used in AfterBeanDiscovery.addBean(javax.enterprise.inject.spi.Bean)}
<T> GProcessAnnotatedType
fireProcessAnnotatedTypeEvent(AnnotatedType<T> annotatedType)
          Returns ProcessAnnotatedType event.
<T> GProcessInjectionTarget
fireProcessInjectionTargetEvent(InjectionTargetImpl<T> injectionTarget, AnnotatedType<T> annotatedType)
          Returns ProcessInjectionTarget event.
<T> GProcessInjectionTarget
fireProcessInjectionTargetEventForJavaEeComponents(Class<T> componentClass)
          Returns ProcessInjectionTarget event.
 void fireProcessObservableMethodBeanEvent(Map<ObserverMethod<?>,AnnotatedMethod<?>> annotatedMethods)
           
<T> Producer<T>
fireProcessProducerEvent(Producer<T> producer, AnnotatedMember<?> annotatedMember)
           
 void fireProcessProducerFieldBeanEvent(Map<ProducerFieldBean<?>,AnnotatedField<?>> annotatedFields)
           
 void fireProcessProducerMethodBeanEvent(Map<ProducerMethodBean<?>,AnnotatedMethod<?>> annotatedMethods, AnnotatedType<?> annotatedType)
           
<T> BeanMetadataBean<T>
getBeanMetadataBean()
          Creates a new bean metadata bean.
 ConversationBean getConversationBean()
          Returns new conversation bean instance.
static ClassLoader getCurrentClassLoader()
          Gets current classloader with current thread.
<T> DecoratorMetadataBean<T>
getDecoratorMetadataBean()
          Creates a new decorator metadata bean.
<T> EventBean<T>
getEventBean()
          Creates a new event bean.
 InjectionPointBean getInjectionPointBean()
          Returns a new injected point bean instance.
<T> InstanceBean<T>
getInstanceBean()
          Creates a new instance bean.
<T> InterceptedOrDecoratedBeanMetadataBean<T>
getInterceptedOrDecoratedBeanMetadataBean()
          Creates a new metadata bean.
<T> InterceptorMetadataBean<T>
getInterceptorMetadataBean()
          Creates a new interceptor metadata bean.
static String getManagedBeanDefaultName(String clazzName)
           
 BeanManagerBean getManagerBean()
          Creates a new manager bean instance.
static Bean<?> getMostSpecializedBean(BeanManager manager, Bean<?> component)
           
<T> Constructor<T>
getNoArgConstructor(Class<T> clazz)
           
static String getPassivationId(Contextual<?> contextual)
           
static String getProducerDefaultName(String methodName)
           
static boolean hasInjectionTargetBeanAnnotatedWithAlternative(AnnotatedType<?> beanType, Set<Class<? extends Annotation>> stereotypes)
           
static boolean hasInjectionTargetBeanAnnotatedWithAlternative(InjectionTargetBean<?> bean)
           
 void inspectErrorStack(String logMessage)
           
 boolean isAnnotatedTypeDecoratorOrInterceptor(AnnotatedType<?> annotatedType)
          Return true if this annotated type represents a decorator.
 boolean isBeanEnabled(AnnotatedType<?> at, Set<Class<? extends Annotation>> stereotypes)
           
static boolean isCdiInterceptor(AnnotatedType<?> annotatedType)
           
 Set<Bean<?>> isConfiguredWebBeans(Class<?> clazz, boolean annotate)
           
 boolean isConstructorOk(Class<?> clazz)
          Check that simple web beans class has compatible constructor.
static boolean isDecorator(AnnotatedType<?> annotatedType)
           
static boolean isDefaultExtensionBeanEventType(Class<?> clazz)
           
static boolean isDefaultExtensionProducerOrObserverEventType(Class<?> clazz)
           
static boolean isDependent(Bean<?> bean)
           
protected static boolean isDirectlySpecializedBeanSet(Set<Bean<?>> beans)
          Return true if a list of beans are directly specialized/extended each other.
static boolean isExtensionBeanEventType(Type type)
           
static boolean isExtensionEventType(Type type)
           
static boolean isExtensionProducerOrObserverEventType(Type type)
           
 boolean isPassivationCapableDependency(InjectionPoint injectionPoint)
           
 boolean isProducerBeanEnabled(InjectionTargetBean<?> parent, Set<Class<? extends Annotation>> stereotypes, Annotation[] annotations)
           
 boolean isSuperMethodNamed(AbstractOwbBean<?> component, Method method, Method superMethod)
          Configures the name of the producer method for specializing the parent.
 void setBeanEnableFlagForProducerBean(InjectionTargetBean<?> parent, AbstractProducerBean<?> producer, Annotation[] annotations)
           
 void setInjectionTargetBeanEnableFlag(InjectionTargetBean<?> bean)
          Sets bean enabled flag.
 boolean supportsJavaEeComponentInjections(Class<?> clazz)
          Returns true if given class supports injections, false otherwise.
static void throwRuntimeExceptions(Exception e)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WebBeansUtil

public WebBeansUtil(WebBeansContext webBeansContext)
Method Detail

getCurrentClassLoader

public static ClassLoader getCurrentClassLoader()
Gets current classloader with current thread.

Returns:
Current class loader instance

checkGenericType

public static void checkGenericType(Class<?> clazz,
                                    Class<? extends Annotation> scope)
Checks the generic type requirements.


checkProducerGenericType

public static void checkProducerGenericType(Bean<?> bean,
                                            Member member)
Check producer method/field bean return type.

Parameters:
bean - producer bean instance
member - related member instance

checkManagedBean

public void checkManagedBean(Class<?> clazz)
Returns true if this class can be candidate for simple web bean, false otherwise.

Parameters:
clazz - implementation class
Throws:
WebBeansConfigurationException - if any configuration exception occurs

checkManagedBeanCondition

public void checkManagedBeanCondition(Class<?> clazz)
                               throws WebBeansConfigurationException
Throws:
WebBeansConfigurationException

supportsJavaEeComponentInjections

public boolean supportsJavaEeComponentInjections(Class<?> clazz)
Returns true if given class supports injections, false otherwise.

Each plugin is asked with given class that supports injections or not.

Parameters:
clazz - scanned class
Returns:
true if given class supports injections

isConstructorOk

public boolean isConstructorOk(Class<?> clazz)
                        throws WebBeansConfigurationException
Check that simple web beans class has compatible constructor.

Parameters:
clazz - web beans simple class
Throws:
WebBeansConfigurationException - if the web beans has incompatible constructor

createNewComponent

public <T> Bean<T> createNewComponent(Class<T> type)

createNewComponent

public <T> NewManagedBean<T> createNewComponent(OwbBean<T> bean,
                                                Class<T> type)
New WebBeans component class.

Returns:
the new component

createExtensionComponent

public <T> ExtensionBean<T> createExtensionComponent(Class<T> clazz)
Creates a new extension bean.

Type Parameters:
T - extension service class
Parameters:
clazz - impl. class
Returns:
a new extension service bean

getManagerBean

public BeanManagerBean getManagerBean()
Creates a new manager bean instance.

Returns:
new manager bean instance

getInstanceBean

public <T> InstanceBean<T> getInstanceBean()
Creates a new instance bean.

Returns:
new instance bean

getEventBean

public <T> EventBean<T> getEventBean()
Creates a new event bean.

Returns:
new event bean

getBeanMetadataBean

public <T> BeanMetadataBean<T> getBeanMetadataBean()
Creates a new bean metadata bean.

Returns:
new bean

getInterceptorMetadataBean

public <T> InterceptorMetadataBean<T> getInterceptorMetadataBean()
Creates a new interceptor metadata bean.

Returns:
new bean

getDecoratorMetadataBean

public <T> DecoratorMetadataBean<T> getDecoratorMetadataBean()
Creates a new decorator metadata bean.

Returns:
new bean

getInterceptedOrDecoratedBeanMetadataBean

public <T> InterceptedOrDecoratedBeanMetadataBean<T> getInterceptedOrDecoratedBeanMetadataBean()
Creates a new metadata bean.

Returns:
new bean

getConversationBean

public ConversationBean getConversationBean()
Returns new conversation bean instance. The name is explicitly specified in 6.7.2 and is not the normal default name.

Returns:
new conversation bean

getInjectionPointBean

public InjectionPointBean getInjectionPointBean()
Returns a new injected point bean instance.

Returns:
new injected point bean

getManagedBeanDefaultName

public static String getManagedBeanDefaultName(String clazzName)

getProducerDefaultName

public static String getProducerDefaultName(String methodName)

isDirectlySpecializedBeanSet

protected static boolean isDirectlySpecializedBeanSet(Set<Bean<?>> beans)
Return true if a list of beans are directly specialized/extended each other.

Parameters:
beans, - a set of specialized beans.
Returns:

configureSpecializations

public void configureSpecializations(List<Class<?>> beanClasses)

configureSpecializations

protected void configureSpecializations(Class<?> specializedClass,
                                        List<Class<?>> beanClasses)
Configures the bean specializations.

Specialized beans inherit the name property from their parents. Specialized bean deployment priority must be higher than its super class related bean.

from the spec:
"If Y has a name and X declares a name explicitly, using @Named, the container automatically detects the problem and treats it as a definition error.

Parameters:
specializedClass - specialized class
beanClasses - all Classes which are either @Specializes or specialized.
Throws:
DefinitionException - if name is defined
InconsistentSpecializationException - related with priority
WebBeansConfigurationException - any other exception

configSpecializedProducerMethodBeans

protected void configSpecializedProducerMethodBeans(List<ProducerMethodBean> sortedProducerBeans)
Configure a list of producer method beans, which override the same method and the bean classes are directly extended each other.

Parameters:
sortedProducerBeans -

configureProducerMethodSpecializations

public void configureProducerMethodSpecializations()
Configure direct/indirect specialized producer method beans.


isConfiguredWebBeans

public Set<Bean<?>> isConfiguredWebBeans(Class<?> clazz,
                                         boolean annotate)

getNoArgConstructor

public <T> Constructor<T> getNoArgConstructor(Class<T> clazz)

isSuperMethodNamed

public boolean isSuperMethodNamed(AbstractOwbBean<?> component,
                                  Method method,
                                  Method superMethod)
Configures the name of the producer method for specializing the parent.

Parameters:
component - producer method component
method - specialized producer method
superMethod - overriden super producer method

checkObtainsInjectionPointConditions

public static boolean checkObtainsInjectionPointConditions(InjectionPoint injectionPoint)
Returns true if instance injection point false otherwise.

Parameters:
injectionPoint - injection point definition
Returns:
true if instance injection point

checkNullInstance

public static void checkNullInstance(Object instance,
                                     Class<?> scopeType,
                                     String errorMessage,
                                     Object... errorMessageArgs)

checkSerializableScopeType

public void checkSerializableScopeType(Class<? extends Annotation> scopeType,
                                       boolean isSerializable,
                                       String errorMessage,
                                       Object... errorMessageArgs)

getMostSpecializedBean

public static Bean<?> getMostSpecializedBean(BeanManager manager,
                                             Bean<?> component)

fireProcessAnnotatedTypeEvent

public <T> GProcessAnnotatedType fireProcessAnnotatedTypeEvent(AnnotatedType<T> annotatedType)
Returns ProcessAnnotatedType event.

Type Parameters:
T - bean type
Parameters:
annotatedType - bean class
Returns:
event

fireProcessInjectionTargetEvent

public <T> GProcessInjectionTarget fireProcessInjectionTargetEvent(InjectionTargetImpl<T> injectionTarget,
                                                                   AnnotatedType<T> annotatedType)
Returns ProcessInjectionTarget event.

Type Parameters:
T - bean type
Returns:
event

fireProcessInjectionTargetEventForJavaEeComponents

public <T> GProcessInjectionTarget fireProcessInjectionTargetEventForJavaEeComponents(Class<T> componentClass)
Returns ProcessInjectionTarget event.

Type Parameters:
T - bean type
Returns:
event

fireProcessProducerEvent

public <T> Producer<T> fireProcessProducerEvent(Producer<T> producer,
                                                AnnotatedMember<?> annotatedMember)

fireProcessProducerMethodBeanEvent

public void fireProcessProducerMethodBeanEvent(Map<ProducerMethodBean<?>,AnnotatedMethod<?>> annotatedMethods,
                                               AnnotatedType<?> annotatedType)

fireProcessObservableMethodBeanEvent

public void fireProcessObservableMethodBeanEvent(Map<ObserverMethod<?>,AnnotatedMethod<?>> annotatedMethods)

fireProcessProducerFieldBeanEvent

public void fireProcessProducerFieldBeanEvent(Map<ProducerFieldBean<?>,AnnotatedField<?>> annotatedFields)

checkInjectionPointNamedQualifier

public static void checkInjectionPointNamedQualifier(InjectionPoint injectionPoint)

setInjectionTargetBeanEnableFlag

public void setInjectionTargetBeanEnableFlag(InjectionTargetBean<?> bean)
Sets bean enabled flag.

Parameters:
bean - bean instance

isBeanEnabled

public boolean isBeanEnabled(AnnotatedType<?> at,
                             Set<Class<? extends Annotation>> stereotypes)

hasInjectionTargetBeanAnnotatedWithAlternative

public static boolean hasInjectionTargetBeanAnnotatedWithAlternative(InjectionTargetBean<?> bean)

hasInjectionTargetBeanAnnotatedWithAlternative

public static boolean hasInjectionTargetBeanAnnotatedWithAlternative(AnnotatedType<?> beanType,
                                                                     Set<Class<? extends Annotation>> stereotypes)

setBeanEnableFlagForProducerBean

public void setBeanEnableFlagForProducerBean(InjectionTargetBean<?> parent,
                                             AbstractProducerBean<?> producer,
                                             Annotation[] annotations)

isProducerBeanEnabled

public boolean isProducerBeanEnabled(InjectionTargetBean<?> parent,
                                     Set<Class<? extends Annotation>> stereotypes,
                                     Annotation[] annotations)

isExtensionEventType

public static boolean isExtensionEventType(Type type)

isExtensionBeanEventType

public static boolean isExtensionBeanEventType(Type type)

isDefaultExtensionBeanEventType

public static boolean isDefaultExtensionBeanEventType(Class<?> clazz)

isExtensionProducerOrObserverEventType

public static boolean isExtensionProducerOrObserverEventType(Type type)

isDefaultExtensionProducerOrObserverEventType

public static boolean isDefaultExtensionProducerOrObserverEventType(Class<?> clazz)

isDependent

public static boolean isDependent(Bean<?> bean)

inspectErrorStack

public void inspectErrorStack(String logMessage)

getPassivationId

public static String getPassivationId(Contextual<?> contextual)
Parameters:
contextual - the Bean to check
Returns:
the uniqueId if it is PassivationCapable and enabled

defineManagedBeanWithoutFireEvents

public <T> ManagedBean<T> defineManagedBeanWithoutFireEvents(AnnotatedType<T> type)
This method will be used in AfterBeanDiscovery.addBean(javax.enterprise.inject.spi.Bean)}


isPassivationCapableDependency

public boolean isPassivationCapableDependency(InjectionPoint injectionPoint)

throwRuntimeExceptions

public static void throwRuntimeExceptions(Exception e)

isDecorator

public static boolean isDecorator(AnnotatedType<?> annotatedType)
Returns:
true if this annotated type represents a decorator.

isAnnotatedTypeDecoratorOrInterceptor

public boolean isAnnotatedTypeDecoratorOrInterceptor(AnnotatedType<?> annotatedType)
Return true if this annotated type represents a decorator.

Parameters:
annotatedType - annotated type
Returns:
true if decorator

isCdiInterceptor

public static boolean isCdiInterceptor(AnnotatedType<?> annotatedType)
Returns:
true if this AnnotatedType represents a CDI Interceptor defined via a Interceptor annotation

defineManagedBean

public <T> ManagedBean<T> defineManagedBean(AnnotatedType<T> type)

checkManagedBeanCondition

public <X> void checkManagedBeanCondition(AnnotatedType<X> type)
                               throws WebBeansConfigurationException
Checks the implementation class for checking conditions.

Parameters:
type - implementation class
Throws:
WebBeansConfigurationException - if any configuration exception occurs


Copyright © 2008–2014 The Apache Software Foundation. All rights reserved.