1 23 24 package com.sun.enterprise.deployment.node.web; 25 26 import java.util.Map ; 27 import java.util.Enumeration ; 28 import java.util.logging.Level ; 29 import org.w3c.dom.Node ; 30 31 import com.sun.enterprise.deployment.xml.WebTagNames; 32 import com.sun.enterprise.deployment.node.DisplayableComponentNode; 33 import com.sun.enterprise.deployment.node.DescriptorFactory; 34 import com.sun.enterprise.deployment.node.XMLElement; 35 import com.sun.enterprise.deployment.node.SecurityRoleRefNode; 36 import com.sun.enterprise.deployment.node.RunAsNode; 37 38 import com.sun.enterprise.deployment.Descriptor; 39 import com.sun.enterprise.deployment.RoleReference; 40 import com.sun.enterprise.deployment.RunAsIdentityDescriptor; 41 import com.sun.enterprise.deployment.web.EnvironmentEntry; 42 import com.sun.enterprise.deployment.web.InitializationParameter; 43 import com.sun.enterprise.deployment.WebComponentDescriptor; 44 45 import com.sun.enterprise.deployment.util.DOLUtils; 46 47 53 public class ServletNode extends DisplayableComponentNode { 54 55 private final static XMLElement tag = 56 new XMLElement(WebTagNames.SERVLET); 57 58 private WebComponentDescriptor descriptor; 59 60 61 public ServletNode() { 62 super(); 63 registerElementHandler(new XMLElement(WebTagNames.ROLE_REFERENCE), SecurityRoleRefNode.class); 64 registerElementHandler(new XMLElement(WebTagNames.INIT_PARAM), InitParamNode.class); 65 registerElementHandler(new XMLElement(WebTagNames.RUNAS_SPECIFIED_IDENTITY), 66 RunAsNode.class, "setRunAsIdentity"); 67 68 } 69 70 73 protected XMLElement getXMLRootTag() { 74 return tag; 75 } 76 77 80 public Object getDescriptor() { 81 82 if (descriptor==null) { 83 descriptor = (WebComponentDescriptor) DescriptorFactory.getDescriptor(getXMLPath()); 84 } 85 return descriptor; 86 } 87 88 94 public void addDescriptor(Object newDescriptor) { 95 if (newDescriptor instanceof RoleReference) { 96 if (DOLUtils.getDefaultLogger().isLoggable(Level.FINE)) { 97 DOLUtils.getDefaultLogger().fine("Adding security role ref " + newDescriptor); 98 } 99 descriptor.addSecurityRoleReference( 100 (RoleReference) newDescriptor); 101 } else if (newDescriptor instanceof EnvironmentEntry) { 102 if (DOLUtils.getDefaultLogger().isLoggable(Level.FINE)) { 103 DOLUtils.getDefaultLogger().fine("Adding init-param " + newDescriptor); 104 } 105 descriptor.addInitializationParameter( 106 (InitializationParameter) newDescriptor); 107 } else super.addDescriptor(newDescriptor); 108 } 109 110 116 protected Map getDispatchTable() { 117 Map table = super.getDispatchTable(); 119 table.put(WebTagNames.NAME, "setName"); 120 table.put(WebTagNames.SERVLET_NAME, "setCanonicalName"); 121 table.put(WebTagNames.LOAD_ON_STARTUP, "setLoadOnStartUp"); 122 return table; 123 } 124 125 131 public void setElementValue(XMLElement element, String value) { 132 if (WebTagNames.SERVLET_CLASS.equals(element.getQName())) { 133 descriptor.setServlet(true); 134 descriptor.setWebComponentImplementation(value); 135 } else if (WebTagNames.JSP_FILENAME.equals(element.getQName())) { 136 descriptor.setServlet(false); 137 descriptor.setWebComponentImplementation(value); 138 } else { 139 super.setElementValue(element, value); 140 } 141 } 142 143 151 public Node writeDescriptor(Node parent, WebComponentDescriptor descriptor) { 152 153 Node myNode = super.writeDescriptor(parent, descriptor); 154 appendTextChild(myNode, WebTagNames.SERVLET_NAME, descriptor.getCanonicalName()); 155 if (descriptor.isServlet()) { 156 appendTextChild(myNode, WebTagNames.SERVLET_CLASS, descriptor.getWebComponentImplementation()); 157 } else { 158 appendTextChild(myNode, WebTagNames.JSP_FILENAME, descriptor.getWebComponentImplementation()); 159 } 160 161 WebBundleNode.addInitParam(myNode, WebTagNames.INIT_PARAM, descriptor.getInitializationParameters()); 163 164 if (descriptor.getLoadOnStartUp()!=-1) { 165 appendTextChild(myNode, WebTagNames.LOAD_ON_STARTUP, String.valueOf(descriptor.getLoadOnStartUp())); 166 } 167 168 RunAsIdentityDescriptor runAs = descriptor.getRunAsIdentity(); 170 if (runAs!=null) { 171 RunAsNode runAsNode = new RunAsNode(); 172 runAsNode.writeDescriptor(myNode, WebTagNames.RUNAS_SPECIFIED_IDENTITY, runAs); 173 } 174 175 Enumeration roleRefs = descriptor.getSecurityRoleReferences(); 177 SecurityRoleRefNode roleRefNode = new SecurityRoleRefNode(); 178 while (roleRefs.hasMoreElements()) { 179 roleRefNode.writeDescriptor(myNode, WebTagNames.ROLE_REFERENCE, 180 (RoleReference) roleRefs.nextElement()); 181 } 182 183 return myNode; 184 } 185 } 186 | Popular Tags |