Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   *
   * Copyright (c) 1997-2012 Oracle and/or its affiliates. All rights reserved.
   *
   * The contents of this file are subject to the terms of either the GNU
   * General Public License Version 2 only ("GPL") or the Common Development
   * and Distribution License("CDDL") (collectively, the "License").  You
   * may not use this file except in compliance with the License.  You can
  * obtain a copy of the License at
  * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
  * or packager/legal/LICENSE.txt.  See the License for the specific
  * language governing permissions and limitations under the License.
  *
  * When distributing the software, include this License Header Notice in each
  * file and include the License file at packager/legal/LICENSE.txt.
  *
  * GPL Classpath Exception:
  * Oracle designates this particular file as subject to the "Classpath"
  * exception as provided by Oracle in the GPL Version 2 section of the License
  * file that accompanied this code.
  *
  * Modifications:
  * If applicable, add the following below the License Header, with the fields
  * enclosed by brackets [] replaced by your own identifying information:
  * "Portions Copyright [year] [name of copyright owner]"
  *
  * Contributor(s):
  * If you wish your version of this file to be governed by only the CDDL or
  * only the GPL Version 2, indicate your decision by adding "[Contributor]
  * elects to include this software in this distribution under the [CDDL or GPL
  * Version 2] license."  If you don't indicate a single choice of license, a
  * recipient has the option to distribute your version of this file under
  * either the CDDL, the GPL Version 2 or to extend the choice of license to
  * its licensees as provided above.  However, if you add GPL Version 2 code
  * and therefore, elected the GPL Version 2 license, then the option applies
  * only if the new code is made subject to such option by the copyright
  * holder.
  */
 
 package org.glassfish.web.deployment.node;
 
 
 import java.util.*;

This node is responsible for handling the web-common xml tree

Author(s):
Shing Wai Chan
Version:
 
 public abstract class WebCommonNode<T extends WebBundleDescriptorImplextends AbstractBundleNode<T> {
     public final static String SPEC_VERSION = "3.0";
 
     protected T descriptor;
     private Map<StringVector<String>> servletMappings;

    
Creates new WebBundleNode
 
     protected WebCommonNode()  {
         super();
 
         registerElementHandler(new XMLElement(.), EnvEntryNode.class);                          
         registerElementHandler(new XMLElement(.), EjbReferenceNode.class);     
         JndiEnvRefNode serviceRefNode = .getService(JndiEnvRefNode.class.);
         if (serviceRefNode != null) {
             registerElementHandler(new XMLElement(.), serviceRefNode.getClass(),"addServiceReferenceDescriptor");
         }
                                                             ResourceRefNode.class"addResourceReferenceDescriptor");   
                                                             ResourceEnvRefNode.class"addResourceEnvReferenceDescriptor");               
         registerElementHandler(new XMLElement(.), MessageDestinationRefNode.class"addMessageDestinationReferenceDescriptor");
         registerElementHandler(new XMLElement(.), EntityManagerReferenceNode.class"addEntityManagerReferenceDescriptor");
         registerElementHandler(new XMLElement(.), EntityManagerFactoryReferenceNode.class"addEntityManagerFactoryReferenceDescriptor");
                                                             SecurityRoleNode.class"addRole");            
         registerElementHandler(new XMLElement(.), ServletNode.class);       
         registerElementHandler(new XMLElement(.), ServletMappingNode.class);               
                                                             MimeMappingNode.class"addMimeMapping");
                                                             InitParamNode.class"addContextParameter");        
         registerElementHandler(new XMLElement(.),         
                                                             SecurityConstraintNode.class"addSecurityConstraint");                
                                                            FilterNode.class"addServletFilter");
                                                            FilterMappingNode.class"addServletFilterMapping");            
                                                            ListenerNode.class"addAppListenerDescriptor");                    
                                                            ErrorPageNode.class"addErrorPageDescriptor");            
                                                            LoginConfigNode.class);                    
        // for backward compatibility, from Servlet 2.4 the taglib element is in jsp-config
        registerElementHandler(new XMLElement(.),         
                                                            TagLibNode.class);                      
        registerElementHandler(new XMLElement(.),         
                                                            JspConfigNode.class);                      
                                                            LocaleEncodingMappingListNode.class"addLocaleEncodingMappingListDescriptor");         
                               MessageDestinationNode.class,
                               "addMessageDestination");
        registerElementHandler(new XMLElement(.), LifecycleCallbackNode.class"addPostConstructDescriptor");
        registerElementHandler(new XMLElement(.), LifecycleCallbackNode.class"addPreDestroyDescriptor");
        registerElementHandler(new XMLElement(.), DataSourceDefinitionNode.class"addResourceDescriptor");
        registerElementHandler(new XMLElement(.), ConnectorResourceDefinitionNode.class"addResourceDescriptor");
        registerElementHandler(new XMLElement(.), JMSDestinationDefinitionNode.class"addResourceDescriptor");
        registerElementHandler(new XMLElement(.), MailSessionNode.class"addResourceDescriptor");
    }
    
    
