beansXMLURL = WEB_INF_CLASSES_META_INF_BEANS_XML;
}
if (beansXMLURL != null) {
// Parse the descriptor to determine if CDI is disabled
BeansXml beansXML = parseBeansXML(archive, beansXMLURL);
BeanDiscoveryMode bdMode = beansXML.getBeanDiscoveryMode();
if (!bdMode.equals(BeanDiscoveryMode.NONE)) {
webinfbda = true;
// If the mode is explicitly set to "annotated", then pretend there is no beans.xml
// to force the implicit behavior
hasBeansXml = !bdMode.equals(BeanDiscoveryMode.ANNOTATED);
if (logger.isLoggable(FINE)) {
logger.log(FINE,
CDILoggerInfo.PROCESSING_BEANS_XML,
new Object[]{archive.getURI(),
WEB_INF_BEANS_XML,
WEB_INF_CLASSES_META_INF_BEANS_XML});
}
} else {
addBeansXMLURL(archive, beansXMLURL);
}
} else if (archive.exists(WEB_INF_CLASSES)) { // If WEB-INF/classes exists, check for CDI beans there
// Check WEB-INF/classes for CDI-enabling annotations
URI webinfclasses = new File(context.getSourceDir().getAbsolutePath(),
WEB_INF_CLASSES).toURI();
if (WeldUtils.isImplicitBeanArchive(context, webinfclasses)) {
webinfbda = true;
if (logger.isLoggable(FINE)) {
logger.log(FINE,
CDILoggerInfo.PROCESSING_CDI_ENABLED_ARCHIVE,
new Object[]{archive.getURI()});
}
}
}
if (webinfbda) {
bdaType = BDAType.WAR;
Enumeration<String> entries = archive.entries();
while (entries.hasMoreElements()) {
String entry = entries.nextElement();
if (legalClassName(entry)) {
if (entry.contains(WEB_INF_CLASSES)) {
//Workaround for incorrect WARs that bundle classes above WEB-INF/classes
//[See. GLASSFISH-16706]
entry = entry.substring(WEB_INF_CLASSES.length() + 1);
}
String className = filenameToClassname(entry);
try {
if (hasBeansXml || isCDIAnnotatedClass(className)) {
beanClassNames.add(className);
beanClasses.add(getClassLoader().loadClass(className));
}
moduleClassNames.add(className);
} catch (Throwable t) {
if (logger.isLoggable(Level.WARNING)) {
logger.log(Level.WARNING,
CDILoggerInfo.ERROR_LOADING_BEAN_CLASS,
new Object[]{className, t.toString()});
}
}
} else if (entry.endsWith(BEANS_XML_FILENAME)) {
addBeansXMLURL(archive, entry);
}
}
archive.close();
}
// If this archive has WEB-INF/lib entry..
// Examine all jars; If the examined jar has a META_INF/beans.xml:
// collect all classes in the jar archive
// beans.xml in the jar archive
if (archive.exists(WEB_INF_LIB)) {
if (logger.isLoggable(FINE)) {
logger.log(FINE, CDILoggerInfo.PROCESSING_WEB_INF_LIB,
new Object[]{archive.getURI()});
}
bdaType = BDAType.WAR;
Enumeration<String> entries = archive.entries(WEB_INF_LIB);
List<ReadableArchive> weblibJarsThatAreBeanArchives =
new ArrayList<ReadableArchive>();
while (entries.hasMoreElements()) {
String entry = (String) entries.nextElement();
//if directly under WEB-INF/lib
if (entry.endsWith(JAR_SUFFIX) &&
entry.indexOf(SEPARATOR_CHAR, WEB_INF_LIB.length() + 1) == -1) {
ReadableArchive weblibJarArchive = archive.getSubArchive(entry);
if (weblibJarArchive.exists(META_INF_BEANS_XML)) {
// Parse the descriptor to determine if CDI is disabled
BeansXml beansXML = parseBeansXML(weblibJarArchive, META_INF_BEANS_XML);
BeanDiscoveryMode bdMode = beansXML.getBeanDiscoveryMode();
if (!bdMode.equals(BeanDiscoveryMode.NONE)) {
if (logger.isLoggable(FINE)) {
logger.log(FINE,
CDILoggerInfo.WEB_INF_LIB_CONSIDERING_BEAN_ARCHIVE,
new Object[]{entry});
}
if (!bdMode.equals(BeanDiscoveryMode.ANNOTATED) || isImplicitBeanArchive(context, weblibJarArchive)) {
weblibJarsThatAreBeanArchives.add(weblibJarArchive);
}
}
} else {
// Check for classes annotated with qualified annotations
if (WeldUtils.isImplicitBeanArchive(context, weblibJarArchive)) {
if (logger.isLoggable(FINE)) {
logger.log(FINE,
CDILoggerInfo.WEB_INF_LIB_CONSIDERING_BEAN_ARCHIVE,
new Object[]{entry});
}
weblibJarsThatAreBeanArchives.add(weblibJarArchive);
} else {
if (logger.isLoggable(FINE)) {
logger.log(FINE,
CDILoggerInfo.WEB_INF_LIB_SKIPPING_BEAN_ARCHIVE,
new Object[]{archive.getName()});
}
}
}
}
}
//process all web-inf lib JARs and create BDAs for them
List<BeanDeploymentArchiveImpl> webLibBDAs = new ArrayList<BeanDeploymentArchiveImpl>();
if (weblibJarsThatAreBeanArchives.size() > 0) {
ListIterator<ReadableArchive> libJarIterator = weblibJarsThatAreBeanArchives.listIterator();
while (libJarIterator.hasNext()) {
ReadableArchive libJarArchive = (ReadableArchive) libJarIterator.next();
BeanDeploymentArchiveImpl wlbda =
new BeanDeploymentArchiveImpl(libJarArchive,
ejbs,
context,
WEB_INF_LIB + SEPARATOR_CHAR + libJarArchive.getName() /* Use WEB-INF/lib/jarName as BDA Id*/);
this.beanDeploymentArchives.add(wlbda); //add to list of BDAs for this WAR
webLibBDAs.add(wlbda);
}
}
ensureWebLibJarVisibility(webLibBDAs);
} else if (archive.getName().endsWith(RAR_SUFFIX) || archive.getName().endsWith(EXPANDED_RAR_SUFFIX)) {
//Handle RARs. RARs are packaged differently from EJB-JARs or WARs.
//see 20.2 of Connectors 1.6 specification
//The resource adapter classes are in a jar file within the
//RAR archive
bdaType = BDAType.RAR;
collectRarInfo(archive);
} else if (archive.exists(META_INF_BEANS_XML)) {
// Parse the descriptor to determine if CDI is disabled
BeansXml beansXML = parseBeansXML(archive, META_INF_BEANS_XML);
BeanDiscoveryMode bdMode = beansXML.getBeanDiscoveryMode();
if (!bdMode.equals(BeanDiscoveryMode.NONE)) {
if (logger.isLoggable(FINE)) {
logger.log(FINE, CDILoggerInfo.PROCESSING_BDA_JAR,
new Object[]{archive.getURI()});