Package org.glassfish.weld.connector
Class WeldUtils
- java.lang.Object
-
- org.glassfish.weld.connector.WeldUtils
-
public class WeldUtils extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
WeldUtils.BDAType
Bean Deployment Archive type.
-
Field Summary
Fields Modifier and Type Field Description static String
BEANS_XML_FILENAME
protected static Set<String>
cdiEnablingAnnotations
protected static Set<String>
cdiScopeAnnotations
static String
CLASS_SUFFIX
static String
EXPANDED_JAR_SUFFIX
static String
EXPANDED_RAR_SUFFIX
static String
JAR_SUFFIX
static String
META_INF_BCE_SERVICES_EXTENSION
static String
META_INF_BEANS_XML
static String
META_INF_SERVICES_EXTENSION
static String
RAR_SUFFIX
static char
SEPARATOR_CHAR
static String
WEB_INF
static String
WEB_INF_BCE_EXTENSION
static String
WEB_INF_BEANS_XML
static String
WEB_INF_CLASSES
static String
WEB_INF_CLASSES_META_INF_BEANS_XML
static String
WEB_INF_LIB
static String
WEB_INF_SERVICES_EXTENSION
-
Constructor Summary
Constructors Constructor Description WeldUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
getBeanDiscoveryMode(InputStream beansXmlInputStream)
Get the "bean-discovery-mode" from the "beans" element if it exists in beans.xml From section 12.1 of CDI spec: A bean archive has a bean discovery mode of all, annotated or none.static InputStream
getBeansXmlInputStream(ReadableArchive archive)
static InputStream
getBeansXmlInputStream(DeploymentContext context)
static Collection<String>
getCDIAnnotatedClassNames(DeploymentContext context)
Get the names of any classes that are annotated with bean-defining annotations, which should enable CDI processing even in the absence of a beans.xml descriptor.static String[]
getCDIEnablingAnnotations(DeploymentContext context)
Get the names of any annotation types that are applied to beans, which should enable CDI processing even in the absence of a beans.xml descriptor.static Collection<String>
getInjectionTargetClassNames(org.glassfish.hk2.classmodel.reflect.Types types, Collection<String> knownClassNames)
Searches through the known class names of aBeanDeploymentArchive
to determine which have fields or methods with theInject
annotation.static int
getPreLoaderThreads()
static boolean
hasBeansXML(ReadableArchive archive)
static boolean
hasCDIEnablingAnnotation(Class clazz)
Determine whether the specified class is annotated with a CDI-enabling annotation.static boolean
hasCDIEnablingAnnotations(DeploymentContext context, URI path)
Determine whether there are any beans annotated with annotations that should enable CDI processing even in the absence of a beans.xml descriptor.static boolean
hasCDIEnablingAnnotations(DeploymentContext context, Collection<URI> paths)
Determine whether there are any beans annotated with annotations that should enable CDI processing even in the absence of a beans.xml descriptor.static boolean
hasExtension(ReadableArchive archive)
static boolean
hasScopeAnnotation(Class clazz)
Determine whether the specified class is annotated with a CDI scope annotation.static boolean
hasValidAnnotation(Class annotatedClass, Set<String> validScopes, Collection<String> excludedScopes)
Determine whether the specified class is annotated with one of the annotations in the specified validScopes collection, but not with any of the annotations in the specified exclusion set.static boolean
isCDIDevModeEnabled(DeploymentContext context)
static boolean
isConcurrentDeploymentEnabled()
static boolean
isEmptyBeansXmlModeALL(DeploymentContext context)
static boolean
isImplicitBeanArchive(DeploymentContext context, URI archivePath)
Determine whether the specified archive is an implicit bean deployment archive.static boolean
isImplicitBeanArchive(DeploymentContext context, ReadableArchive archive)
Determine whether the specified archive is an implicit bean deployment archive.static boolean
isImplicitBeanDiscoveryEnabled()
static boolean
isImplicitBeanDiscoveryEnabled(DeploymentContext context)
static boolean
isValidBdaBasedOnExtensionAndBeansXml(ReadableArchive archive)
Determine if an archive is a valid bda based on what the spec says about extensions.static void
setCDIDevMode(DeploymentContext context, boolean enabled)
-
-
-
Field Detail
-
SEPARATOR_CHAR
public static final char SEPARATOR_CHAR
- See Also:
- Constant Field Values
-
WEB_INF
public static final String WEB_INF
- See Also:
- Constant Field Values
-
WEB_INF_CLASSES
public static final String WEB_INF_CLASSES
- See Also:
- Constant Field Values
-
WEB_INF_LIB
public static final String WEB_INF_LIB
- See Also:
- Constant Field Values
-
BEANS_XML_FILENAME
public static final String BEANS_XML_FILENAME
- See Also:
- Constant Field Values
-
WEB_INF_BEANS_XML
public static final String WEB_INF_BEANS_XML
- See Also:
- Constant Field Values
-
META_INF_BEANS_XML
public static final String META_INF_BEANS_XML
- See Also:
- Constant Field Values
-
WEB_INF_CLASSES_META_INF_BEANS_XML
public static final String WEB_INF_CLASSES_META_INF_BEANS_XML
- See Also:
- Constant Field Values
-
META_INF_SERVICES_EXTENSION
public static final String META_INF_SERVICES_EXTENSION
- See Also:
- Constant Field Values
-
META_INF_BCE_SERVICES_EXTENSION
public static final String META_INF_BCE_SERVICES_EXTENSION
- See Also:
- Constant Field Values
-
WEB_INF_SERVICES_EXTENSION
public static final String WEB_INF_SERVICES_EXTENSION
- See Also:
- Constant Field Values
-
WEB_INF_BCE_EXTENSION
public static final String WEB_INF_BCE_EXTENSION
- See Also:
- Constant Field Values
-
CLASS_SUFFIX
public static final String CLASS_SUFFIX
- See Also:
- Constant Field Values
-
JAR_SUFFIX
public static final String JAR_SUFFIX
- See Also:
- Constant Field Values
-
RAR_SUFFIX
public static final String RAR_SUFFIX
- See Also:
- Constant Field Values
-
EXPANDED_RAR_SUFFIX
public static final String EXPANDED_RAR_SUFFIX
- See Also:
- Constant Field Values
-
EXPANDED_JAR_SUFFIX
public static final String EXPANDED_JAR_SUFFIX
- See Also:
- Constant Field Values
-
-
Method Detail
-
isImplicitBeanArchive
public static boolean isImplicitBeanArchive(DeploymentContext context, ReadableArchive archive) throws IOException
Determine whether the specified archive is an implicit bean deployment archive.- Parameters:
context
- The deployment contextarchive
- The archive in question- Returns:
- true, if it is an implicit bean deployment archive; otherwise, false.
- Throws:
IOException
-
isImplicitBeanArchive
public static boolean isImplicitBeanArchive(DeploymentContext context, URI archivePath)
Determine whether the specified archive is an implicit bean deployment archive.- Parameters:
context
- The deployment contextarchivePath
- The URI of the archive- Returns:
- true, if it is an implicit bean deployment archive; otherwise, false.
-
hasCDIEnablingAnnotations
public static boolean hasCDIEnablingAnnotations(DeploymentContext context, URI path)
Determine whether there are any beans annotated with annotations that should enable CDI processing even in the absence of a beans.xml descriptor.- Parameters:
context
- The DeploymentContextpath
- The path to check for annotated beans- Returns:
- true, if there is at least one bean annotated with a qualified annotation in the specified path
-
hasCDIEnablingAnnotations
public static boolean hasCDIEnablingAnnotations(DeploymentContext context, Collection<URI> paths)
Determine whether there are any beans annotated with annotations that should enable CDI processing even in the absence of a beans.xml descriptor.- Parameters:
context
- The DeploymentContextpaths
- The paths to check for annotated beans- Returns:
- true, if there is at least one bean annotated with a qualified annotation in the specified paths
-
getCDIEnablingAnnotations
public static String[] getCDIEnablingAnnotations(DeploymentContext context)
Get the names of any annotation types that are applied to beans, which should enable CDI processing even in the absence of a beans.xml descriptor.- Parameters:
context
- The DeploymentContext- Returns:
- An array of annotation type names; The array could be empty if none are found.
-
getCDIAnnotatedClassNames
public static Collection<String> getCDIAnnotatedClassNames(DeploymentContext context)
Get the names of any classes that are annotated with bean-defining annotations, which should enable CDI processing even in the absence of a beans.xml descriptor.- Parameters:
context
- The DeploymentContext- Returns:
- A collection of class names; The collection could be empty if none are found.
-
getInjectionTargetClassNames
public static Collection<String> getInjectionTargetClassNames(org.glassfish.hk2.classmodel.reflect.Types types, Collection<String> knownClassNames)
Searches through the known class names of aBeanDeploymentArchive
to determine which have fields or methods with theInject
annotation.- Parameters:
types
- The Types obtained from aDeploymentContext
's transient metadataknownClassNames
- The known class names of aBeanDeploymentArchive
- Returns:
- The class names from the given list which have fields or methods annotated with
Inject
-
hasScopeAnnotation
public static boolean hasScopeAnnotation(Class clazz)
Determine whether the specified class is annotated with a CDI scope annotation.- Parameters:
clazz
- The class to check.- Returns:
- true, if the specified class has a CDI scope annotation; Otherwise, false.
-
hasCDIEnablingAnnotation
public static boolean hasCDIEnablingAnnotation(Class clazz)
Determine whether the specified class is annotated with a CDI-enabling annotation.- Parameters:
clazz
- The class to check.- Returns:
- true, if the specified class has a CDI scope annotation; Otherwise, false.
-
hasValidAnnotation
public static boolean hasValidAnnotation(Class annotatedClass, Set<String> validScopes, Collection<String> excludedScopes)
Determine whether the specified class is annotated with one of the annotations in the specified validScopes collection, but not with any of the annotations in the specified exclusion set.- Parameters:
annotatedClass
- The class to check.validScopes
- A collection of valid CDI scope type namesexcludedScopes
- A collection of excluded CDI scope type names- Returns:
- true, if the specified class has at least one of the annotations specified in validScopes, and none of the annotations specified in excludedScopes; Otherwise, false.
-
getPreLoaderThreads
public static int getPreLoaderThreads()
-
isConcurrentDeploymentEnabled
public static boolean isConcurrentDeploymentEnabled()
-
isImplicitBeanDiscoveryEnabled
public static boolean isImplicitBeanDiscoveryEnabled()
-
isImplicitBeanDiscoveryEnabled
public static boolean isImplicitBeanDiscoveryEnabled(DeploymentContext context)
-
isCDIDevModeEnabled
public static boolean isCDIDevModeEnabled(DeploymentContext context)
-
setCDIDevMode
public static void setCDIDevMode(DeploymentContext context, boolean enabled)
-
isEmptyBeansXmlModeALL
public static boolean isEmptyBeansXmlModeALL(DeploymentContext context)
-
getBeansXmlInputStream
public static InputStream getBeansXmlInputStream(DeploymentContext context)
-
isValidBdaBasedOnExtensionAndBeansXml
public static boolean isValidBdaBasedOnExtensionAndBeansXml(ReadableArchive archive)
Determine if an archive is a valid bda based on what the spec says about extensions. See section 12.1 which states that if an archive contains an extension but no beans.xml then it is NOT a valid bean deployment archive.- Parameters:
archive
- The archive to check.- Returns:
- false if there is an extension and no beans.xml true otherwise
-
hasExtension
public static boolean hasExtension(ReadableArchive archive)
-
hasBeansXML
public static boolean hasBeansXML(ReadableArchive archive) throws IOException
- Throws:
IOException
-
getBeansXmlInputStream
public static InputStream getBeansXmlInputStream(ReadableArchive archive)
-
getBeanDiscoveryMode
public static String getBeanDiscoveryMode(InputStream beansXmlInputStream)
Get the "bean-discovery-mode" from the "beans" element if it exists in beans.xml From section 12.1 of CDI spec: A bean archive has a bean discovery mode of all, annotated or none. A bean archive which contains a beans.xml file with no version has a default bean discovery mode of annotated. A bean archive which contains a beans.xml file with version 1.1 (or later) must specify the bean- discovey-mode attribute. The default value for the attribute is annotated.- Parameters:
beansXmlInputStream
- The InputStream for the beans.xml to check.- Returns:
- "annotated" if there is no beans.xml "annotated" if the bean-discovery-mode is missing "annotated" if the bean-discovery-mode is empty The value of bean-discovery-mode in all other cases.
-
-