Package org.jboss.metadata.web.spec

Examples of org.jboss.metadata.web.spec.WebMetaData


        }
        final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
        if (warMetaData == null) {
            return;
        }
        final WebMetaData sharedWebMetaData = warMetaData.getSharedWebMetaData();
        if (sharedWebMetaData == null) {
            return;
        }

        // Set cookie-path to "/" for all web applications
        SessionConfigMetaData sessionConfig = sharedWebMetaData.getSessionConfig();
        if (sessionConfig == null) {
            sessionConfig = new SessionConfigMetaData();
            warMetaData.getWebMetaData().setSessionConfig(sessionConfig);
        }
        CookieConfigMetaData cookieConfig = sessionConfig.getCookieConfig();
View Full Code Here


        WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
        assert warMetaData != null;
        List<ResourceRoot> resourceRoots = deploymentUnit.getAttachment(Attachments.RESOURCE_ROOTS);
        assert resourceRoots != null;

        WebMetaData specMetaData = warMetaData.getWebMetaData();
        boolean isComplete = false;
        if (specMetaData != null) {
            if (specMetaData instanceof Web25MetaData) {
                isComplete |= ((Web25MetaData) specMetaData).isMetadataComplete();
            } else if (specMetaData instanceof Web30MetaData) {
                isComplete |= ((Web30MetaData) specMetaData).isMetadataComplete();
            } else {
                // Any web.xml 2.4 or earlier deployment is metadata complete
                isComplete = true;
            }
        }

        // Find all fragments that have been processed by deployers, and place
        // them in a map keyed by location
        LinkedList<String> order = new LinkedList<String>();
        List<WebOrdering> orderings = new ArrayList<WebOrdering>();
        HashSet<String> jarsSet = new HashSet<String>();
        Set<VirtualFile> overlays = new HashSet<VirtualFile>();
        Map<String, VirtualFile> scis = new HashMap<String, VirtualFile>();
        boolean fragmentFound = false;
        Map<String, WebFragmentMetaData> webFragments = warMetaData.getWebFragmentsMetaData();
        for (ResourceRoot resourceRoot : resourceRoots) {
            if (resourceRoot.getRoot().getLowerCaseName().endsWith(".jar")) {
                jarsSet.add(resourceRoot.getRootName());
                // Find overlays
                VirtualFile overlay = resourceRoot.getRoot().getChild("META-INF/resources");
                if (overlay.exists()) {
                    overlays.add(overlay);
                }
                // Find ServletContainerInitializer services
                VirtualFile sci = resourceRoot.getRoot()
                        .getChild("META-INF/services/javax.servlet.ServletContainerInitializer");
                if (sci.exists()) {
                    scis.put(resourceRoot.getRootName(), sci);
                }
            }
        }

        if (!isComplete) {
            HashSet<String> jarsWithoutFragmentsSet = new HashSet<String>();
            jarsWithoutFragmentsSet.addAll(jarsSet);
            for (String jarName : webFragments.keySet()) {
                fragmentFound = true;
                WebFragmentMetaData fragmentMetaData = webFragments.get(jarName);
                webFragments.put(jarName, fragmentMetaData);
                WebOrdering webOrdering = new WebOrdering();
                webOrdering.setName(fragmentMetaData.getName());
                webOrdering.setJar(jarName);
                jarsWithoutFragmentsSet.remove(jarName);
                if (fragmentMetaData.getOrdering() != null) {
                    if (fragmentMetaData.getOrdering().getAfter() != null) {
                        for (OrderingElementMetaData orderingElementMetaData : fragmentMetaData.getOrdering().getAfter()
                                .getOrdering()) {
                            if (orderingElementMetaData.isOthers()) {
                                webOrdering.setAfterOthers(true);
                            } else {
                                webOrdering.addAfter(orderingElementMetaData.getName());
                            }
                        }
                    }
                    if (fragmentMetaData.getOrdering().getBefore() != null) {
                        for (OrderingElementMetaData orderingElementMetaData : fragmentMetaData.getOrdering().getBefore()
                                .getOrdering()) {
                            if (orderingElementMetaData.isOthers()) {
                                webOrdering.setBeforeOthers(true);
                            } else {
                                webOrdering.addBefore(orderingElementMetaData.getName());
                            }
                        }
                    }
                }
                orderings.add(webOrdering);
            }
            // If there is no fragment, still consider it for ordering as a
            // fragment specifying no name and no order
            for (String jarName : jarsWithoutFragmentsSet) {
                WebOrdering ordering = new WebOrdering();
                ordering.setJar(jarName);
                orderings.add(ordering);
            }

        }

        if (!fragmentFound) {
            // Drop the order as there is no fragment in the webapp
            orderings.clear();
        }

        // Generate web fragments parsing order
        AbsoluteOrderingMetaData absoluteOrderingMetaData = null;
        if (!isComplete && specMetaData instanceof Web30MetaData) {
            absoluteOrderingMetaData = ((Web30MetaData) specMetaData).getAbsoluteOrdering();
        }
        if (absoluteOrderingMetaData != null) {
            // Absolute ordering from web.xml, any relative fragment ordering is
            // ignored
            int otherPos = -1;
            int i = 0;
            for (OrderingElementMetaData orderingElementMetaData : absoluteOrderingMetaData.getOrdering()) {
                if (orderingElementMetaData.isOthers()) {
                    if (otherPos >= 0) {
                        throw new DeploymentUnitProcessingException(MESSAGES.invalidMultipleOthers());
                    }
                    otherPos = i;
                } else {
                    boolean found = false;
                    for (WebOrdering ordering : orderings) {
                        if (orderingElementMetaData.getName().equals(ordering.getName())) {
                            order.add(ordering.getJar());
                            jarsSet.remove(ordering.getJar());
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                        throw new DeploymentUnitProcessingException(MESSAGES.invalidAbsoluteOrdering(orderingElementMetaData.getName()));
                }
                i++;
            }
            if (otherPos >= 0) {
                order.addAll(otherPos, jarsSet);
                jarsSet.clear();
            }
        } else if (orderings.size() > 0) {
            // Resolve relative ordering
            try {
                resolveOrder(orderings, order);
            } catch (IllegalStateException e) {
                throw new DeploymentUnitProcessingException(MESSAGES.invalidRelativeOrdering(), e);
            }
            jarsSet.clear();
        } else {
            // No order specified
            order.addAll(jarsSet);
            jarsSet.clear();
            warMetaData.setNoOrder(true);
        }

        Logger log = Logger.getLogger("org.jboss.web");
        if (log.isDebugEnabled()) {
            StringBuilder builder = new StringBuilder();
            builder.append("Resolved order: [ ");
            for (String jar : order) {
                builder.append(jar).append(' ');
            }
            builder.append(']');
            log.debug(builder.toString());
        }

        warMetaData.setOrder(order);
        warMetaData.setOverlays(overlays);
        warMetaData.setScis(scis);

        Map<String, WebMetaData> annotationsMetaData = warMetaData.getAnnotationsMetaData();

        // 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");
        }
        // Augment with meta data from annotations in /WEB-INF/classes
        WebMetaData classesAnnotatedMetaData = annotationsMetaData.get("classes");
        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);
            }
            WebCommonMetaDataMerger.augment(specMetaData, 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 || isComplete) {
                webFragmentMetaData = new WebFragmentMetaData();
                // Add non overriding default distributable flag
                webFragmentMetaData.setDistributable(new EmptyMetaData());
            }
            WebMetaData jarAnnotatedMetaData = annotationsMetaData.get(jar);
            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
                WebCommonMetaDataMerger.augment(webFragmentMetaData, jarAnnotatedMetaData, null, true);
            }
            // Merge fragment meta data according to the conflict rules
            try {
                WebCommonMetaDataMerger.augment(mergedFragmentMetaData, webFragmentMetaData, specMetaData, false);
            } catch (Exception e) {
                throw new DeploymentUnitProcessingException(MESSAGES.invalidWebFragment(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());
            WebMetaData jarAnnotatedMetaData = annotationsMetaData.get(jar);
            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
                WebCommonMetaDataMerger.augment(webFragmentMetaData, jarAnnotatedMetaData, null, true);
            }
View Full Code Here

/*     */   protected void createMetaData(DeploymentUnit unit, String name, String suffix)
/*     */     throws DeploymentException
/*     */   {
/*  87 */     super.createMetaData(unit, name, suffix);
/*     */
/*  89 */     WebMetaData specMetaData = (WebMetaData)unit.getAttachment(WebMetaData.class);
/*  90 */     JBossWebMetaData metaData = (JBossWebMetaData)unit.getAttachment(JBossWebMetaData.class);
/*  91 */     if ((specMetaData == null) && (metaData == null)) {
/*  92 */       return;
/*     */     }
/*     */
View Full Code Here

/*     */   protected void createMetaData(DeploymentUnit unit, String name, String suffix, String key)
/*     */     throws DeploymentException
/*     */   {
/* 140 */     super.createMetaData(unit, name, suffix, key);
/*     */
/* 142 */     WebMetaData wmd = (WebMetaData)unit.getTransientManagedObjects().getAttachment(WebMetaData.class);
/* 143 */     JBossWebMetaData result = (JBossWebMetaData)unit.getTransientManagedObjects().getAttachment(getOutput());
/* 144 */     if ((result == null) && (wmd != null))
/*     */     {
/* 146 */       result = new JBossWebMetaData();
/* 147 */       result.merge(null, wmd);
View Full Code Here

        }
        String configFiles = null;
        //now look for files in the javax.faces.CONFIG_FILES context param
        final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
        if (warMetaData != null) {
            final WebMetaData webMetaData = warMetaData.getWebMetaData();
            if (webMetaData != null) {
                final List<ParamValueMetaData> contextParams = webMetaData.getContextParams();
                if (contextParams != null) {
                    for (final ParamValueMetaData param : contextParams) {
                        if (param.getParamName().equals(CONFIG_FILES)) {
                            configFiles = param.getParamValue();
                            break;
View Full Code Here

   {
      WebFilter webFilter = finder.getAnnotation(element, WebFilter.class);
      if (webFilter == null)
         return null;

      WebMetaData metaData = new WebMetaData();
      FiltersMetaData filters = new FiltersMetaData();
      FilterMetaData filter = new FilterMetaData();
      filter.setFilterClass(element.getName());
      String filterName = null;
      if (webFilter.filterName().length() == 0)
         filterName = element.getName();
      else
         filterName = webFilter.filterName();
      filter.setFilterName(filterName);
      filter.setAsyncSupported(webFilter.asyncSupported());
      if (webFilter.initParams() != null)
      {
         List<ParamValueMetaData> initParams = new ArrayList<ParamValueMetaData>();
         for (WebInitParam webInitParam : webFilter.initParams())
         {
            ParamValueMetaData paramValue = new ParamValueMetaData();
            paramValue.setParamName(webInitParam.name());
            paramValue.setParamValue(webInitParam.value());
            initParams.add(paramValue);
         }
         filter.setInitParam(initParams);
      }
      DescriptionGroupMetaData descriptionGroup =
         ProcessorUtils.getDescriptionGroup(webFilter.description(), webFilter.displayName(),
            webFilter.smallIcon(), webFilter.largeIcon());
      if (descriptionGroup != null)
         filter.setDescriptionGroup(descriptionGroup);
      filters.add(filter);
      metaData.setFilters(filters);
      if (webFilter.urlPatterns() != null || webFilter.value() != null || webFilter.servletNames() != null)
      {
         List<FilterMappingMetaData> filterMappings = new ArrayList<FilterMappingMetaData>();
         FilterMappingMetaData filterMapping = new FilterMappingMetaData();
         filterMapping.setFilterName(filterName);
         if (webFilter.urlPatterns() != null || webFilter.value() != null)
         {
            List<String> urlPatterns = new ArrayList<String>();
            if (webFilter.urlPatterns() != null)
            {
               for (String urlPattern : webFilter.urlPatterns())
               {
                  urlPatterns.add(urlPattern);
               }
            }
            if (webFilter.value() != null)
            {
               for (String urlPattern : webFilter.value())
               {
                  urlPatterns.add(urlPattern);
               }
            }
            filterMapping.setUrlPatterns(urlPatterns);
         }
         if (webFilter.servletNames() != null)
         {
            List<String> servletNames = new ArrayList<String>();
            for (String servletName : webFilter.servletNames())
            {
               servletNames.add(servletName);
            }
            filterMapping.setServletNames(servletNames);
         }
         if (webFilter.dispatcherTypes() != null)
         {
            List<DispatcherType> dispatcherTypes = new ArrayList<DispatcherType>();
            for (javax.servlet.DispatcherType dispatcherType : webFilter.dispatcherTypes())
            {
               dispatcherTypes.add(DispatcherType.valueOf(dispatcherType.toString()));
            }
            filterMapping.setDispatchers(dispatcherTypes);
         }
         filterMappings.add(filterMapping);
         metaData.setFilterMappings(filterMappings);
      }
      return metaData;
   }
View Full Code Here

   {
      WebFilter annotation = finder.getAnnotation(type, WebFilter.class);
      if(annotation == null)
         return;

      WebMetaData filterMetaData = create(type);
      if (metaData.getFilters() == null)
      {
         metaData.setFilters(filterMetaData.getFilters());
      }
      else
      {
         metaData.getFilters().addAll(filterMetaData.getFilters());
      }
      if (metaData.getFilterMappings() == null)
      {
         metaData.setFilterMappings(filterMetaData.getFilterMappings());
      }
      else if (filterMetaData.getFilterMappings() != null)
      {
         metaData.getFilterMappings().addAll(filterMetaData.getFilterMappings());
      }
   }
View Full Code Here

        WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
        assert warMetaData != null;
        List<ResourceRoot> resourceRoots = deploymentUnit.getAttachment(Attachments.RESOURCE_ROOTS);
        assert resourceRoots != null;

        WebMetaData specMetaData = warMetaData.getWebMetaData();
        boolean isComplete = false;
        if (specMetaData != null) {
            if (specMetaData instanceof Web25MetaData) {
                isComplete |= ((Web25MetaData) specMetaData).isMetadataComplete();
            } else if (specMetaData instanceof Web30MetaData) {
                isComplete |= ((Web30MetaData) specMetaData).isMetadataComplete();
            } else {
                // Any web.xml 2.4 or earlier deployment is metadata complete
                isComplete = true;
            }
        }

        // Find all fragments that have been processed by deployers, and place
        // them in a map keyed by location
        LinkedList<String> order = new LinkedList<String>();
        List<WebOrdering> orderings = new ArrayList<WebOrdering>();
        HashSet<String> jarsSet = new HashSet<String>();
        Set<VirtualFile> overlays = new HashSet<VirtualFile>();
        Map<String, VirtualFile> scis = new HashMap<String, VirtualFile>();
        boolean fragmentFound = false;
        Map<String, WebFragmentMetaData> webFragments = warMetaData.getWebFragmentsMetaData();
        for (ResourceRoot resourceRoot : resourceRoots) {
            if (resourceRoot.getRoot().getLowerCaseName().endsWith(".jar")) {
                jarsSet.add(resourceRoot.getRootName());
                // Find overlays
                VirtualFile overlay = resourceRoot.getRoot().getChild("META-INF/resources");
                if (overlay.exists()) {
                    overlays.add(overlay);
                }
                // Find ServletContainerInitializer services
                VirtualFile sci = resourceRoot.getRoot()
                        .getChild("META-INF/services/javax.servlet.ServletContainerInitializer");
                if (sci.exists()) {
                    scis.put(resourceRoot.getRootName(), sci);
                }
            }
        }

        if (!isComplete) {
            HashSet<String> jarsWithoutFragmentsSet = new HashSet<String>();
            jarsWithoutFragmentsSet.addAll(jarsSet);
            for (String jarName : webFragments.keySet()) {
                fragmentFound = true;
                WebFragmentMetaData fragmentMetaData = webFragments.get(jarName);
                webFragments.put(jarName, fragmentMetaData);
                WebOrdering webOrdering = new WebOrdering();
                webOrdering.setName(fragmentMetaData.getName());
                webOrdering.setJar(jarName);
                jarsWithoutFragmentsSet.remove(jarName);
                if (fragmentMetaData.getOrdering() != null) {
                    if (fragmentMetaData.getOrdering().getAfter() != null) {
                        for (OrderingElementMetaData orderingElementMetaData : fragmentMetaData.getOrdering().getAfter()
                                .getOrdering()) {
                            if (orderingElementMetaData.isOthers()) {
                                webOrdering.setAfterOthers(true);
                            } else {
                                webOrdering.addAfter(orderingElementMetaData.getName());
                            }
                        }
                    }
                    if (fragmentMetaData.getOrdering().getBefore() != null) {
                        for (OrderingElementMetaData orderingElementMetaData : fragmentMetaData.getOrdering().getBefore()
                                .getOrdering()) {
                            if (orderingElementMetaData.isOthers()) {
                                webOrdering.setBeforeOthers(true);
                            } else {
                                webOrdering.addBefore(orderingElementMetaData.getName());
                            }
                        }
                    }
                }
                orderings.add(webOrdering);
            }
            // If there is no fragment, still consider it for ordering as a
            // fragment specifying no name and no order
            for (String jarName : jarsWithoutFragmentsSet) {
                WebOrdering ordering = new WebOrdering();
                ordering.setJar(jarName);
                orderings.add(ordering);
            }

        }

        if (!fragmentFound) {
            // Drop the order as there is no fragment in the webapp
            orderings.clear();
        }

        // Generate web fragments parsing order
        AbsoluteOrderingMetaData absoluteOrderingMetaData = null;
        if (!isComplete && specMetaData instanceof Web30MetaData) {
            absoluteOrderingMetaData = ((Web30MetaData) specMetaData).getAbsoluteOrdering();
        }
        if (absoluteOrderingMetaData != null) {
            // Absolute ordering from web.xml, any relative fragment ordering is
            // ignored
            int otherPos = -1;
            int i = 0;
            for (OrderingElementMetaData orderingElementMetaData : absoluteOrderingMetaData.getOrdering()) {
                if (orderingElementMetaData.isOthers()) {
                    if (otherPos >= 0) {
                        throw new DeploymentUnitProcessingException("Duplicate others in absolute ordering");
                    }
                    otherPos = i;
                } else {
                    boolean found = false;
                    for (WebOrdering ordering : orderings) {
                        if (orderingElementMetaData.getName().equals(ordering.getName())) {
                            order.add(ordering.getJar());
                            jarsSet.remove(ordering.getJar());
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                        throw new DeploymentUnitProcessingException("Could not resolve name in absolute ordering: "
                                + orderingElementMetaData.getName());
                }
                i++;
            }
            if (otherPos >= 0) {
                order.addAll(otherPos, jarsSet);
                jarsSet.clear();
            }
        } else if (orderings.size() > 0) {
            // Resolve relative ordering
            try {
                resolveOrder(orderings, order);
            } catch (IllegalStateException e) {
                throw new DeploymentUnitProcessingException("Invalid ordering", e);
            }
            jarsSet.clear();
        } else {
            // No order specified
            order.addAll(jarsSet);
            jarsSet.clear();
            warMetaData.setNoOrder(true);
        }

        Logger log = Logger.getLogger("org.jboss.web");
        if (log.isDebugEnabled()) {
            StringBuilder builder = new StringBuilder();
            builder.append("Resolved order: [ ");
            for (String jar : order) {
                builder.append(jar).append(' ');
            }
            builder.append(']');
            log.debug(builder.toString());
        }

        warMetaData.setOrder(order);
        warMetaData.setOverlays(overlays);
        warMetaData.setScis(scis);

        Map<String, WebMetaData> annotationsMetaData = warMetaData.getAnnotationsMetaData();

        // 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");
        }
        // Augment with meta data from annotations in /WEB-INF/classes
        WebMetaData classesAnnotatedMetaData = annotationsMetaData.get("classes");
        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);
            }
            WebCommonMetaDataMerger.augment(specMetaData, 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());
            }
            WebMetaData jarAnnotatedMetaData = annotationsMetaData.get(jar);
            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
                WebCommonMetaDataMerger.augment(webFragmentMetaData, jarAnnotatedMetaData, null, true);
            }
            // Merge fragment meta data according to the conflict rules
            try {
                WebCommonMetaDataMerger.augment(mergedFragmentMetaData, webFragmentMetaData, specMetaData, false);
            } catch (Exception e) {
                throw new DeploymentUnitProcessingException("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());
            WebMetaData jarAnnotatedMetaData = annotationsMetaData.get(jar);
            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
                WebCommonMetaDataMerger.augment(webFragmentMetaData, jarAnnotatedMetaData, null, true);
            }
View Full Code Here

        assert warMetaData != null;
        DeploymentStructure structure = context.getAttachment(DeploymentStructure.ATTACHMENT_KEY);
        assert structure != null;
        assert structure.getEntries() != null;

        WebMetaData specMetaData = warMetaData.getWebMetaData();
        boolean isComplete = false;
        if (specMetaData != null) {
            if (specMetaData instanceof Web25MetaData) {
                isComplete |= ((Web25MetaData) specMetaData).isMetadataComplete();
            } else if (specMetaData instanceof Web30MetaData) {
                isComplete |= ((Web30MetaData) specMetaData).isMetadataComplete();
            } else {
                // Any web.xml 2.4 or earlier deployment is metadata complete
                isComplete = true;
            }
        }

        // Find all fragments that have been processed by deployers, and place
        // them in a map keyed by location
        LinkedList<String> order = new LinkedList<String>();
        List<WebOrdering> orderings = new ArrayList<WebOrdering>();
        HashSet<String> jarsSet = new HashSet<String>();
        Set<VirtualFile> overlays = new HashSet<VirtualFile>();
        Map<String, VirtualFile> scis = new HashMap<String, VirtualFile>();
        boolean fragmentFound = false;
        Map<String, WebFragmentMetaData> webFragments = warMetaData.getWebFragmentsMetaData();
        for (DeploymentStructure.ClassPathEntry resourceRoot : structure.getEntries()) {
            if (resourceRoot.getRoot().getLowerCaseName().endsWith(".jar")) {
                jarsSet.add(resourceRoot.getName());
                // Find overlays
                VirtualFile overlay = resourceRoot.getRoot().getChild("META-INF/resources");
                if (overlay.exists()) {
                    overlays.add(overlay);
                }
                // Find ServletContainerInitializer services
                VirtualFile sci = resourceRoot.getRoot()
                        .getChild("META-INF/services/javax.servlet.ServletContainerInitializer");
                if (sci.exists()) {
                    scis.put(resourceRoot.getName(), sci);
                }
            }
        }

        if (!isComplete) {
            HashSet<String> jarsWithoutFragmentsSet = new HashSet<String>();
            jarsWithoutFragmentsSet.addAll(jarsSet);
            for (String jarName : webFragments.keySet()) {
                fragmentFound = true;
                WebFragmentMetaData fragmentMetaData = webFragments.get(jarName);
                webFragments.put(jarName, fragmentMetaData);
                WebOrdering webOrdering = new WebOrdering();
                webOrdering.setName(fragmentMetaData.getName());
                webOrdering.setJar(jarName);
                jarsWithoutFragmentsSet.remove(jarName);
                if (fragmentMetaData.getOrdering() != null) {
                    if (fragmentMetaData.getOrdering().getAfter() != null) {
                        for (OrderingElementMetaData orderingElementMetaData : fragmentMetaData.getOrdering().getAfter()
                                .getOrdering()) {
                            if (orderingElementMetaData.isOthers()) {
                                webOrdering.setAfterOthers(true);
                            } else {
                                webOrdering.addAfter(orderingElementMetaData.getName());
                            }
                        }
                    }
                    if (fragmentMetaData.getOrdering().getBefore() != null) {
                        for (OrderingElementMetaData orderingElementMetaData : fragmentMetaData.getOrdering().getBefore()
                                .getOrdering()) {
                            if (orderingElementMetaData.isOthers()) {
                                webOrdering.setBeforeOthers(true);
                            } else {
                                webOrdering.addBefore(orderingElementMetaData.getName());
                            }
                        }
                    }
                }
                orderings.add(webOrdering);
            }
            // If there is no fragment, still consider it for ordering as a
            // fragment specifying no name and no order
            for (String jarName : jarsWithoutFragmentsSet) {
                WebOrdering ordering = new WebOrdering();
                ordering.setJar(jarName);
                orderings.add(ordering);
            }

        }

        if (!fragmentFound) {
            // Drop the order as there is no fragment in the webapp
            orderings.clear();
        }

        // Generate web fragments parsing order
        AbsoluteOrderingMetaData absoluteOrderingMetaData = null;
        if (!isComplete && specMetaData instanceof Web30MetaData) {
            absoluteOrderingMetaData = ((Web30MetaData) specMetaData).getAbsoluteOrdering();
        }
        if (absoluteOrderingMetaData != null) {
            // Absolute ordering from web.xml, any relative fragment ordering is
            // ignored
            int otherPos = -1;
            int i = 0;
            for (OrderingElementMetaData orderingElementMetaData : absoluteOrderingMetaData.getOrdering()) {
                if (orderingElementMetaData.isOthers()) {
                    if (otherPos >= 0) {
                        throw new DeploymentUnitProcessingException("Duplicate others in absolute ordering");
                    }
                    otherPos = i;
                } else {
                    boolean found = false;
                    for (WebOrdering ordering : orderings) {
                        if (orderingElementMetaData.getName().equals(ordering.getName())) {
                            order.add(ordering.getJar());
                            jarsSet.remove(ordering.getJar());
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                        throw new DeploymentUnitProcessingException("Could not resolve name in absolute ordering: "
                                + orderingElementMetaData.getName());
                }
                i++;
            }
            if (otherPos >= 0) {
                order.addAll(otherPos, jarsSet);
                jarsSet.clear();
            }
        } else if (orderings.size() > 0) {
            // Resolve relative ordering
            try {
                resolveOrder(orderings, order);
            } catch (IllegalStateException e) {
                throw new DeploymentUnitProcessingException("Invalid ordering", e);
            }
            jarsSet.clear();
        } else {
            // No order specified
            order.addAll(jarsSet);
            jarsSet.clear();
            warMetaData.setNoOrder(true);
        }

        Logger log = Logger.getLogger("org.jboss.web");
        if (log.isDebugEnabled()) {
            StringBuilder builder = new StringBuilder();
            builder.append("Resolved order: [ ");
            for (String jar : order) {
                builder.append(jar).append(' ');
            }
            builder.append(']');
            log.debug(builder.toString());
        }

        warMetaData.setOrder(order);
        warMetaData.setOverlays(overlays);
        warMetaData.setScis(scis);

        Map<String, WebMetaData> annotationsMetaData = warMetaData.getAnnotationsMetaData();

        // 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");
        }
        // Augment with meta data from annotations in /WEB-INF/classes
        WebMetaData classesAnnotatedMetaData = annotationsMetaData.get("");
        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());
            }
            WebMetaData jarAnnotatedMetaData = annotationsMetaData.get(jar);
            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) {
                throw new DeploymentUnitProcessingException("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());
            WebMetaData jarAnnotatedMetaData = annotationsMetaData.get(jar);
            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);
            }
View Full Code Here

            }
        }
    }

    WebMetaData create() {
        final WebMetaData metadata = new WebMetaData();

        metadata.setServlets(new ServletsMetaData());

        // Add DefaultServlet
        enableStaticResouces(metadata);
        // Add JSPServlet
        enableJsp(metadata);

        // Session config
        final SessionConfigMetaData sessionConfig = new SessionConfigMetaData();
        sessionConfig.setSessionTimeout(30);
        metadata.setSessionConfig(sessionConfig);

        // Mime mappings
        metadata.setMimeMappings(Collections.unmodifiableList(mimeMappings));

        // Welcome files
        metadata.setWelcomeFileList(new WelcomeFileListMetaData());
        metadata.getWelcomeFileList().setWelcomeFiles(Collections.unmodifiableList(welcomeFiles));
        return metadata;
    }
View Full Code Here

TOP

Related Classes of org.jboss.metadata.web.spec.WebMetaData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.