00001
00027 package org.objectweb.jonas_web.deployment.api;
00028
00029 import java.util.ArrayList;
00030 import java.util.Collection;
00031 import java.util.HashMap;
00032 import java.util.Hashtable;
00033 import java.util.Iterator;
00034 import java.util.List;
00035 import java.util.Map;
00036 import java.util.Vector;
00037
00038 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException;
00039 import org.objectweb.jonas_lib.deployment.api.EjbLocalRefDesc;
00040 import org.objectweb.jonas_lib.deployment.api.EjbRefDesc;
00041 import org.objectweb.jonas_lib.deployment.api.EnvEntryDesc;
00042 import org.objectweb.jonas_lib.deployment.api.JndiEnvRefsGroupDesc;
00043 import org.objectweb.jonas_lib.deployment.api.MessageDestinationRefDesc;
00044 import org.objectweb.jonas_lib.deployment.api.ResourceEnvRefDesc;
00045 import org.objectweb.jonas_lib.deployment.api.ResourceRefDesc;
00046 import org.objectweb.jonas_lib.deployment.xml.SecurityRole;
00047
00048 import org.objectweb.jonas_web.deployment.xml.JonasWebApp;
00049 import org.objectweb.jonas_web.deployment.xml.Servlet;
00050 import org.objectweb.jonas_web.deployment.xml.ServletMapping;
00051 import org.objectweb.jonas_web.deployment.xml.WebApp;
00052
00053 import org.objectweb.jonas_ws.deployment.api.ServiceRefDesc;
00054
00063 public class WebContainerDeploymentDesc extends JndiEnvRefsGroupDesc {
00064
00069 private String host = null;
00070
00074 private String contextRoot = null;
00075
00080 private String port = null;
00081
00085 private boolean java2DelegationModel = true;
00086
00090 private Map servlets = new HashMap();
00091
00095 private Hashtable servletsUrlMapping = new Hashtable();
00096
00100 private String xmlContent = "";
00101
00105 private String jonasXmlContent = "";
00106
00110 private List securityRoleList;
00111
00115 private SecurityConstraintListDesc securityConstraintListDesc;
00116
00117
00130 public WebContainerDeploymentDesc(String fileName,
00131 ClassLoader classLoader,
00132 WebApp webApp,
00133 JonasWebApp jonasWebApp)
00134 throws DeploymentDescException {
00135
00136 super(classLoader, webApp, jonasWebApp, fileName);
00137
00138
00139
00140 if (jonasWebApp.getHost() != null) {
00141 host = jonasWebApp.getHost();
00142 } else {
00143 host = null;
00144 }
00145
00146
00147 if (jonasWebApp.getContextRoot() != null) {
00148 contextRoot = jonasWebApp.getContextRoot();
00149 } else {
00150 contextRoot = null;
00151 }
00152
00153
00154 if (jonasWebApp.getPort() != null) {
00155 port = jonasWebApp.getPort();
00156 } else {
00157 port = null;
00158 }
00159
00160
00161 String delegationModel = null;
00162 if (jonasWebApp.getJava2DelegationModel() != null) {
00163 delegationModel = jonasWebApp.getJava2DelegationModel();
00164 } else {
00165 delegationModel = "true";
00166 }
00167
00168 if (delegationModel.equalsIgnoreCase("false")) {
00169 java2DelegationModel = false;
00170 } else if (delegationModel.equalsIgnoreCase("true")) {
00171 java2DelegationModel = true;
00172 } else {
00173 throw new WebContainerDeploymentDescException("The java2 delegation model could be 'true' or 'false', not '" + delegationModel + "'.");
00174 }
00175
00176
00177 SecurityRole securityRole = null;
00178 securityRoleList = new ArrayList();
00179 for (Iterator itSecurityRole = webApp.getSecurityRoleList().iterator(); itSecurityRole.hasNext();) {
00180 securityRole = (SecurityRole) itSecurityRole.next();
00181 securityRoleList.add(new SecurityRoleDesc(securityRole));
00182 }
00183
00184
00185
00186 List servletList = webApp.getServletList();
00187 for (Iterator i = servletList.iterator(); i.hasNext();) {
00188 Servlet servlet = (Servlet) i.next();
00189 if (servlet.getServletName() != null) {
00190 ServletDesc servletDesc = new ServletDesc(servlet);
00191 servlets.put(servlet.getServletName(), servletDesc);
00192 }
00193 }
00194
00195
00196
00197 List urlMappings = webApp.getServletMappingList();
00198 for (Iterator i = servletList.iterator(); i.hasNext();) {
00199 Servlet servlet = (Servlet) i.next();
00200 String name = servlet.getServletName().trim();
00201 Vector mappings = new Vector();
00202 for (Iterator m = urlMappings.iterator(); m.hasNext();) {
00203 ServletMapping sm = (ServletMapping) m.next();
00204 if (sm.getServletName().trim().equals(name)) {
00205 String pattern = sm.getUrlPattern().trim();
00206 if (pattern.indexOf('\n') != -1) {
00207 throw new WebContainerDeploymentDescException("There is a '\\n' character inside the url pattern for servlet named '" + sm.getServletName() + "' in the file '" + fileName + "'.");
00208 }
00209 mappings.add(pattern);
00210 }
00211 }
00212 servletsUrlMapping.put(name, mappings);
00213 }
00214
00215
00216 securityConstraintListDesc = new SecurityConstraintListDesc(webApp);
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229 if (webApp.getJspConfigNumber() > 1) {
00230 throw new WebContainerDeploymentDescException("The web-app element must contain only one element jsp-config in file '" + fileName + "'");
00231 }
00232
00233 if (webApp.getLoginConfigNumber() > 1) {
00234 throw new WebContainerDeploymentDescException("The web-app element must contain only one element login-config in file '" + fileName + "'");
00235 }
00236
00237 if (webApp.getSessionConfigNumber() > 1) {
00238 throw new WebContainerDeploymentDescException("The web-app element must contain only one element session-config in file '" + fileName + "'");
00239 }
00240
00241
00242
00243 }
00244
00249 public String getXmlContent() {
00250 return xmlContent;
00251 }
00252
00257 public String getJOnASXmlContent() {
00258 return jonasXmlContent;
00259 }
00260
00265 public void setXmlContent(String xml) {
00266 xmlContent = xml;
00267 }
00268
00273 public void setJOnASXmlContent(String jXml) {
00274 jonasXmlContent = jXml;
00275 }
00276
00277
00282 public String getContextRoot() {
00283 return contextRoot;
00284 }
00285
00290 public boolean getJava2DelegationModel() {
00291 return java2DelegationModel;
00292 }
00293
00298 public String getHost() {
00299 return host;
00300 }
00301
00306 public String getPort() {
00307 return port;
00308 }
00309
00314 public String toString() {
00315 StringBuffer ret = new StringBuffer();
00316
00317
00318 ret.append("\ngetDisplayName()=" + getDisplayName());
00319
00320
00321 ResourceEnvRefDesc[] rer = getResourceEnvRefDesc();
00322 for (int i = 0; i < rer.length; i++) {
00323 ret.append("\ngetResourceEnvRefDesc(" + i + ")=" + rer[i].getClass().getName());
00324 ret.append(rer[i].toString());
00325 }
00326
00327
00328 ResourceRefDesc[] resourceRefDesc = getResourceRefDesc();
00329 for (int i = 0; i < resourceRefDesc.length; i++) {
00330 ret.append("\ngetResourceRefDesc(" + i + ")=" + resourceRefDesc[i].getClass().getName());
00331 ret.append(resourceRefDesc[i].toString());
00332 }
00333
00334
00335 EnvEntryDesc[] envEntries = getEnvEntryDesc();
00336 for (int i = 0; i < envEntries.length; i++) {
00337 ret.append("\ngetEnvEntryDesc(" + i + ")=" + envEntries[i].getClass().getName());
00338 ret.append(envEntries[i].toString());
00339 }
00340
00341
00342 EjbRefDesc[] ejbRefDesc = getEjbRefDesc();
00343 for (int i = 0; i < ejbRefDesc.length; i++) {
00344 ret.append("\ngetEjbRefDesc(" + i + ")=" + ejbRefDesc[i].getClass().getName());
00345 ret.append(ejbRefDesc[i].toString());
00346 }
00347
00348
00349 EjbLocalRefDesc[] ejbLocalRefDesc = getEjbLocalRefDesc();
00350 for (int i = 0; i < ejbLocalRefDesc.length; i++) {
00351 ret.append("\ngetEjbLocalRefDesc(" + i + ")=" + ejbLocalRefDesc[i].getClass().getName());
00352 ret.append(ejbLocalRefDesc[i].toString());
00353 }
00354
00355
00356 ServiceRefDesc[] svcRef = getServiceRefDesc();
00357 for (int i = 0; i < svcRef.length; i++) {
00358 ret.append("\ngetServiceRefDesc(" + i + ")=" + svcRef[i].getClass().getName());
00359 ret.append(svcRef[i].toString());
00360 }
00361
00362
00363 MessageDestinationRefDesc[] mdRefDesc = getMessageDestinationRefDesc();
00364 for (int i = 0; i < mdRefDesc.length; i++) {
00365 ret.append("\ngetMessageDestinationRefDesc(" + i + ")=" + mdRefDesc[i].getClass().getName());
00366 ret.append(mdRefDesc[i].toString());
00367 }
00368
00369
00370 ret.append("\ngetHost()=" + getHost());
00371
00372
00373 ret.append("\ngetContextRoot()=" + getContextRoot());
00374
00375 return ret.toString();
00376 }
00377
00382 public Collection getServletDescList() {
00383 return servlets.values();
00384 }
00385
00390 public String[] getServletsName() {
00391 String[] st = new String[servlets.size()];
00392 return (String[]) servlets.keySet().toArray(st);
00393 }
00394
00400 public String getServletClassname(String servName) {
00401 return ((ServletDesc) servlets.get(servName)).getServletClass();
00402 }
00403
00408 public SecurityConstraintListDesc getSecurityConstraintListDesc() {
00409 return securityConstraintListDesc;
00410 }
00411
00416 public List getSecurityRoleList() {
00417 return securityRoleList;
00418 }
00419
00425 public List getServletMappings(String servName) {
00426 return (List) servletsUrlMapping.get(servName);
00427 }
00428
00429 }