1 23 24 package com.sun.enterprise.deployment.node.runtime.web; 25 26 import java.util.HashMap ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 import java.util.Map ; 30 import java.util.Set ; 31 import org.w3c.dom.Element ; 32 import org.w3c.dom.Node ; 33 import org.xml.sax.Attributes ; 34 35 import com.sun.enterprise.deployment.Application; 36 import com.sun.enterprise.deployment.Descriptor; 37 import com.sun.enterprise.deployment.Group; 38 import com.sun.enterprise.deployment.interfaces.SecurityRoleMapper; 39 import com.sun.enterprise.deployment.JmsDestinationReferenceDescriptor; 40 import com.sun.enterprise.deployment.node.runtime.*; 41 import com.sun.enterprise.deployment.node.runtime.common.EjbRefNode; 42 import com.sun.enterprise.deployment.node.runtime.common.ResourceEnvRefNode; 43 import com.sun.enterprise.deployment.node.runtime.common.ResourceRefNode; 44 import com.sun.enterprise.deployment.node.runtime.common.SecurityRoleMappingNode; 45 import com.sun.enterprise.deployment.node.ServiceReferenceNode; 46 import com.sun.enterprise.deployment.node.XMLElement; 47 import com.sun.enterprise.deployment.ResourcePrincipal; 48 import com.sun.enterprise.deployment.ResourceReferenceDescriptor; 49 import com.sun.enterprise.deployment.Role; 50 import com.sun.enterprise.deployment.runtime.common.DefaultResourcePrincipal; 51 import com.sun.enterprise.deployment.runtime.common.EjbRef; 52 import com.sun.enterprise.deployment.runtime.common.PrincipalNameDescriptor; 53 import com.sun.enterprise.deployment.runtime.common.ResourceEnvRef; 54 import com.sun.enterprise.deployment.runtime.common.ResourceRef; 55 import com.sun.enterprise.deployment.runtime.common.SecurityRoleMapping; 56 import com.sun.enterprise.deployment.runtime.web.Cache; 57 import com.sun.enterprise.deployment.runtime.web.ClassLoader; 58 import com.sun.enterprise.deployment.runtime.web.IdempotentUrlPattern; 59 import com.sun.enterprise.deployment.runtime.web.Servlet; 60 import com.sun.enterprise.deployment.runtime.web.SunWebApp; 61 import com.sun.enterprise.deployment.ServiceReferenceDescriptor; 62 import com.sun.enterprise.deployment.types.EjbReference; 63 import com.sun.enterprise.deployment.util.DOLUtils; 64 import com.sun.enterprise.deployment.WebBundleDescriptor; 65 import com.sun.enterprise.deployment.WebComponentDescriptor; 66 import com.sun.enterprise.deployment.WritableJndiNameEnvironment; 67 import com.sun.enterprise.deployment.xml.ApplicationTagNames; 68 import com.sun.enterprise.deployment.xml.DTDRegistry; 69 import com.sun.enterprise.deployment.xml.RuntimeTagNames; 70 import com.sun.enterprise.deployment.xml.WebServicesTagNames; 71 72 73 80 public class WebBundleRuntimeNode extends RuntimeBundleNode { 81 82 WebBundleDescriptor descriptor=null; 83 84 85 public WebBundleRuntimeNode(WebBundleDescriptor descriptor) { 86 super(descriptor); 87 this.descriptor = descriptor; 88 getDescriptor(); 89 } 90 91 92 public WebBundleRuntimeNode() { 93 super(null); 94 } 95 96 99 protected void Init() { 100 handlers = null; 102 103 registerElementHandler(new XMLElement(RuntimeTagNames.SECURITY_ROLE_MAPPING), 104 SecurityRoleMappingNode.class); 105 registerElementHandler(new XMLElement(RuntimeTagNames.SERVLET), 106 com.sun.enterprise.deployment.node.runtime.ServletNode.class); 107 registerElementHandler(new XMLElement(RuntimeTagNames.IDEMPOTENT_URL_PATTERN), IdempotentUrlPatternNode.class, "addIdempotentUrlPattern"); 108 registerElementHandler(new XMLElement(RuntimeTagNames.SESSION_CONFIG), 109 SessionConfigNode.class, "setSessionConfig"); 110 registerElementHandler(new XMLElement(RuntimeTagNames.RESOURCE_ENV_REFERENCE), 111 ResourceEnvRefNode.class); 112 registerElementHandler(new XMLElement(RuntimeTagNames.MESSAGE_DESTINATION_REFERENCE), 113 MessageDestinationRefNode.class); 114 115 registerElementHandler(new XMLElement(RuntimeTagNames.RESOURCE_REFERENCE), 116 ResourceRefNode.class); 117 registerElementHandler(new XMLElement(RuntimeTagNames.EJB_REFERENCE), 118 EjbRefNode.class); 119 120 registerElementHandler(new XMLElement(RuntimeTagNames.CACHE), 121 CacheNode.class, "setCache"); 122 123 registerElementHandler(new XMLElement(RuntimeTagNames.CLASS_LOADER), 124 ClassLoaderNode.class, "setClassLoader"); 125 126 registerElementHandler(new XMLElement(RuntimeTagNames.JSP_CONFIG), 127 WebPropertyContainerNode.class, "setJspConfig"); 128 129 registerElementHandler(new XMLElement(RuntimeTagNames.LOCALE_CHARSET_INFO), 130 LocaleCharsetInfoNode.class, "setLocaleCharsetInfo"); 131 132 registerElementHandler(new XMLElement(RuntimeTagNames.PROPERTY), 133 WebPropertyContainerNode.class, "addWebProperty"); 134 135 registerElementHandler(new XMLElement(WebServicesTagNames.SERVICE_REF), 136 ServiceRefNode.class); 137 registerElementHandler(new XMLElement(RuntimeTagNames.MESSAGE_DESTINATION), 138 MessageDestinationRuntimeNode.class); 139 registerElementHandler(new XMLElement(WebServicesTagNames.WEB_SERVICE), 140 WebServiceRuntimeNode.class); 141 } 142 143 146 protected XMLElement getXMLRootTag() { 147 return new XMLElement(RuntimeTagNames.S1AS_WEB_RUNTIME_TAG); 148 } 149 150 153 public String getDocType() { 154 return DTDRegistry.SUN_WEBAPP_250_DTD_PUBLIC_ID; 155 } 156 157 160 public String getSystemID() { 161 return DTDRegistry.SUN_WEBAPP_250_DTD_SYSTEM_ID; 162 } 163 164 167 public List <String > getSystemIDs() { 168 return null; 169 } 170 171 177 public static String registerBundle(Map publicIDToDTD) { 178 publicIDToDTD.put(DTDRegistry.SUN_WEBAPP_230_DTD_PUBLIC_ID, DTDRegistry.SUN_WEBAPP_230_DTD_SYSTEM_ID); 179 publicIDToDTD.put(DTDRegistry.SUN_WEBAPP_231_DTD_PUBLIC_ID, DTDRegistry.SUN_WEBAPP_231_DTD_SYSTEM_ID); 180 publicIDToDTD.put(DTDRegistry.SUN_WEBAPP_240_DTD_PUBLIC_ID, DTDRegistry.SUN_WEBAPP_240_DTD_SYSTEM_ID); 181 publicIDToDTD.put(DTDRegistry.SUN_WEBAPP_241_DTD_PUBLIC_ID, DTDRegistry.SUN_WEBAPP_241_DTD_SYSTEM_ID); 182 publicIDToDTD.put(DTDRegistry.SUN_WEBAPP_250_DTD_PUBLIC_ID, DTDRegistry.SUN_WEBAPP_250_DTD_SYSTEM_ID); 183 if (!restrictDTDDeclarations()) { 184 publicIDToDTD.put(DTDRegistry.SUN_WEBAPP_240beta_DTD_PUBLIC_ID, DTDRegistry.SUN_WEBAPP_240beta_DTD_SYSTEM_ID); 185 } 186 187 return RuntimeTagNames.S1AS_WEB_RUNTIME_TAG; 188 } 189 190 193 public Object getDescriptor() { 194 195 return descriptor.getSunDescriptor(); 196 } 197 198 201 public WebBundleDescriptor getWebBundleDescriptor() { 202 return descriptor; 203 } 204 205 211 public void addDescriptor(Object newDescriptor) { 212 if (newDescriptor instanceof EjbRef) { 213 EjbRef ejbRef = (EjbRef) newDescriptor; 214 descriptor.getSunDescriptor().addEjbRef(ejbRef); 215 EjbReference ref = descriptor.getEjbReference(ejbRef.getEjbRefName()); 216 ref.setJndiName(ejbRef.getJndiName()); 217 } else 218 if (newDescriptor instanceof ResourceRef) { 219 ResourceRef resourceRef = (ResourceRef) newDescriptor; 220 descriptor.getSunDescriptor().addResourceRef(resourceRef); 221 ResourceReferenceDescriptor rrd = descriptor.getResourceReferenceByName(resourceRef.getResRefName()); 222 rrd.setJndiName(resourceRef.getJndiName()); 223 DefaultResourcePrincipal drp = resourceRef.getDefaultResourcePrincipal(); 224 if (drp!=null) { 225 ResourcePrincipal rp = new ResourcePrincipal(drp.getName(), drp.getPassword()); 226 rrd.setResourcePrincipal(rp); 227 } 228 } else 229 if (newDescriptor instanceof ResourceEnvRef) { 230 ResourceEnvRef resourceEnvRef = (ResourceEnvRef) newDescriptor; 231 descriptor.getSunDescriptor().addResourceEnvRef(resourceEnvRef); 232 JmsDestinationReferenceDescriptor rrd = descriptor.getJmsDestinationReferenceByName(resourceEnvRef.getResourceEnvRefName()); 233 rrd.setJndiName(resourceEnvRef.getJndiName()); 234 } else 235 if (newDescriptor instanceof WebComponentDescriptor) { 236 WebComponentDescriptor servlet = (WebComponentDescriptor) newDescriptor; 237 Servlet s1descriptor = new Servlet(); 239 s1descriptor.setServletName(servlet.getCanonicalName()); 240 if (servlet.getRunAsIdentity()!=null) { 241 s1descriptor.setPrincipalName(servlet.getRunAsIdentity().getPrincipal()); 242 } 243 descriptor.getSunDescriptor().addServlet(s1descriptor); 244 } else 245 if (newDescriptor instanceof ServiceReferenceDescriptor) { 246 descriptor.addServiceReferenceDescriptor((ServiceReferenceDescriptor) newDescriptor); 247 } else 248 if (newDescriptor instanceof SecurityRoleMapping) { 249 SecurityRoleMapping srm = (SecurityRoleMapping) newDescriptor; 250 descriptor.getSunDescriptor().addSecurityRoleMapping(srm); 251 Application app = descriptor.getApplication(); 253 if (app!=null && app.isVirtual()) { 254 Role role = new Role(srm.getRoleName()); 255 SecurityRoleMapper rm = app.getRoleMapper(); 256 if (rm != null) { 257 List <PrincipalNameDescriptor> principals = srm.getPrincipalNames(); 258 for (int i = 0; i < principals.size(); i++) { 259 rm.assignRole(principals.get(i).getPrincipal(), role); 260 } 261 List <String > groups = srm.getGroupNames(); 262 for (int i = 0; i < groups.size(); i++) { 263 rm.assignRole(new Group(groups.get(i)), role); 264 } 265 } 266 } 267 } 268 else super.addDescriptor(descriptor); 269 } 270 271 public void startElement(XMLElement element, Attributes attributes) { 272 if (element.getQName().equals(RuntimeTagNames.PARAMETER_ENCODING)) { 273 SunWebApp sunWebApp = (SunWebApp)getDescriptor(); 274 sunWebApp.setParameterEncoding(true); 275 for (int i=0; i<attributes.getLength();i++) { 276 if (RuntimeTagNames.DEFAULT_CHARSET.equals( 277 attributes.getQName(i))) { 278 sunWebApp.setAttributeValue(SunWebApp.PARAMETER_ENCODING, SunWebApp.DEFAULT_CHARSET, attributes.getValue(i)); 279 } 280 if (RuntimeTagNames.FORM_HINT_FIELD.equals( 281 attributes.getQName(i))) { 282 sunWebApp.setAttributeValue(SunWebApp.PARAMETER_ENCODING, SunWebApp.FORM_HINT_FIELD, attributes.getValue(i)); 283 } 284 } 285 } else super.startElement(element, attributes); 286 } 287 288 296 protected boolean setAttributeValue(XMLElement elementName, 297 XMLElement attributeName, String value) { 298 SunWebApp sunWebApp = (SunWebApp)getDescriptor(); 299 if (attributeName.getQName().equals(RuntimeTagNames.ERROR_URL)) { 300 sunWebApp.setAttributeValue(sunWebApp.ERROR_URL, value); 301 return true; 302 } 303 if (attributeName.getQName().equals(RuntimeTagNames.HTTPSERVLET_SECURITY_PROVIDER)) { 304 sunWebApp.setAttributeValue(sunWebApp.HTTPSERVLET_SECURITY_PROVIDER, value); 305 return true; 306 } 307 308 return false; 309 } 310 311 312 318 public void setElementValue(XMLElement element, String value) { 319 if (element.getQName().equals(RuntimeTagNames.CONTEXT_ROOT)) { 320 Application app = descriptor.getApplication(); 324 if ( (app == null) || (app!=null && app.isVirtual()) ) { 325 descriptor.setContextRoot(value); 326 } 327 } else 328 super.setElementValue(element, value); 329 } 330 331 338 public Node writeDescriptor(Node parent, Descriptor descriptor) { 339 if (! (descriptor instanceof WebBundleDescriptor)) { 340 throw new IllegalArgumentException (getClass() + " cannot handles descriptors of type " + descriptor.getClass()); 341 } 342 WebBundleDescriptor bundleDescriptor = (WebBundleDescriptor) descriptor; 343 Element web = (Element )super.writeDescriptor(parent, descriptor); 344 345 SunWebApp sunWebApp = bundleDescriptor.getSunDescriptor(); 346 347 appendTextChild(web, RuntimeTagNames.CONTEXT_ROOT, bundleDescriptor.getContextRoot()); 349 350 SecurityRoleMapping[] roleMappings = sunWebApp.getSecurityRoleMapping(); 352 if (roleMappings!=null && roleMappings.length>0) { 353 SecurityRoleMappingNode srmn = new SecurityRoleMappingNode(); 354 for (int i=0;i<roleMappings.length;i++) { 355 srmn.writeDescriptor(web, RuntimeTagNames.SECURITY_ROLE_MAPPING, roleMappings[i]); 356 } 357 } 358 359 Set servlets = bundleDescriptor.getServletDescriptors(); 361 if (servlets!=null) { 362 com.sun.enterprise.deployment.node.runtime.ServletNode node = 363 new com.sun.enterprise.deployment.node.runtime.ServletNode(); 364 for (Iterator itr=servlets.iterator();itr.hasNext();) { 365 WebComponentDescriptor servlet = (WebComponentDescriptor) itr.next(); 366 node.writeDescriptor(web, RuntimeTagNames.SERVLET, servlet); 367 } 368 } 369 370 IdempotentUrlPattern[] patterns = sunWebApp.getIdempotentUrlPatterns(); 372 if (patterns != null && patterns.length > 0) { 373 IdempotentUrlPatternNode node = new IdempotentUrlPatternNode(); 374 for (int i = 0;i < patterns.length; i++) { 375 node.writeDescriptor(web, RuntimeTagNames.IDEMPOTENT_URL_PATTERN, patterns[i]); 376 } 377 } 378 379 if (sunWebApp.getSessionConfig()!=null) { 381 SessionConfigNode scn = new SessionConfigNode(); 382 scn.writeDescriptor(web, RuntimeTagNames.SESSION_CONFIG, sunWebApp.getSessionConfig()); 383 } 384 385 EjbRef[] ejbRefs = sunWebApp.getEjbRef(); 387 if (ejbRefs!=null && ejbRefs.length>0) { 388 EjbRefNode node = new EjbRefNode(); 389 for (int i=0;i<ejbRefs.length;i++) { 390 node.writeDescriptor(web, RuntimeTagNames.EJB_REF, ejbRefs[i]); 391 } 392 } 393 394 ResourceRef[] resourceRefs = sunWebApp.getResourceRef(); 396 if (resourceRefs!=null && resourceRefs.length>0) { 397 ResourceRefNode node = new ResourceRefNode(); 398 for (int i=0;i<resourceRefs.length;i++) { 399 node.writeDescriptor(web, RuntimeTagNames.RESOURCE_REF, resourceRefs[i]); 400 } 401 } 402 403 ResourceEnvRef[] resourceEnvRefs = sunWebApp.getResourceEnvRef(); 405 if (resourceEnvRefs!=null && resourceEnvRefs.length>0) { 406 ResourceEnvRefNode node = new ResourceEnvRefNode(); 407 for (int i=0;i<resourceEnvRefs.length;i++) { 408 node.writeDescriptor(web, RuntimeTagNames.RESOURCE_ENV_REF, resourceEnvRefs[i]); 409 } 410 } 411 412 if (bundleDescriptor.hasServiceReferenceDescriptors()) { 414 ServiceRefNode serviceNode = new ServiceRefNode(); 415 for (Iterator serviceItr=bundleDescriptor.getServiceReferenceDescriptors().iterator(); 416 serviceItr.hasNext();) { 417 ServiceReferenceDescriptor next = (ServiceReferenceDescriptor) serviceItr.next(); 418 serviceNode.writeDescriptor(web, WebServicesTagNames.SERVICE_REF, next); 419 } 420 } 421 422 Cache cache = sunWebApp.getCache(); 424 if (cache!=null) { 425 CacheNode cn = new CacheNode(); 426 cn.writeDescriptor(web, RuntimeTagNames.CACHE, cache); 427 } 428 429 ClassLoader classLoader = sunWebApp.getClassLoader(); 431 if (classLoader!=null) { 432 ClassLoaderNode cln = new ClassLoaderNode(); 433 cln.writeDescriptor(web, RuntimeTagNames.CLASS_LOADER, classLoader); 434 } 435 436 if (sunWebApp.getJspConfig()!=null) { 438 WebPropertyNode propertyNode = new WebPropertyNode(); 439 Node jspConfig = appendChild(web, RuntimeTagNames.JSP_CONFIG); 440 propertyNode.writeDescriptor(jspConfig, RuntimeTagNames.PROPERTY, sunWebApp.getJspConfig().getWebProperty()); 441 } 442 443 if (sunWebApp.getLocaleCharsetInfo()!=null) { 445 LocaleCharsetInfoNode localeNode = new LocaleCharsetInfoNode(); 446 localeNode.writeDescriptor(web, RuntimeTagNames.LOCALE_CHARSET_INFO, 447 sunWebApp.getLocaleCharsetInfo()); 448 } 449 450 if (sunWebApp.isParameterEncoding()) { 452 Element parameter = (Element ) appendChild(web, RuntimeTagNames.PARAMETER_ENCODING); 453 454 if (sunWebApp.getAttributeValue(SunWebApp.PARAMETER_ENCODING, SunWebApp.FORM_HINT_FIELD)!=null) { 455 setAttribute(parameter, RuntimeTagNames.FORM_HINT_FIELD, 456 (String ) sunWebApp.getAttributeValue(SunWebApp.PARAMETER_ENCODING, SunWebApp.FORM_HINT_FIELD)); 457 } 458 459 if (sunWebApp.getAttributeValue(SunWebApp.PARAMETER_ENCODING, SunWebApp.DEFAULT_CHARSET)!=null) { 460 setAttribute(parameter, RuntimeTagNames.DEFAULT_CHARSET, 461 (String ) sunWebApp.getAttributeValue(SunWebApp.PARAMETER_ENCODING, SunWebApp.DEFAULT_CHARSET)); 462 } 463 } 464 465 if (sunWebApp.getWebProperty()!=null) { 467 WebPropertyNode props = new WebPropertyNode(); 468 props.writeDescriptor(web, RuntimeTagNames.PROPERTY, sunWebApp.getWebProperty()); 469 } 470 471 RuntimeDescriptorNode.writeMessageDestinationInfo(web, bundleDescriptor); 473 474 WebServiceRuntimeNode webServiceNode = new WebServiceRuntimeNode(); 476 webServiceNode.writeWebServiceRuntimeInfo(web, bundleDescriptor); 477 478 if (sunWebApp.getAttributeValue(sunWebApp.ERROR_URL) != null) { 480 setAttribute(web, RuntimeTagNames.ERROR_URL, sunWebApp.getAttributeValue(sunWebApp.ERROR_URL)); 481 } 482 483 if (sunWebApp.getAttributeValue(sunWebApp.HTTPSERVLET_SECURITY_PROVIDER) != null) { 485 setAttribute(web, RuntimeTagNames.HTTPSERVLET_SECURITY_PROVIDER, 486 sunWebApp.getAttributeValue(sunWebApp.HTTPSERVLET_SECURITY_PROVIDER)); 487 } 488 489 return web; 490 } 491 } 492 | Popular Tags |