Adds a new DOL descriptor instance to the descriptor instance associated with this XMLNode

Parameters:
newDescriptor the new descriptor
    
    public void addDescriptor(Object  newDescriptor) {
        if (newDescriptor instanceof EjbReference) {            
            .addEjbReferenceDescriptor(
                        (EjbReferencenewDescriptor);
        } else  if (newDescriptor instanceof EnvironmentProperty) {
            DOLUtils.getDefaultLogger().fine("Adding env entry" + newDescriptor);            
           .addEnvironmentProperty((EnvironmentPropertynewDescriptor);
        } else if (newDescriptor instanceof WebComponentDescriptor) {
            DOLUtils.getDefaultLogger().fine("Adding web component" + newDescriptor);            
            .addWebComponentDescriptor((WebComponentDescriptornewDescriptor);
        } else if (newDescriptor instanceof TagLibConfigurationDescriptor) {
            // for backward compatibility with 2.2 and 2.3 specs, we need to be able 
            // to read tag lib under web-app. Starting with 2.4, the tag moved under jsp-config
            DOLUtils.getDefaultLogger().fine("Adding taglib component " + newDescriptor);
            if (.getJspConfigDescriptor()==null) {
                .setJspConfigDescriptor(new JspConfigDescriptorImpl());
            }
        } else if (newDescriptor instanceof JspConfigDescriptorImpl) {
            DOLUtils.getDefaultLogger().fine("Adding JSP Config Descriptor" 
                + newDescriptor);
            if (.getJspConfigDescriptor()!=null) {
                throw new RuntimeException(
                    "Has more than one jsp-config element!");
            }
            .setJspConfigDescriptor(
                (JspConfigDescriptorImpl)newDescriptor);
        } else if (newDescriptor instanceof LoginConfiguration) {
            DOLUtils.getDefaultLogger().fine("Adding Login Config Descriptor"
                 + newDescriptor);
            if (.getLoginConfiguration()!=null) {
                throw new RuntimeException(
                    "Has more than one login-config element!");
            }
            .setLoginConfiguration(
                (LoginConfiguration)newDescriptor);
        } else if (newDescriptor instanceof SessionConfig) {
            if (.getSessionConfig() != null) {
                throw new RuntimeException(
                    "Has more than one session-config element!");
            }
            .setSessionConfig((SessionConfig)newDescriptor);
        } else {
            super.addDescriptor(newDescriptor);
        }
    }       
    

    
receives notiification of the value for a particular tag

Parameters:
element the xml element
value it's associated value
    
    public void setElementValue(XMLElement elementString value) {    
        if (..equals(element.getQName())) {
            .addWelcomeFile(value);
        } else {
            super.setElementValue(elementvalue);
        }
    }       
    
    
add a servelt mapping for one of the servlet of this bundle

Parameters:
servletName the servlet the mapping applies to
urlPattern the url pattern mapping
    void addServletMapping(String servletNameString urlPattern) {
        if (==null) {
             = new HashMap<StringVector<String>>();
        } 
        if (.containsKey(servletName)) {
            ((Vector<String>) .get(servletName)).add(urlPattern);
        } else {
            Vector<Stringmappings = new Vector<String>();
            mappings.add(urlPattern);
            .put(servletNamemappings);
        }
    }
    
    
receives notification of the end of an XML element by the Parser

Parameters:
element the xml tag identification
Returns:
true if this node is done processing the XML sub tree
    public boolean endElement(XMLElement element) {
        if (..equals(element.getQName())) {       
            .setDistributable(true);
            return false;
        } else {
            boolean allDone = super.endElement(element);
            if (allDone && !=null) {
                for (Iterator<Stringkeys = .keySet().iterator(); keys.hasNext();) {
                    String servletName = keys.next();
                    Vector<Stringmappings = .get(servletName);
                    WebComponentDescriptor servlet.getWebComponentByCanonicalName(servletName);
                    if (servlet!=null) {
                        for (Iterator<Stringmapping = mappings.iterator();mapping.hasNext();) {
                            servlet.addUrlPattern(mapping.next());
                        }
                    } else {
                        throw new RuntimeException("There is no web component by the name of " + servletName + " here.");                    
                    } 
                }
            }
            return allDone;
        }
    }

    
write the descriptor class to a DOM tree and return it

Parameters:
parent node for the DOM tree
webBundleDesc descriptor to write
Returns:
the DOM tree top node
    
    public Node writeDescriptor(Node parent
        T webBundleDesc) {
        Node jarNode = super.writeDescriptor(parentwebBundleDesc);             
        if (webBundleDesc.isDistributable()) {
            appendChild(jarNode.);        
        }
        
        // context-param*
        addInitParam(jarNode.webBundleDesc.getContextParametersSet());
        
        // filter*
        FilterNode filterNode = new FilterNode();
        for (Enumeration filters = webBundleDesc.getServletFilters().elements();filters.hasMoreElements();) {
            filterNode.writeDescriptor(jarNode.
                                                     (ServletFilterDescriptorfilters.nextElement());
        }
        
        // filter-mapping*
        FilterMappingNode filterMappingNode = new FilterMappingNode();
        for (Enumeration mappings = webBundleDesc.getServletFilterMappings().elements();
              mappings.hasMoreElements();) {
            filterMappingNode.writeDescriptor(jarNode.
                                                     (ServletFilterMappingDescriptormappings.nextElement());
        }        
        
        // listener*
        Vector appListeners = webBundleDesc.getAppListenerDescriptors();
        if (appListeners!=null && !appListeners.isEmpty()) {
            ListenerNode listenerNode = new ListenerNode();
            for (Enumeration e = appListeners.elements();e.hasMoreElements();) {
                listenerNode.writeDescriptor(jarNode.,
                        (AppListenerDescriptorImple.nextElement());
            }
        }
        
        Set servlets = webBundleDesc.getWebComponentDescriptors();
        if (servlets!=null && !servlets.isEmpty()) {
            // servlet*
            ServletNode servletNode = new ServletNode();
            for (Iterator  eservlets.iterator();e.hasNext();) {
                WebComponentDescriptor aServlet = (WebComponentDescriptore.next();
                servletNode.writeDescriptor(jarNodeaServlet);
            }
            // servlet-mapping*        
            for (Iterator servletsIterator = servlets.iterator(); servletsIterator.hasNext();) {
                WebComponentDescriptor aServlet = (WebComponentDescriptorservletsIterator.next();                
                for (Iterator patterns = aServlet.getUrlPatternsSet().iterator();patterns.hasNext();) {
                    String pattern = (Stringpatterns.next();
                    Node mappingNodeappendChild(jarNode.);
                    appendTextChild(mappingNode.aServlet.getCanonicalName());
                    
                    // If URL Pattern does not start with "/" then
                    // prepend it (for 1.2 Web apps)                    
                    if (webBundleDesc.getSpecVersion().equals("2.2")) {
                        if (!pattern.startsWith("/"
                            && !pattern.startsWith("*.")) {
                            pattern = "/" + pattern;
                        }                    
                    }
                    appendTextChild(mappingNode.pattern);
                }
            }
        }
        
        // mime-mapping*
        MimeMappingNode mimeNode = new MimeMappingNode();
        for (Enumeration e = webBundleDesc.getMimeMappings();e.hasMoreElements();) {
            MimeMappingDescriptor mimeMapping = (MimeMappingDescriptore.nextElement();
            mimeNode.writeDescriptor(jarNode.mimeMapping);
        }
        
        // welcome-file-list?
        Enumeration welcomeFiles = webBundleDesc.getWelcomeFiles();
        if (welcomeFiles.hasMoreElements()) {
            Node welcomeList = appendChild(jarNode.);
            while (welcomeFiles.hasMoreElements()) {
                appendTextChild(welcomeList.,
                                (StringwelcomeFiles.nextElement());
            }
        }
        
        // error-page*
        Enumeration errorPages = webBundleDesc.getErrorPageDescriptors();
        if (errorPages.hasMoreElements()) {
            ErrorPageNode errorPageNode = new ErrorPageNode();
            while (errorPages.hasMoreElements()) {
                errorPageNode.writeDescriptor(jarNode.
                                (ErrorPageDescriptorerrorPages.nextElement());
            }
        }
        
        // jsp-config *
	JspConfigDescriptorImpl jspConf = webBundleDesc.getJspConfigDescriptor();
	if(jspConf != null) {
	    JspConfigNode ln = new JspConfigNode();
	    ln.writeDescriptor(jarNode
				jspConf);
	}
        // security-constraint*
        Enumeration securityConstraints = webBundleDesc.getSecurityConstraints();
        if (securityConstraints.hasMoreElements()) {
            SecurityConstraintNode scNode = new SecurityConstraintNode();
            while (securityConstraints.hasMoreElements()) {
                SecurityConstraintImpl sc = (SecurityConstraintImplsecurityConstraints.nextElement();
                scNode.writeDescriptor(jarNode.sc);
            }
        }
        // login-config ?
        LoginConfigurationImpl lci = (LoginConfigurationImplwebBundleDesc.getLoginConfiguration();
        if (lci!=null) {
            LoginConfigNode lcn = new LoginConfigNode();
            lcn.writeDescriptor(jarNode.lci);
        }
        
        // security-role*
        Enumeration roles = webBundleDesc.getSecurityRoles();
        if (roles.hasMoreElements()) {
            SecurityRoleNode srNode = new SecurityRoleNode();
            while (roles.hasMoreElements()) {
                SecurityRoleDescriptor role = (SecurityRoleDescriptorroles.nextElement();
                srNode.writeDescriptor(jarNode.role);            
            }
        }
        // env-entry*
        writeEnvEntryDescriptors(jarNodewebBundleDesc.getEnvironmentProperties().iterator());
        // ejb-ref * and ejb-local-ref*
        writeEjbReferenceDescriptors(jarNodewebBundleDesc.getEjbReferenceDescriptors().iterator());
        // service-ref*
        // resource-ref*
        writeResourceRefDescriptors(jarNodewebBundleDesc.getResourceReferenceDescriptors().iterator());
                
        // resource-env-ref*
        writeResourceEnvRefDescriptors(jarNodewebBundleDesc.getResourceEnvReferenceDescriptors().iterator());        
        // message-destination-ref*
        
        // persistence-context-ref*
        
        // persistence-unit-ref*
        
        // post-construct
        // pre-destroy
        // all descriptors (includes DSD, MSD, JMSCFD, JMSDD,AOD, CRD)*
        writeResourceDescriptors(jarNodewebBundleDesc.getAllResourcesDescriptors().iterator());
        // message-destination*
           (jarNodewebBundleDesc.getMessageDestinations().iterator());
	if(lemDesc != null) {
	    ln.writeDescriptor(jarNode
				lemDesc);
	}           
        if (webBundleDesc.getSessionConfig() != null) {
            SessionConfigNode scNode = new SessionConfigNode();
            scNode.writeDescriptor(jarNode.,
                    (SessionConfigDescriptor)webBundleDesc.getSessionConfig());            
        }
        return jarNode;
    }
   
    static void addInitParam(Node parentNodeString nodeNameSet initParams) {
        if (!initParams.isEmpty()) {
            InitParamNode initParamNode = new InitParamNode();
            for (Iterator e=initParams.iterator();e.hasNext();) {
                EnvironmentProperty ep = (EnvironmentPropertye.next();
                initParamNode.writeDescriptor(parentNodenodeNameep);
            }
        }    
    }
    
    static void addInitParam(Node parentNodeString nodeNameEnumeration initParams) {
        InitParamNode initParamNode = new InitParamNode();
        while (initParams.hasMoreElements()) {
            EnvironmentProperty ep = (EnvironmentPropertyinitParams.nextElement();
            initParamNode.writeDescriptor(parentNodenodeNameep);
        }
    }
    
    

Returns:
the default spec version level this node complies to
    public String getSpecVersion() {
        return ;
    }
    
New to GrepCode? Check out our FAQ X