FileDocCategorySizeDatePackage
ServletNode.javaAPI DocGlassfish v2 API8359Fri May 04 22:31:48 BST 2007com.sun.enterprise.deployment.node.web

ServletNode

public class ServletNode extends com.sun.enterprise.deployment.node.DisplayableComponentNode
This node is responsible for handling the servlet xml sub tree
author
Jerome Dochez
version

Fields Summary
private static final com.sun.enterprise.deployment.node.XMLElement
tag
private com.sun.enterprise.deployment.WebComponentDescriptor
descriptor
Constructors Summary
public ServletNode()
Creates new ServletNode

    
        
      
        super();
        registerElementHandler(new XMLElement(WebTagNames.ROLE_REFERENCE), SecurityRoleRefNode.class);        
        registerElementHandler(new XMLElement(WebTagNames.INIT_PARAM), InitParamNode.class);                
        registerElementHandler(new XMLElement(WebTagNames.RUNAS_SPECIFIED_IDENTITY), 
                                                             RunAsNode.class, "setRunAsIdentity");                
        
    
Methods Summary
public voidaddDescriptor(java.lang.Object newDescriptor)
Adds a new DOL descriptor instance to the descriptor instance associated with this XMLNode

param
descriptor the new descriptor

       
        if (newDescriptor instanceof RoleReference) {  
            if (DOLUtils.getDefaultLogger().isLoggable(Level.FINE)) {            
                DOLUtils.getDefaultLogger().fine("Adding security role ref " + newDescriptor);
            }
            descriptor.addSecurityRoleReference(
                        (RoleReference) newDescriptor);    
        } else if (newDescriptor instanceof EnvironmentEntry) {            
            if (DOLUtils.getDefaultLogger().isLoggable(Level.FINE)) {            
                DOLUtils.getDefaultLogger().fine("Adding init-param " + newDescriptor);
            }
            descriptor.addInitializationParameter(
                        (InitializationParameter) newDescriptor);    
        } else super.addDescriptor(newDescriptor);
    
public java.lang.ObjectgetDescriptor()

return
the descriptor instance to associate with this XMLNode

        
        if (descriptor==null) {
            descriptor = (WebComponentDescriptor) DescriptorFactory.getDescriptor(getXMLPath());
        }
        return descriptor;
    
protected java.util.MapgetDispatchTable()
all sub-implementation of this class can use a dispatch table to map xml element to method name on the descriptor class for setting the element value.

return
the map with the element name as a key, the setter method as a value

        // no need to be synchronized for now
        Map table = super.getDispatchTable();
        table.put(WebTagNames.NAME, "setName");        
        table.put(WebTagNames.SERVLET_NAME, "setCanonicalName");
        table.put(WebTagNames.LOAD_ON_STARTUP, "setLoadOnStartUp");
        return table;
    
protected com.sun.enterprise.deployment.node.XMLElementgetXMLRootTag()

return
the XML tag associated with this XMLNode

        return tag;
    
public voidsetElementValue(com.sun.enterprise.deployment.node.XMLElement element, java.lang.String value)
receives notiification of the value for a particular tag

param
element the xml element
param
value it's associated value

        if (WebTagNames.SERVLET_CLASS.equals(element.getQName())) {
            descriptor.setServlet(true);            
            descriptor.setWebComponentImplementation(value);
        } else if (WebTagNames.JSP_FILENAME.equals(element.getQName())) {
            descriptor.setServlet(false);
            descriptor.setWebComponentImplementation(value);
        } else {
            super.setElementValue(element, value);
        }
    
public org.w3c.dom.NodewriteDescriptor(org.w3c.dom.Node parent, com.sun.enterprise.deployment.WebComponentDescriptor descriptor)
write the descriptor class to a DOM tree and return it

param
parent node in the DOM tree
param
node name for the root element of this xml fragment
param
the descriptor to write
return
the DOM tree top node

    

        Node myNode = super.writeDescriptor(parent, descriptor);
        appendTextChild(myNode, WebTagNames.SERVLET_NAME, descriptor.getCanonicalName());         
        if (descriptor.isServlet()) {
            appendTextChild(myNode, WebTagNames.SERVLET_CLASS, descriptor.getWebComponentImplementation());
        } else {
            appendTextChild(myNode, WebTagNames.JSP_FILENAME, descriptor.getWebComponentImplementation());
        }
        
        // init-param*
        WebBundleNode.addInitParam(myNode, WebTagNames.INIT_PARAM, descriptor.getInitializationParameters());
        
        if (descriptor.getLoadOnStartUp()!=-1) {
            appendTextChild(myNode, WebTagNames.LOAD_ON_STARTUP, String.valueOf(descriptor.getLoadOnStartUp()));
        }
        
        // run-as
        RunAsIdentityDescriptor runAs = descriptor.getRunAsIdentity();
        if (runAs!=null) {
            RunAsNode runAsNode = new RunAsNode();
            runAsNode.writeDescriptor(myNode, WebTagNames.RUNAS_SPECIFIED_IDENTITY, runAs);
        }
        
        // sercurity-role-ref*
        Enumeration roleRefs = descriptor.getSecurityRoleReferences();
        SecurityRoleRefNode roleRefNode = new SecurityRoleRefNode();
        while (roleRefs.hasMoreElements()) {
            roleRefNode.writeDescriptor(myNode, WebTagNames.ROLE_REFERENCE, 
                            (RoleReference) roleRefs.nextElement());            
        }
        
        return myNode;