1 23 package com.sun.enterprise.deployment; 24 25 import java.util.*; 26 import com.sun.enterprise.deployment.*; 27 import com.sun.enterprise.deployment.web.InitializationParameter; 28 import com.sun.enterprise.deployment.web.SecurityRoleReference; 29 30 36 public class WebComponentDescriptor extends Descriptor { 37 38 private WebBundleDescriptor webBundleDescriptor = null; 39 40 public static String BASIC_AUTHENTICATION = "basic"; 41 42 public static String FORM_AUTHENTICATION = "form"; 43 44 public static String SSL_AUTHENTICATION = "ssl"; 45 46 public static String GET = "GET"; 47 48 public static String PUT = "PUT"; 49 50 public static String POST = "POST"; 51 52 public static String DELETE = "DELETE"; 53 54 private Set initializationParameters; 55 private Set urlPatterns; 56 private String canonicalName; 57 private int loadOnStartUp = -1; 58 private Set securityRoleReferences; 59 60 private RunAsIdentityDescriptor runAs; 61 62 65 66 public WebComponentDescriptor() {} 67 68 private Set getInitializationParameterSet() { 69 if (this.initializationParameters == null) { 70 this.initializationParameters = new OrderedSet(); 71 } 72 return this.initializationParameters = new OrderedSet(this.initializationParameters); 73 } 74 75 78 public Enumeration getInitializationParameters() { 79 return (new Vector(this.getInitializationParameterSet())).elements(); 80 } 81 82 85 public InitializationParameter getInitializationParameterByName(String name) { 86 for (Iterator itr = this.getInitializationParameterSet().iterator(); itr.hasNext();) { 87 InitializationParameter next = (InitializationParameter) itr.next(); 88 if (next.getName().equals(name)) { 89 return next; 90 } 91 } 92 return null; 93 } 94 95 98 public void addInitializationParameter(InitializationParameter initializationParameter) { 99 this.getInitializationParameterSet().add(initializationParameter); 100 this.changed(); 101 } 102 105 public void removeInitializationParameter(InitializationParameter initializationParameter) { 106 this.getInitializationParameterSet().remove(initializationParameter); 107 this.changed(); 108 } 109 110 113 public Set getUrlPatternsSet() { 114 if (this.urlPatterns == null) { 115 this.urlPatterns = new OrderedSet(); 116 } 117 return this.urlPatterns; 118 } 119 120 123 public Enumeration getUrlPatterns() { 124 return (new Vector(this.getUrlPatternsSet())).elements(); 125 } 126 127 130 public void addUrlPattern(String urlPattern) { 131 this.getUrlPatternsSet().add(urlPattern); 132 this.changed(); 133 } 134 135 138 public void removeUrlPattern(String urlPattern) { 139 this.getUrlPatternsSet().remove(urlPattern); 140 this.changed(); 141 } 142 143 void setWebBundleDescriptor(WebBundleDescriptor webBundleDescriptor) { 144 this.webBundleDescriptor = webBundleDescriptor; 145 } 146 147 150 public WebBundleDescriptor getWebBundleDescriptor() { 151 return this.webBundleDescriptor; 152 } 153 154 157 public String getCanonicalName() { 158 if (this.canonicalName == null) { 159 this.canonicalName = this.getName(); 160 } 161 return this.canonicalName; 162 } 163 164 167 public void setCanonicalName(String canonicalName) { 168 this.canonicalName = canonicalName; 169 this.changed(); 170 } 171 172 175 public int getLoadOnStartUp() { 176 return this.loadOnStartUp; 177 } 178 179 182 public void setLoadOnStartUp(int loadOnStartUp) { 183 this.loadOnStartUp = loadOnStartUp; 184 this.changed(); 185 } 186 187 190 public void setLoadOnStartUp(String loadOnStartUp) throws NumberFormatException { 191 this.loadOnStartUp = Integer.decode(loadOnStartUp).intValue(); 192 this.changed(); 193 } 194 195 Set getSecurityRoleReferenceSet() { 196 if (this.securityRoleReferences == null) { 197 this.securityRoleReferences = new OrderedSet(); 198 } 199 return this.securityRoleReferences = new OrderedSet(this.securityRoleReferences); 200 } 201 202 205 public Enumeration getSecurityRoleReferences() { 206 return (new Vector(this.getSecurityRoleReferenceSet())).elements(); 207 } 208 209 212 public SecurityRoleReference getSecurityRoleReferenceByName(String roleReferenceName) { 213 for (Enumeration e = this.getSecurityRoleReferences(); e.hasMoreElements();) { 214 SecurityRoleReference nextRR = (SecurityRoleReference) e.nextElement(); 215 if (nextRR.getRolename().equals( roleReferenceName )) { 216 return nextRR; 217 } 218 } 219 return null; 220 } 221 222 225 public void addSecurityRoleReference(SecurityRoleReference securityRoleReference) { 226 this.getSecurityRoleReferenceSet().add(securityRoleReference); 227 this.changed(); 228 } 229 230 233 public void removeSecurityRoleReference(SecurityRoleReference securityRoleReference) { 234 this.getSecurityRoleReferenceSet().remove(securityRoleReference); 235 this.changed(); 236 } 237 238 242 public void setRunAsIdentity(RunAsIdentityDescriptor runAs) { 243 if (this.runAs == null) { 244 this.runAs = runAs; 245 } 246 } 247 248 252 public RunAsIdentityDescriptor getRunAsIdentity() { 253 return this.runAs; 254 } 255 256 public boolean getUsesCallerIdentity() { 257 return (this.runAs==null); 258 } 259 260 public void setUsesCallerIdentity(boolean isCallerID) { 261 if (isCallerID) { 262 this.runAs = null; 263 } else { 264 this.runAs = new RunAsIdentityDescriptor(""); 265 } 266 } 267 268 public Application getApplication() { 269 if (this.getWebBundleDescriptor()!=null) { 270 return this.getWebBundleDescriptor().getApplication(); 271 } 272 return null; 273 } 274 275 private String implFile=""; 276 private boolean isServlet=false; 277 278 284 public void setWebComponentImplementation(String implFile) { 285 if (!isServlet && !implFile.startsWith("/")) { 286 implFile = "/" + implFile; 287 } 288 this.implFile = implFile; 289 changed(); 290 } 291 292 public String getWebComponentImplementation() { 293 return implFile; 294 } 295 296 public boolean isServlet() { 297 return isServlet; 298 } 299 300 public void setServlet(boolean isServlet) { 301 this.isServlet=isServlet; 302 } 303 304 306 307 310 public void print(StringBuffer toStringBuffer) { 311 super.print(toStringBuffer); 312 toStringBuffer.append("WebComponentDescriptor\n"); 313 toStringBuffer.append( "\n initializationParameters ").append(initializationParameters); 314 toStringBuffer.append( "\n urlPatterns ").append(urlPatterns); 315 toStringBuffer.append( "\n canonicalName ").append(canonicalName); 316 toStringBuffer.append( "\n loadOnStartUp ").append(loadOnStartUp); 317 toStringBuffer.append( "\n securityRoleReferences ").append(securityRoleReferences); 318 if (isServlet()) { 319 toStringBuffer.append( "\n servlet className ").append(getWebComponentImplementation()); 320 } else { 321 toStringBuffer.append( "\n jspFileName ").append(getWebComponentImplementation()); 322 } 323 } 324 325 326 public void changed() { 327 if (this.getWebBundleDescriptor() != null) { 328 this.getWebBundleDescriptor().changed(); 329 } else { 330 super.changed(); 331 } 332 } 333 334 public boolean equals(Object other) { 335 if (other instanceof WebComponentDescriptor && 336 this.getCanonicalName().equals((( 337 WebComponentDescriptor)other).getCanonicalName())) { 338 return true; 339 } 340 return false; 341 } 342 343 public void add(WebComponentDescriptor other) { 353 if (! getCanonicalName().equals(other.getCanonicalName())) { 356 return; 357 } 358 if ( (isServlet() && !other.isServlet()) || 361 (!isServlet() && other.isServlet()) ) { 362 return; 363 } 364 365 getUrlPatternsSet().addAll(other.getUrlPatternsSet()); 367 368 371 for (Iterator initParamIter = 372 other.getInitializationParameterSet().iterator(); 373 initParamIter.hasNext();) { 374 InitializationParameter initParam = 375 (InitializationParameter)initParamIter.next(); 376 if (getInitializationParameterByName(initParam.getName()) == null) { 377 getInitializationParameterSet().add(initParam); 378 } 379 } 380 for (Iterator secRoleRefIter = 381 other.getSecurityRoleReferenceSet().iterator(); 382 secRoleRefIter.hasNext();) { 383 SecurityRoleReference secRoleRef = 384 (SecurityRoleReference) secRoleRefIter.next(); 385 if (getSecurityRoleReferenceByName(secRoleRef.getRolename()) 386 == null) { 387 getSecurityRoleReferenceSet().add(secRoleRef); 388 } 389 } 390 391 394 if (getLoadOnStartUp() == -1) { 395 setLoadOnStartUp(other.getLoadOnStartUp()); 396 } 397 if (getRunAsIdentity() == null) { 398 setRunAsIdentity(other.getRunAsIdentity()); 399 } 400 if (getWebComponentImplementation() == null) { 401 setWebComponentImplementation( 402 other.getWebComponentImplementation()); 403 } 404 } 405 } 406 407 | Popular Tags |