1 26 27 package org.objectweb.jonas_web.deployment.api; 28 29 import java.util.ArrayList ; 30 import java.util.Collection ; 31 import java.util.HashMap ; 32 import java.util.Hashtable ; 33 import java.util.Iterator ; 34 import java.util.List ; 35 import java.util.Map ; 36 import java.util.Vector ; 37 38 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException; 39 import org.objectweb.jonas_lib.deployment.api.EjbLocalRefDesc; 40 import org.objectweb.jonas_lib.deployment.api.EjbRefDesc; 41 import org.objectweb.jonas_lib.deployment.api.EnvEntryDesc; 42 import org.objectweb.jonas_lib.deployment.api.JndiEnvRefsGroupDesc; 43 import org.objectweb.jonas_lib.deployment.api.MessageDestinationRefDesc; 44 import org.objectweb.jonas_lib.deployment.api.ResourceEnvRefDesc; 45 import org.objectweb.jonas_lib.deployment.api.ResourceRefDesc; 46 import org.objectweb.jonas_lib.deployment.xml.SecurityRole; 47 48 import org.objectweb.jonas_web.deployment.xml.JonasWebApp; 49 import org.objectweb.jonas_web.deployment.xml.Servlet; 50 import org.objectweb.jonas_web.deployment.xml.ServletMapping; 51 import org.objectweb.jonas_web.deployment.xml.WebApp; 52 53 import org.objectweb.jonas_ws.deployment.api.ServiceRefDesc; 54 55 63 public class WebContainerDeploymentDesc extends JndiEnvRefsGroupDesc { 64 65 69 private String host = null; 70 71 74 private String contextRoot = null; 75 76 80 private String port = null; 81 82 85 private boolean java2DelegationModel = true; 86 87 90 private Map servlets = new HashMap (); 91 92 95 private Hashtable servletsUrlMapping = new Hashtable (); 96 97 100 private String xmlContent = ""; 101 102 105 private String jonasXmlContent = ""; 106 107 110 private List securityRoleList; 111 112 115 private SecurityConstraintListDesc securityConstraintListDesc; 116 117 118 130 public WebContainerDeploymentDesc(String fileName, 131 ClassLoader classLoader, 132 WebApp webApp, 133 JonasWebApp jonasWebApp) 134 throws DeploymentDescException { 135 136 super(classLoader, webApp, jonasWebApp, fileName); 137 138 139 if (jonasWebApp.getHost() != null) { 141 host = jonasWebApp.getHost(); 142 } else { 143 host = null; 144 } 145 146 if (jonasWebApp.getContextRoot() != null) { 148 contextRoot = jonasWebApp.getContextRoot(); 149 } else { 150 contextRoot = null; 151 } 152 153 if (jonasWebApp.getPort() != null) { 155 port = jonasWebApp.getPort(); 156 } else { 157 port = null; 158 } 159 160 String delegationModel = null; 162 if (jonasWebApp.getJava2DelegationModel() != null) { 163 delegationModel = jonasWebApp.getJava2DelegationModel(); 164 } else { 165 delegationModel = "true"; 166 } 167 168 if (delegationModel.equalsIgnoreCase("false")) { 169 java2DelegationModel = false; 170 } else if (delegationModel.equalsIgnoreCase("true")) { 171 java2DelegationModel = true; 172 } else { 173 throw new WebContainerDeploymentDescException("The java2 delegation model could be 'true' or 'false', not '" + delegationModel + "'."); 174 } 175 176 SecurityRole securityRole = null; 178 securityRoleList = new ArrayList (); 179 for (Iterator itSecurityRole = webApp.getSecurityRoleList().iterator(); itSecurityRole.hasNext();) { 180 securityRole = (SecurityRole) itSecurityRole.next(); 181 securityRoleList.add(new SecurityRoleDesc(securityRole)); 182 } 183 184 185 List servletList = webApp.getServletList(); 187 for (Iterator i = servletList.iterator(); i.hasNext();) { 188 Servlet servlet = (Servlet) i.next(); 189 if (servlet.getServletName() != null) { 190 ServletDesc servletDesc = new ServletDesc(servlet); 191 servlets.put(servlet.getServletName(), servletDesc); 192 } 193 } 194 195 196 List urlMappings = webApp.getServletMappingList(); 198 for (Iterator i = servletList.iterator(); i.hasNext();) { 199 Servlet servlet = (Servlet) i.next(); 200 String name = servlet.getServletName().trim(); 201 Vector mappings = new Vector (); 202 for (Iterator m = urlMappings.iterator(); m.hasNext();) { 203 ServletMapping sm = (ServletMapping) m.next(); 204 if (sm.getServletName().trim().equals(name)) { 205 String pattern = sm.getUrlPattern().trim(); 206 if (pattern.indexOf('\n') != -1) { 207 throw new WebContainerDeploymentDescException("There is a '\\n' character inside the url pattern for servlet named '" + sm.getServletName() + "' in the file '" + fileName + "'."); 208 } 209 mappings.add(pattern); 210 } 211 } 212 servletsUrlMapping.put(name, mappings); 213 } 214 215 securityConstraintListDesc = new SecurityConstraintListDesc(webApp); 217 218 229 if (webApp.getJspConfigNumber() > 1) { 230 throw new WebContainerDeploymentDescException("The web-app element must contain only one element jsp-config in file '" + fileName + "'"); 231 } 232 233 if (webApp.getLoginConfigNumber() > 1) { 234 throw new WebContainerDeploymentDescException("The web-app element must contain only one element login-config in file '" + fileName + "'"); 235 } 236 237 if (webApp.getSessionConfigNumber() > 1) { 238 throw new WebContainerDeploymentDescException("The web-app element must contain only one element session-config in file '" + fileName + "'"); 239 } 240 241 242 243 } 244 245 249 public String getXmlContent() { 250 return xmlContent; 251 } 252 253 257 public String getJOnASXmlContent() { 258 return jonasXmlContent; 259 } 260 261 265 public void setXmlContent(String xml) { 266 xmlContent = xml; 267 } 268 269 273 public void setJOnASXmlContent(String jXml) { 274 jonasXmlContent = jXml; 275 } 276 277 278 282 public String getContextRoot() { 283 return contextRoot; 284 } 285 286 290 public boolean getJava2DelegationModel() { 291 return java2DelegationModel; 292 } 293 294 298 public String getHost() { 299 return host; 300 } 301 302 306 public String getPort() { 307 return port; 308 } 309 310 314 public String toString() { 315 StringBuffer ret = new StringBuffer (); 316 317 ret.append("\ngetDisplayName()=" + getDisplayName()); 319 320 ResourceEnvRefDesc[] rer = getResourceEnvRefDesc(); 322 for (int i = 0; i < rer.length; i++) { 323 ret.append("\ngetResourceEnvRefDesc(" + i + ")=" + rer[i].getClass().getName()); 324 ret.append(rer[i].toString()); 325 } 326 327 ResourceRefDesc[] resourceRefDesc = getResourceRefDesc(); 329 for (int i = 0; i < resourceRefDesc.length; i++) { 330 ret.append("\ngetResourceRefDesc(" + i + ")=" + resourceRefDesc[i].getClass().getName()); 331 ret.append(resourceRefDesc[i].toString()); 332 } 333 334 EnvEntryDesc[] envEntries = getEnvEntryDesc(); 336 for (int i = 0; i < envEntries.length; i++) { 337 ret.append("\ngetEnvEntryDesc(" + i + ")=" + envEntries[i].getClass().getName()); 338 ret.append(envEntries[i].toString()); 339 } 340 341 EjbRefDesc[] ejbRefDesc = getEjbRefDesc(); 343 for (int i = 0; i < ejbRefDesc.length; i++) { 344 ret.append("\ngetEjbRefDesc(" + i + ")=" + ejbRefDesc[i].getClass().getName()); 345 ret.append(ejbRefDesc[i].toString()); 346 } 347 348 EjbLocalRefDesc[] ejbLocalRefDesc = getEjbLocalRefDesc(); 350 for (int i = 0; i < ejbLocalRefDesc.length; i++) { 351 ret.append("\ngetEjbLocalRefDesc(" + i + ")=" + ejbLocalRefDesc[i].getClass().getName()); 352 ret.append(ejbLocalRefDesc[i].toString()); 353 } 354 355 ServiceRefDesc[] svcRef = getServiceRefDesc(); 357 for (int i = 0; i < svcRef.length; i++) { 358 ret.append("\ngetServiceRefDesc(" + i + ")=" + svcRef[i].getClass().getName()); 359 ret.append(svcRef[i].toString()); 360 } 361 362 MessageDestinationRefDesc[] mdRefDesc = getMessageDestinationRefDesc(); 364 for (int i = 0; i < mdRefDesc.length; i++) { 365 ret.append("\ngetMessageDestinationRefDesc(" + i + ")=" + mdRefDesc[i].getClass().getName()); 366 ret.append(mdRefDesc[i].toString()); 367 } 368 369 ret.append("\ngetHost()=" + getHost()); 371 372 ret.append("\ngetContextRoot()=" + getContextRoot()); 374 375 return ret.toString(); 376 } 377 378 382 public Collection getServletDescList() { 383 return servlets.values(); 384 } 385 386 390 public String [] getServletsName() { 391 String [] st = new String [servlets.size()]; 392 return (String []) servlets.keySet().toArray(st); 393 } 394 395 400 public String getServletClassname(String servName) { 401 return ((ServletDesc) servlets.get(servName)).getServletClass(); 402 } 403 404 408 public SecurityConstraintListDesc getSecurityConstraintListDesc() { 409 return securityConstraintListDesc; 410 } 411 412 416 public List getSecurityRoleList() { 417 return securityRoleList; 418 } 419 420 425 public List getServletMappings(String servName) { 426 return (List ) servletsUrlMapping.get(servName); 427 } 428 429 } 430 | Popular Tags |