// The fragments and corresponding annotations will need to be merged in order
// For each JAR in the order:
// - Merge the annotation metadata into the fragment meta data
// (unless the fragment exists and is meta data complete)
// - Merge the fragment metadata into merged fragment meta data
WebCommonMetaData mergedFragmentMetaData = new WebCommonMetaData();
if (specMetaData == null)
{
// If there is no web.xml, it has to be considered to be the latest version
specMetaData = new Web30MetaData();
specMetaData.setVersion("3.0");
}
String key = AnnotationMetaDataDeployer.WEB_ANNOTATED_ATTACHMENT_NAME + ":classes";
// Augment with meta data from annotations in /WEB-INF/classes
WebMetaData classesAnnotatedMetaData = unit.getAttachment(key, WebMetaData.class);
if (classesAnnotatedMetaData != null)
{
if (isComplete)
{
// Discard @WebFilter, @WebListener and @WebServlet
classesAnnotatedMetaData.setFilters(null);
classesAnnotatedMetaData.setFilterMappings(null);
classesAnnotatedMetaData.setListeners(null);
classesAnnotatedMetaData.setServlets(null);
classesAnnotatedMetaData.setServletMappings(null);
}
specMetaData.augment(classesAnnotatedMetaData, null, true);
}
// Augment with meta data from fragments and annotations from the corresponding JAR
for (String jar : order)
{
WebFragmentMetaData webFragmentMetaData = webFragments.get(jar);
if (webFragmentMetaData == null)
{
webFragmentMetaData = new WebFragmentMetaData();
// Add non overriding default distributable flag
webFragmentMetaData.setDistributable(new EmptyMetaData());
}
key = AnnotationMetaDataDeployer.WEB_ANNOTATED_ATTACHMENT_NAME + ":" + jar;
WebMetaData jarAnnotatedMetaData = unit.getAttachment(key, WebMetaData.class);
if ((isComplete || webFragmentMetaData.isMetadataComplete()) && jarAnnotatedMetaData != null)
{
// Discard @WebFilter, @WebListener and @WebServlet
jarAnnotatedMetaData.setFilters(null);
jarAnnotatedMetaData.setFilterMappings(null);
jarAnnotatedMetaData.setListeners(null);
jarAnnotatedMetaData.setServlets(null);
jarAnnotatedMetaData.setServletMappings(null);
}
if (jarAnnotatedMetaData != null)
{
// Merge annotations corresponding to the JAR
webFragmentMetaData.augment(jarAnnotatedMetaData, null, true);
}
// Merge fragment meta data according to the conflict rules
try
{
mergedFragmentMetaData.augment(webFragmentMetaData, specMetaData, false);
}
catch (Exception e)
{
DeploymentException.rethrowAsDeploymentException("Deployment error processing fragment for JAR: " + jar, e);
}
}
// Augment with meta data from annotations from JARs excluded from the order
for (String jar : jarsSet)
{
WebFragmentMetaData webFragmentMetaData = new WebFragmentMetaData();
// Add non overriding default distributable flag
webFragmentMetaData.setDistributable(new EmptyMetaData());
key = AnnotationMetaDataDeployer.WEB_ANNOTATED_ATTACHMENT_NAME + ":" + jar;
WebMetaData jarAnnotatedMetaData = unit.getAttachment(key, WebMetaData.class);
if (jarAnnotatedMetaData != null)
{
// Discard @WebFilter, @WebListener and @WebServlet
jarAnnotatedMetaData.setFilters(null);
jarAnnotatedMetaData.setFilterMappings(null);
jarAnnotatedMetaData.setListeners(null);
jarAnnotatedMetaData.setServlets(null);
jarAnnotatedMetaData.setServletMappings(null);
}
if (jarAnnotatedMetaData != null)
{
// Merge annotations corresponding to the JAR
webFragmentMetaData.augment(jarAnnotatedMetaData, null, true);
}
// Merge fragment meta data according to the conflict rules
try
{
mergedFragmentMetaData.augment(webFragmentMetaData, specMetaData, false);
}
catch (Exception e)
{
DeploymentException.rethrowAsDeploymentException("Deployment error processing fragment for JAR: " + jar, e);
}