1 22 package org.jboss.metadata.web; 23 24 import org.jboss.logging.Logger; 25 import org.jboss.metadata.DDObjectFactory; 26 import org.jboss.metadata.EjbLocalRefMetaData; 27 import org.jboss.metadata.EjbRefMetaData; 28 import org.jboss.metadata.EnvEntryMetaData; 29 import org.jboss.metadata.Listener; 30 import org.jboss.metadata.MessageDestinationMetaData; 31 import org.jboss.metadata.MessageDestinationRefMetaData; 32 import org.jboss.metadata.NameValuePair; 33 import org.jboss.metadata.ResourceEnvRefMetaData; 34 import org.jboss.metadata.ResourceRefMetaData; 35 import org.jboss.metadata.RunAs; 36 import org.jboss.metadata.SecurityRoleMetaData; 37 import org.jboss.metadata.SecurityRoleRefMetaData; 38 import org.jboss.metadata.WebMetaData; 39 import org.jboss.metadata.WebSecurityMetaData; 40 import org.jboss.metadata.WebSecurityMetaData.WebResourceCollection; 41 import org.jboss.xb.binding.UnmarshallingContext; 42 import org.xml.sax.Attributes ; 43 44 50 public class WebMetaDataObjectFactory extends DDObjectFactory 51 { 52 private static Logger log = Logger.getLogger(WebMetaDataObjectFactory.class); 53 54 55 private static final ThreadLocal <WebMetaData> activeMetaData = new ThreadLocal <WebMetaData>(); 56 57 public WebMetaData newRoot(Object root, UnmarshallingContext navigator, 58 String namespaceURI, String localName, Attributes attrs) 59 { 60 WebMetaData metaData = null; 61 if (root != null) 62 metaData = (WebMetaData) root; 63 else 64 metaData = new WebMetaData(); 65 activeMetaData.set(metaData); 66 return metaData; 67 } 68 69 public Object completeRoot(Object root, UnmarshallingContext ctx, 70 String uri, String name) 71 { 72 activeMetaData.set(null); 73 return root; 74 } 75 76 86 public Object newChild(WebMetaData dd, UnmarshallingContext navigator, 87 String namespaceURI, String localName, Attributes attrs) 88 { 89 Object child = null; 90 log.debug("newChild, " + localName); 91 if ((child = newEnvRefGroupChild(localName)) != null) 93 return child; 94 95 else if (localName.equals("distributable")) 96 dd.setDistributable(true); 97 else if(localName.equals("context-param")) 98 { 99 ParamValue pv = new ParamValue(); 100 pv.setType(ParamValue.ParamType.CONTEXT_PARAM); 101 child = pv; 102 } 103 else if(localName.equals("init-param")) 104 { 105 ParamValue pv = new ParamValue(); 106 pv.setType(ParamValue.ParamType.INIT_PARAM); 107 child = pv; 108 } 109 else if (localName.equals("security-role")) 110 child = new SecurityRoleMetaData(); 111 else if (localName.equals("servlet")) 112 child = new Servlet(); 113 else if (localName.equals("replication-config")) 114 child = new ReplicationConfig(); 115 else if (localName.equals("message-destination")) 116 child = new MessageDestinationMetaData(); 117 else if (localName.equals("filter")) 118 { 119 child = new Filter(); 120 } 121 else if (localName.equals("filter-mapping")) 122 { 123 child = new FilterMapping(); 124 } 125 else if (localName.equals("listener")) 126 { 127 child = new Listener(); 128 } 129 else if (localName.equals("servlet-mapping")) 130 { 131 child = new ServletMapping(); 132 } 133 else if (localName.equals("session-config")) 134 { 135 child = new SessionConfig(); 136 } 137 else if (localName.equals("error-page")) 138 { 139 child = new ErrorPage(); 140 } 141 else if (localName.equals("security-role")) 142 { 143 child = new SecurityRoleMetaData(); 144 } 145 else if (localName.equals("security-constraint")) 146 { 147 child = new WebSecurityMetaData(); 148 } 149 else if (localName.equals("login-config")) 150 { 151 child = new LoginConfig(); 152 } 153 else if (localName.equals("message-destination")) 154 { 155 child = new MessageDestinationMetaData(); 156 } 157 161 else if (log.isTraceEnabled()) 162 { 163 log.trace("Ignoring: " + localName); 164 } 165 return child; 166 } 167 168 178 public Object newChild(Servlet servlet, UnmarshallingContext navigator, 179 String namespaceURI, String localName, Attributes attrs) 180 { 181 Object child = null; 182 if (localName.equals("init-param")) 183 { 184 child = new NameValuePair(); 185 } 186 else if (localName.equals("run-as")) 187 { 188 child = new RunAs(); 189 } 190 else if (localName.equals("security-role-ref")) 191 { 192 child = new SecurityRoleRefMetaData(); 193 } 194 return child; 195 } 196 197 public Object newChild(WebSecurityMetaData constraint, 198 UnmarshallingContext navigator, String namespaceURI, String localName, 199 Attributes attrs) 200 { 201 Object child = null; 202 203 if (localName.equals("web-resource-collection")) 204 { 205 child = new WebResourceCollection(); 206 } 207 else if (localName.equals("auth-constraint")) 208 { 209 child = new AuthConstraint(); 210 } 211 else if (localName.equals("user-data-constraint")) 212 { 213 child = new UserDataConstraint(); 214 } 215 216 return child; 217 } 218 219 public void addChild(WebMetaData parent, ParamValue pv, 220 UnmarshallingContext navigator, String namespaceURI, String localName) 221 { 222 if( pv.getType() == ParamValue.ParamType.CONTEXT_PARAM ) 223 parent.addContextParam(pv); 224 else if( pv.getType() == ParamValue.ParamType.INIT_PARAM ) 225 parent.addInitParam(pv); 226 } 227 228 public void addChild(WebMetaData parent, Filter filter, 229 UnmarshallingContext navigator, String namespaceURI, String localName) 230 { 231 parent.addFilter(filter); 232 } 233 234 public void addChild(WebMetaData parent, FilterMapping mapping, 235 UnmarshallingContext navigator, String namespaceURI, String localName) 236 { 237 parent.addFilterMapping(mapping); 238 } 239 240 public void addChild(WebMetaData parent, Listener listener, 241 UnmarshallingContext navigator, String namespaceURI, String localName) 242 { 243 parent.addListener(listener); 244 } 245 246 public void addChild(WebMetaData parent, Servlet servlet, 247 UnmarshallingContext navigator, String namespaceURI, String localName) 248 { 249 parent.addServlet(servlet); 250 } 251 252 public void addChild(WebMetaData parent, ServletMapping mapping, 253 UnmarshallingContext navigator, String namespaceURI, String localName) 254 { 255 parent.addServletMapping(mapping); 256 } 257 258 public void addChild(WebMetaData parent, SessionConfig config, 259 UnmarshallingContext navigator, String namespaceURI, String localName) 260 { 261 parent.addSessionConfig(config); 262 } 263 264 public void addChild(WebMetaData parent, WebSecurityMetaData constraint, 265 UnmarshallingContext navigator, String namespaceURI, String localName) 266 { 267 parent.addSecurityConstraint(constraint); 268 } 269 270 public void addChild(WebMetaData parent, ErrorPage page, 271 UnmarshallingContext navigator, String namespaceURI, String localName) 272 { 273 parent.addErrorPage(page); 274 } 275 276 public void addChild(WebMetaData parent, SecurityRoleMetaData role, 277 UnmarshallingContext navigator, String namespaceURI, String localName) 278 { 279 parent.addSecurityRole(role); 280 } 281 282 public void addChild(WebMetaData parent, EjbLocalRefMetaData ref, 283 UnmarshallingContext navigator, String namespaceURI, String localName) 284 { 285 parent.addEjbLocalRef(ref); 286 } 287 288 public void addChild(WebMetaData parent, EjbRefMetaData ref, 289 UnmarshallingContext navigator, String namespaceURI, String localName) 290 { 291 parent.addEjbRef(ref); 292 } 293 294 public void addChild(WebMetaData parent, EnvEntryMetaData ref, 295 UnmarshallingContext navigator, String namespaceURI, String localName) 296 { 297 parent.addEnvEntry(ref); 298 } 299 300 public void addChild(WebMetaData parent, MessageDestinationRefMetaData ref, 301 UnmarshallingContext navigator, String namespaceURI, String localName) 302 { 303 parent.addMessageDestinationRef(ref); 304 } 305 306 public void addChild(WebMetaData parent, ResourceEnvRefMetaData ref, 307 UnmarshallingContext navigator, String namespaceURI, String localName) 308 { 309 parent.addResourceEnvRef(ref); 310 } 311 312 public void addChild(WebMetaData parent, ResourceRefMetaData ref, 313 UnmarshallingContext navigator, String namespaceURI, String localName) 314 { 315 parent.addResourceRef(ref); 316 } 317 318 public void addChild(WebMetaData parent, LoginConfig config, 319 UnmarshallingContext navigator, String namespaceURI, String localName) 320 { 321 parent.setLoginConfig(config); 322 } 323 324 public void addChild(WebMetaData parent, 325 MessageDestinationMetaData destination, 326 UnmarshallingContext navigator, String namespaceURI, String localName) 327 { 328 parent.addMessageDestination(destination); 329 } 330 331 public void addChild(Filter parent, NameValuePair param, 332 UnmarshallingContext navigator, String namespaceURI, String localName) 333 { 334 parent.addInitParam(param); 335 } 336 337 public void addChild(Servlet parent, NameValuePair param, 338 UnmarshallingContext navigator, String namespaceURI, String localName) 339 { 340 parent.addInitParam(param); 341 } 342 343 public void addChild(Servlet parent, RunAs runAs, 344 UnmarshallingContext navigator, String namespaceURI, String localName) 345 { 346 parent.setRunAs(runAs); 347 } 348 349 public void addChild(Servlet parent, SecurityRoleRefMetaData ref, 350 UnmarshallingContext navigator, String namespaceURI, String localName) 351 { 352 parent.addSecurityRoleRef(ref); 353 } 354 355 public void addChild(WebSecurityMetaData parent, 356 WebResourceCollection collection, UnmarshallingContext navigator, 357 String namespaceURI, String localName) 358 { 359 parent.setWebResources(collection); 360 } 361 362 public void addChild(WebSecurityMetaData parent, AuthConstraint constraint, 363 UnmarshallingContext navigator, String namespaceURI, String localName) 364 { 365 parent.setAuthConstraint(constraint); 366 } 367 public void addChild(WebSecurityMetaData parent, UserDataConstraint constraint, 368 UnmarshallingContext navigator, String namespaceURI, String localName) 369 { 370 parent.setTransportGuarantee(constraint.getTransportGuarantee()); 371 } 372 373 public void addChild(LoginConfig parent, FormLoginConfig config, 374 UnmarshallingContext navigator, String namespaceURI, String localName) 375 { 376 parent.setFormLoginConfig(config); 377 } 378 379 public void setValue(WebMetaData wmd, UnmarshallingContext navigator, 380 String namespaceURI, String localName, String value) 381 { 382 if (localName.equals("description")) 383 { 384 wmd.setDescription(value); 385 } 386 else if(localName.equals("display-name")) 387 { 388 wmd.setDisplayName(value); 389 } 390 } 391 392 public void setValue(ParamValue pv, UnmarshallingContext navigator, 393 String namespaceURI, String localName, String value) 394 { 395 if (localName.equals("description")) 396 { 397 pv.setDescription(value); 398 } 399 else if(localName.equals("param-name")) 400 { 401 pv.setName(value); 402 } 403 else if(localName.equals("param-value")) 404 { 405 pv.setValue(value); 406 } 407 } 408 409 public void setValue(Filter filter, UnmarshallingContext navigator, 410 String namespaceURI, String localName, String value) 411 { 412 if (localName.equals("filter-name")) 413 { 414 filter.setName(value); 415 } 416 else if (localName.equals("filter-class")) 417 { 418 filter.setFilterClass(value); 419 } 420 } 421 422 public void setValue(FilterMapping mapping, UnmarshallingContext navigator, 423 String namespaceURI, String localName, String value) 424 { 425 if (localName.equals("filter-name")) 426 { 427 mapping.setFilterName(value); 428 } 429 else if (localName.equals("url-pattern")) 430 { 431 mapping.setUrlPattern(value); 432 } 433 else if (localName.equals("servlet-name")) 434 { 435 mapping.setServletName(value); 436 } 437 } 438 439 public void setValue(ServletMapping mapping, UnmarshallingContext navigator, 440 String namespaceURI, String localName, String value) 441 { 442 if (localName.equals("servlet-name")) 443 { 444 mapping.setName(value); 445 } 446 else if (localName.equals("url-pattern")) 447 { 448 mapping.setUrlPattern(value); 449 } 450 } 451 452 public void setValue(ErrorPage page, UnmarshallingContext navigator, 453 String namespaceURI, String localName, String value) 454 { 455 if (localName.equals("error-code")) 456 { 457 page.setErrorCode(value); 458 } 459 else if (localName.equals("location")) 460 { 461 page.setLocation(value); 462 } 463 } 464 465 public void setValue(SessionConfig config, UnmarshallingContext navigator, 466 String namespaceURI, String localName, String value) 467 { 468 if (localName.equals("session-timeout")) 469 { 470 config.setSessionTimeout(value); 471 } 472 } 473 474 public void setValue(NameValuePair param, UnmarshallingContext navigator, 475 String namespaceURI, String localName, String value) 476 { 477 if (localName.equals("param-name")) 478 { 479 param.setName(value); 480 } 481 else if (localName.equals("param-value")) 482 { 483 param.setValue(value); 484 } 485 } 486 487 public void setValue(WebResourceCollection collection, 488 UnmarshallingContext navigator, String namespaceURI, String localName, 489 String value) 490 { 491 if (localName.equals("web-resource-name")) 492 { 493 collection.setName(value); 494 } 495 else if (localName.equals("http-pattern")) 496 { 497 collection.addHttpMethod(value); 498 } 499 else if (localName.equals("url-pattern")) 500 { 501 collection.addPattern(value); 502 } 503 } 504 505 public void setValue(AuthConstraint contraint, 506 UnmarshallingContext navigator, String namespaceURI, String localName, 507 String value) 508 { 509 if (localName.equals("role-name")) 510 { 511 contraint.addRoleName(value); 512 } 513 } 514 515 public void setValue(UserDataConstraint contraint, UnmarshallingContext navigator, 516 String namespaceURI, String localName, String value) 517 { 518 if (localName.equals("transport-guarantee")) 519 { 520 contraint.setTransportGuarantee(value); 521 } 522 } 523 public void setValue(LoginConfig config, UnmarshallingContext navigator, 524 String namespaceURI, String localName, String value) 525 { 526 if (localName.equals("auth-method")) 527 { 528 config.setAuthMethod(value); 529 } 530 else if (localName.equals("realm-name")) 531 { 532 config.setRealmName(value); 533 } 534 } 535 536 public void setValue(FormLoginConfig config, UnmarshallingContext navigator, 537 String namespaceURI, String localName, String value) 538 { 539 if (localName.equals("form-login-page")) 540 { 541 config.setLoginPage(value); 542 } 543 else if (localName.equals("form-error-page")) 544 { 545 config.setErrorPage(value); 546 } 547 } 548 549 558 public void setValue(Servlet servlet, UnmarshallingContext navigator, 559 String namespaceURI, String localName, String value) 560 { 561 if (localName.equals("servlet-name")) 562 { 563 servlet.setName(value); 564 } 565 else if (localName.equals("display-name")) 566 { 567 servlet.setDisplayName(value); 568 } 569 else if (localName.equals("servlet-class")) 570 { 571 servlet.setServletClass(value); 572 } 573 else if (localName.equals("run-as-principal")) 574 { 575 servlet.addRunAsPrincipal(value); 576 } 577 else if (localName.equals("jsp-file")) 578 { 579 servlet.setJspFile(value); 580 } 581 else if (localName.equals("load-on-startup")) 582 { 583 int i = Integer.decode(value); 584 servlet.setLoadOnStartup(i); 585 } 586 } 587 } 588 | Popular Tags |