1 22 package org.jboss.resource.deployment; 23 24 import org.jboss.logging.Logger; 25 import org.jboss.resource.metadata.AdminObjectMetaData; 26 import org.jboss.resource.metadata.AuthenticationMechanismMetaData; 27 import org.jboss.resource.metadata.ConfigPropertyMetaData; 28 import org.jboss.resource.metadata.ConnectionDefinitionMetaData; 29 import org.jboss.resource.metadata.ConnectorMetaData; 30 import org.jboss.resource.metadata.DescriptionGroupMetaData; 31 import org.jboss.resource.metadata.DescriptionMetaData; 32 import org.jboss.resource.metadata.LicenseMetaData; 33 import org.jboss.resource.metadata.MessageListenerMetaData; 34 import org.jboss.resource.metadata.RequiredConfigPropertyMetaData; 35 import org.jboss.resource.metadata.SecurityPermissionMetaData; 36 import org.jboss.resource.metadata.TransactionSupportMetaData; 37 import org.jboss.xb.binding.ObjectModelFactory; 38 import org.jboss.xb.binding.UnmarshallingContext; 39 import org.xml.sax.Attributes ; 40 41 47 public class ResourceAdapterObjectModelFactory implements ObjectModelFactory 48 { 49 50 private static final Logger log = Logger.getLogger(ResourceAdapterObjectModelFactory.class); 51 52 53 private boolean trace = log.isTraceEnabled(); 54 55 64 public Object newChild(ConnectorMetaData cmd, UnmarshallingContext navigator, String namespaceURI, String localName, Attributes attrs) 65 { 66 if (trace) 67 log.trace("connector newChild: nuri=" + namespaceURI + " localName=" + localName + " attrs=" + attrs); 68 69 if (localName.equals("vendor-name") || 70 localName.equals("eis-type") || 71 localName.equals("resourceadapter-version") || 72 (localName.equals("resourceadapter") && cmd.getVersion().equals("1.0") == false) || 73 localName.equals("resourceadapter-class") || 74 localName.equals("reauthentication-support")) 75 { 76 return null; 77 } 78 else if (localName.equals("description") || 79 localName.equals("display-name") || 80 localName.equals("small-icon") || 81 localName.equals("large-icon")) 82 { 83 String language = attrs.getValue("xml:lang"); 84 DescriptionGroupMetaData dmd = null; 85 if (language == null) 86 dmd = cmd.getDescription(); 87 else 88 dmd = cmd.getDescription(language); 89 if (dmd == null) 90 dmd = new DescriptionGroupMetaData(language); 91 cmd.addDescription(dmd); 92 return dmd; 93 } 94 else if (localName.equals("icon") && cmd.getVersion().equals("1.0")) 95 { 96 return null; 97 } 98 else if (localName.equals("config-property")) 99 { 100 ConfigPropertyMetaData cpmd = new ConfigPropertyMetaData(); 101 cmd.addProperty(cpmd); 102 return cpmd; 103 } 104 else if (localName.equals("license")) 105 { 106 return cmd.getLicense(); 107 } 108 else if (localName.equals("outbound-resourceadapter")) 109 { 110 return null; 111 } 112 else if (localName.equals("connection-definition") || 113 (localName.equals("resourceadapter") && cmd.getVersion().equals("1.0"))) 114 { 115 ConnectionDefinitionMetaData cdmd = new ConnectionDefinitionMetaData(cmd); 116 cmd.addConnectionDefinition(cdmd); 117 return cdmd; 118 } 119 else if (localName.equals("transaction-support")) 120 { 121 TransactionSupportMetaData tsmd = new TransactionSupportMetaData(); 122 cmd.setTransactionSupport(tsmd); 123 return tsmd; 124 } 125 else if (localName.equals("authentication-mechanism")) 126 { 127 AuthenticationMechanismMetaData ammd = new AuthenticationMechanismMetaData(); 128 cmd.setAuthenticationMechansim(ammd); 129 return ammd; 130 } 131 else if (localName.equals("inbound-resourceadapter") || 132 localName.equals("messageadapter")) 133 { 134 return null; 135 } 136 else if (localName.equals("messagelistener")) 137 { 138 MessageListenerMetaData mlmd = new MessageListenerMetaData(); 139 cmd.addMessageListener(mlmd); 140 return mlmd; 141 } 142 else if (localName.equals("adminobject")) 143 { 144 AdminObjectMetaData aomd = new AdminObjectMetaData(); 145 cmd.addAdminObject(aomd); 146 return aomd; 147 } 148 else if (localName.equals("security-permission")) 149 { 150 SecurityPermissionMetaData spmd = new SecurityPermissionMetaData(); 151 cmd.addSecurityPermission(spmd); 152 return spmd; 153 } 154 else if (localName.equals("spec-version") || 156 localName.equals("version")) 157 { 158 return null; 159 } 160 throw new IllegalArgumentException ("Unknown connector newChild: nuri=" +namespaceURI + " localName=" + localName + " attrs=" + attrs); 161 } 162 163 172 public void setValue(ConnectorMetaData cmd, UnmarshallingContext navigator, String namespaceURI, String localName, String value) 173 { 174 if (trace) 175 log.trace("connector setValue: nuri=" + namespaceURI + " localName=" + localName + " value=" + value); 176 if (localName.equals("connector") || 177 localName.equals("resourceadapter") || 178 localName.equals("outbound-resourceadapter") || 179 localName.equals("inbound-resourceadapter") || 180 localName.equals("messageadapter")) 181 { 182 } 183 else if (localName.equals("vendor-name")) 184 cmd.setVendorName(value); 185 else if (localName.equals("eis-type")) 186 cmd.setEISType(value); 187 else if (localName.equals("resourceadapter-version")) 188 cmd.setRAVersion(value); 189 else if (localName.equals("resourceadapter-class")) 190 cmd.setRAClass(value); 191 else if (localName.equals("reauthentication-support")) 192 cmd.setReauthenticationSupport(Boolean.valueOf(value).booleanValue()); 193 else if (localName.equals("spec-version")) 195 cmd.setVersion(value); 196 else if (localName.equals("version")) 197 cmd.setRAVersion(value); 198 else 199 throw new IllegalArgumentException ("Unknown connector setValue: nuri=" + namespaceURI + " localName=" + localName + " value=" + value); 200 } 201 202 211 public void setValue(DescriptionGroupMetaData dmd, UnmarshallingContext navigator, String namespaceURI, String localName, String value) 212 { 213 if (trace) 214 log.trace("description group setValue: nuri=" + namespaceURI + " localName=" + localName + " value=" + value); 215 if (localName.equals("description")) 216 dmd.setDescription(value); 217 else if (localName.equals("display-name")) 218 dmd.setDisplayName(value); 219 else if (localName.equals("small-icon")) 220 dmd.setSmallIcon(value); 221 else if (localName.equals("large-icon")) 222 dmd.setLargeIcon(value); 223 else 224 throw new IllegalArgumentException ("Unknown description group setValue: nuri=" + namespaceURI + " localName=" + localName + " value=" + value); 225 } 226 227 236 public void setValue(DescriptionMetaData dmd, UnmarshallingContext navigator, String namespaceURI, String localName, String value) 237 { 238 if (trace) 239 log.trace("description setValue: nuri=" + namespaceURI + " localName=" + localName + " value=" + value); 240 if (localName.equals("description")) 241 dmd.setDescription(value); 242 else 243 throw new IllegalArgumentException ("Unknown description setValue: nuri=" + namespaceURI + " localName=" + localName + " value=" + value); 244 } 245 246 255 public Object newChild(ConfigPropertyMetaData cpmd, UnmarshallingContext navigator, String namespaceURI, String localName, Attributes attrs) 256 { 257 if (trace) 258 log.trace("config property newChild: nuri=" + namespaceURI + " localName=" + localName + " attrs=" + attrs); 259 if (localName.equals("config-property-name") || 260 localName.equals("config-property-type") || 261 localName.equals("config-property-value")) 262 { 263 return null; 264 } 265 else if (localName.equals("description")) 266 { 267 String language = attrs.getValue("xml:lang"); 268 DescriptionMetaData dmd = null; 269 if (language == null) 270 dmd = cpmd.getDescription(); 271 else 272 dmd = cpmd.getDescription(language); 273 if (dmd == null) 274 dmd = new DescriptionMetaData(language); 275 cpmd.addDescription(dmd); 276 return dmd; 277 } 278 279 throw new IllegalArgumentException ("Unknown config property newChild: nuri=" +namespaceURI + " localName=" + localName + " attrs=" + attrs); 280 } 281 282 291 public void setValue(ConfigPropertyMetaData cpmd, UnmarshallingContext navigator, String namespaceURI, String localName, String value) 292 { 293 if (trace) 294 log.trace("config property setValue: nuri=" + namespaceURI + " localName=" + localName + " value=" + value); 295 if (localName.equals("config-property")) 296 { 297 } 298 else if (localName.equals("config-property-name")) 299 cpmd.setName(value); 300 else if (localName.equals("config-property-type")) 301 cpmd.setType(value); 302 else if (localName.equals("config-property-value")) 303 cpmd.setValue(value); 304 else 305 throw new IllegalArgumentException ("Unknown config property setValue: nuri=" + namespaceURI + " localName=" + localName + " value=" + value); 306 } 307 308 317 public Object newChild(LicenseMetaData lmd, UnmarshallingContext navigator, String namespaceURI, String localName, Attributes attrs) 318 { 319 if (trace) 320 log.trace("license newChild: nuri=" + namespaceURI + " localName=" + localName + " attrs=" + attrs); 321 if (localName.equals("license")) 322 { 323 return null; 324 } 325 else if (localName.equals("license-required")) 326 { 327 return null; 328 } 329 else if (localName.equals("description")) 330 { 331 String language = attrs.getValue("xml:lang"); 332 DescriptionMetaData dmd = null; 333 if (language == null) 334 dmd = lmd.getDescription(); 335 else 336 dmd = lmd.getDescription(language); 337 if (dmd == null) 338 dmd = new DescriptionMetaData(language); 339 lmd.addDescription(dmd); 340 return dmd; 341 } 342 343 throw new IllegalArgumentException ("Unknown license newChild: nuri=" +namespaceURI + " localName=" + localName + " attrs=" + attrs); 344 } 345 346 355 public void setValue(LicenseMetaData lmd, UnmarshallingContext navigator, String namespaceURI, String localName, String value) 356 { 357 if (trace) 358 log.trace("license setValue: nuri=" + namespaceURI + " localName=" + localName + " value=" + value); 359 if (localName.equals("license")) 360 { 361 } 362 else if (localName.equals("license-required")) 363 lmd.setRequired(Boolean.valueOf(value).booleanValue()); 364 else 365 throw new IllegalArgumentException ("Unknown license setValue: nuri=" + namespaceURI + " localName=" + localName + " value=" + value); 366 } 367 368 377 public Object newChild(ConnectionDefinitionMetaData cdmd, UnmarshallingContext navigator, String namespaceURI, String localName, Attributes attrs) 378 { 379 if (trace) 380 log.trace("connection definition newChild: nuri=" + namespaceURI + " localName=" + localName + " attrs=" + attrs); 381 if (localName.equals("connection-definition") || 382 localName.equals("managedconnectionfactory-class") || 383 localName.equals("connectionfactory-interface") || 384 localName.equals("connectionfactory-impl-class") || 385 localName.equals("connection-interface") || 386 localName.equals("connection-impl-class")) 387 { 388 return null; 389 } 390 else if (localName.equals("config-property")) 391 { 392 ConfigPropertyMetaData cpmd = new ConfigPropertyMetaData(); 393 cdmd.addProperty(cpmd); 394 return cpmd; 395 } 396 else if (localName.equals("transaction-support")) 398 { 399 TransactionSupportMetaData tsmd = new TransactionSupportMetaData(); 400 cdmd.getConnector().setTransactionSupport(tsmd); 401 return tsmd; 402 } 403 else if (localName.equals("authentication-mechanism")) 404 { 405 AuthenticationMechanismMetaData ammd = new AuthenticationMechanismMetaData(); 406 cdmd.getConnector().setAuthenticationMechansim(ammd); 407 return ammd; 408 } 409 else if (localName.equals("security-permission")) 410 { 411 SecurityPermissionMetaData spmd = new SecurityPermissionMetaData(); 412 cdmd.getConnector().addSecurityPermission(spmd); 413 return spmd; 414 } 415 else if (localName.equals("reauthentication-support")) 416 { 417 return null; 418 } 419 420 throw new IllegalArgumentException ("Unknown connection definition newChild: nuri=" +namespaceURI + " localName=" + localName + " attrs=" + attrs); 421 } 422 423 432 public void setValue(ConnectionDefinitionMetaData cdmd, UnmarshallingContext navigator, String namespaceURI, String localName, String value) 433 { 434 if (trace) 435 log.trace("connection definition setValue: nuri=" + namespaceURI + " localName=" + localName + " value=" + value); 436 if (localName.equals("connection-definition")) 437 { 438 } 439 else if (localName.equals("managedconnectionfactory-class")) 440 cdmd.setManagedConnectionFactoryClass(value); 441 else if (localName.equals("connectionfactory-interface")) 442 cdmd.setConnectionFactoryInterfaceClass(value); 443 else if (localName.equals("connectionfactory-impl-class")) 444 cdmd.setConnectionFactoryImplementationClass(value); 445 else if (localName.equals("connection-interface")) 446 cdmd.setConnectionInterfaceClass(value); 447 else if (localName.equals("connection-impl-class")) 448 cdmd.setConnectionImplementationClass(value); 449 else if (localName.equals("reauthentication-support")) 451 cdmd.getConnector().setReauthenticationSupport(Boolean.valueOf(value).booleanValue()); 452 else 453 throw new IllegalArgumentException ("Unknown connection definition setValue: nuri=" + namespaceURI + " localName=" + localName + " value=" + value); 454 } 455 456 465 public Object newChild(TransactionSupportMetaData tsmd, UnmarshallingContext navigator, String namespaceURI, String localName, Attributes attrs) 466 { 467 if (trace) 468 log.trace("transaction support newChild: nuri=" + namespaceURI + " localName=" + localName + " attrs=" + attrs); 469 if (localName.equals("transaction-support")) 470 return null; 471 throw new IllegalArgumentException ("Unknown transaction support newChild: nuri=" +namespaceURI + " localName=" + localName + " attrs=" + attrs); 472 } 473 474 483 public void setValue(TransactionSupportMetaData tsmd, UnmarshallingContext navigator, String namespaceURI, String localName, String value) 484 { 485 if (trace) 486 log.trace("transaction support setValue: nuri=" + namespaceURI + " localName=" + localName + " value=" + value); 487 if (localName.equals("transaction-support") && value.equals("NoTransaction")) 488 tsmd.setTransactionSupport(TransactionSupportMetaData.NoTransaction); 489 else if (localName.equals("transaction-support") && value.equals("LocalTransaction")) 490 tsmd.setTransactionSupport(TransactionSupportMetaData.LocalTransaction); 491 else if (localName.equals("transaction-support") && value.equals("XATransaction")) 492 tsmd.setTransactionSupport(TransactionSupportMetaData.XATransaction); 493 else 494 throw new IllegalArgumentException ("Unknown transaction support setValue: nuri=" + namespaceURI + " localName=" + localName + " value=" + value); 495 } 496 497 506 public Object newChild(AuthenticationMechanismMetaData ammd, UnmarshallingContext navigator, String namespaceURI, String localName, Attributes attrs) 507 { 508 if (trace) 509 log.trace("authentication mechanism newChild: nuri=" + namespaceURI + " localName=" + localName + " attrs=" + attrs); 510 if (localName.equals("authentication-mechanism") || 511 localName.equals("authentication-mechanism-type") || 512 localName.equals("credential-interface")) 513 { 514 return null; 515 } 516 else if (localName.equals("description")) 517 { 518 String language = attrs.getValue("xml:lang"); 519 DescriptionMetaData dmd = null; 520 if (language == null) 521 dmd = ammd.getDescription(); 522 else 523 dmd = ammd.getDescription(language); 524 if (dmd == null) 525 dmd = new DescriptionMetaData(language); 526 ammd.addDescription(dmd); 527 return dmd; 528 } 529 530 throw new IllegalArgumentException ("Unknown authentication mechanism newChild: nuri=" +namespaceURI + " localName=" + localName + " attrs=" + attrs); 531 } 532 533 542 public void setValue(AuthenticationMechanismMetaData ammd, UnmarshallingContext navigator, String namespaceURI, String localName, String value) 543 { 544 if (trace) 545 log.trace("authentication mechanism setValue: nuri=" + namespaceURI + " localName=" + localName + " value=" + value); 546 if (localName.equals("authentication-mechanism")) 547 { 548 } 549 else if (localName.equals("authentication-mechanism-type")) 550 ammd.setAuthenticationMechansimType(value); 551 else if (localName.equals("credential-interface")) 552 ammd.setCredentialInterfaceClass(value); 553 else 554 throw new IllegalArgumentException ("Unknown authentication mechanism setValue: nuri=" + namespaceURI + " localName=" + localName + " value=" + value); 555 } 556 557 566 public Object newChild(MessageListenerMetaData mlmd, UnmarshallingContext navigator, String namespaceURI, String localName, Attributes attrs) 567 { 568 if (trace) 569 log.trace("message listener newChild: nuri=" + namespaceURI + " localName=" + localName + " attrs=" + attrs); 570 if (localName.equals("messagelistener-type") || 571 localName.equals("activationspec") || 572 localName.equals("activationspec-class")) 573 { 574 return null; 575 } 576 else if (localName.equals("required-config-property")) 577 { 578 RequiredConfigPropertyMetaData rcpmd = new RequiredConfigPropertyMetaData(); 579 mlmd.addRequiredConfigProperty(rcpmd); 580 return rcpmd; 581 } 582 583 throw new IllegalArgumentException ("Unknown message listener newChild: nuri=" +namespaceURI + " localName=" + localName + " attrs=" + attrs); 584 } 585 586 595 public void setValue(MessageListenerMetaData mlmd, UnmarshallingContext navigator, String namespaceURI, String localName, String value) 596 { 597 if (trace) 598 log.trace("message listener setValue: nuri=" + namespaceURI + " localName=" + localName + " value=" + value); 599 if (localName.equals("messagelistener") || 600 localName.equals("activationspec")) 601 { 602 } 603 else if (localName.equals("messagelistener-type")) 604 mlmd.setType(value); 605 else if (localName.equals("activationspec-class")) 606 mlmd.setActivationSpecType(value); 607 else 608 throw new IllegalArgumentException ("Unknown mesasge listener setValue: nuri=" + namespaceURI + " localName=" + localName + " value=" + value); 609 } 610 611 620 public Object newChild(AdminObjectMetaData aomd, UnmarshallingContext navigator, String namespaceURI, String localName, Attributes attrs) 621 { 622 if (trace) 623 log.trace("admin object newChild: nuri=" + namespaceURI + " localName=" + localName + " attrs=" + attrs); 624 if (localName.equals("adminobject") || 625 localName.equals("adminobject-interface") || 626 localName.equals("adminobject-class")) 627 { 628 return null; 629 } 630 else if (localName.equals("config-property")) 631 { 632 ConfigPropertyMetaData cpmd = new ConfigPropertyMetaData(); 633 aomd.addProperty(cpmd); 634 return cpmd; 635 } 636 637 throw new IllegalArgumentException ("Unknown admin object newChild: nuri=" +namespaceURI + " localName=" + localName + " attrs=" + attrs); 638 } 639 640 649 public void setValue(AdminObjectMetaData aomd, UnmarshallingContext navigator, String namespaceURI, String localName, String value) 650 { 651 if (trace) 652 log.trace("admin object setValue: nuri=" + namespaceURI + " localName=" + localName + " value=" + value); 653 if (localName.equals("adminobject")) 654 { 655 } 656 else if (localName.equals("adminobject-interface")) 657 aomd.setAdminObjectInterfaceClass(value); 658 else if (localName.equals("adminobject-class")) 659 aomd.setAdminObjectImplementationClass(value); 660 else 661 throw new IllegalArgumentException ("Unknown admin object setValue: nuri=" + namespaceURI + " localName=" + localName + " value=" + value); 662 } 663 664 673 public Object newChild(SecurityPermissionMetaData spmd, UnmarshallingContext navigator, String namespaceURI, String localName, Attributes attrs) 674 { 675 if (trace) 676 log.trace("security permission newChild: nuri=" + namespaceURI + " localName=" + localName + " attrs=" + attrs); 677 if (localName.equals("security-permission") || 678 localName.equals("security-permission-spec")) 679 { 680 return null; 681 } 682 else if (localName.equals("description")) 683 { 684 String language = attrs.getValue("xml:lang"); 685 DescriptionMetaData dmd = null; 686 if (language == null) 687 dmd = spmd.getDescription(); 688 else 689 dmd = spmd.getDescription(language); 690 if (dmd == null) 691 dmd = new DescriptionMetaData(language); 692 spmd.addDescription(dmd); 693 return dmd; 694 } 695 696 throw new IllegalArgumentException ("Unknown security permission newChild: nuri=" +namespaceURI + " localName=" + localName + " attrs=" + attrs); 697 } 698 699 708 public void setValue(SecurityPermissionMetaData spmd, UnmarshallingContext navigator, String namespaceURI, String localName, String value) 709 { 710 if (trace) 711 log.trace("security permission setValue: nuri=" + namespaceURI + " localName=" + localName + " value=" + value); 712 if (localName.equals("security-permission")) 713 { 714 } 715 else if (localName.equals("security-permission-spec")) 716 spmd.setSecurityPermissionSpec(value); 717 else 718 throw new IllegalArgumentException ("Unknown security permission setValue: nuri=" + namespaceURI + " localName=" + localName + " value=" + value); 719 } 720 721 730 public Object newChild(RequiredConfigPropertyMetaData rcpmd, UnmarshallingContext navigator, String namespaceURI, String localName, Attributes attrs) 731 { 732 if (trace) 733 log.trace("required config property newChild: nuri=" + namespaceURI + " localName=" + localName + " attrs=" + attrs); 734 if (localName.equals("config-property-name")) 735 { 736 return null; 737 } 738 else if (localName.equals("description")) 739 { 740 String language = attrs.getValue("xml:lang"); 741 DescriptionMetaData dmd = null; 742 if (language == null) 743 dmd = rcpmd.getDescription(); 744 else 745 dmd = rcpmd.getDescription(language); 746 if (dmd == null) 747 dmd = new DescriptionMetaData(language); 748 rcpmd.addDescription(dmd); 749 return dmd; 750 } 751 752 throw new IllegalArgumentException ("Unknown required config property newChild: nuri=" +namespaceURI + " localName=" + localName + " attrs=" + attrs); 753 } 754 755 764 public void setValue(RequiredConfigPropertyMetaData rcpmd, UnmarshallingContext navigator, String namespaceURI, String localName, String value) 765 { 766 if (trace) 767 log.trace("required config property setValue: nuri=" + namespaceURI + " localName=" + localName + " value=" + value); 768 if (localName.equals("required-config-property")) 769 { 770 } 771 else if (localName.equals("config-property-name")) 772 rcpmd.setName(value); 773 else 774 throw new IllegalArgumentException ("Unknown required config property setValue: nuri=" + namespaceURI + " localName=" + localName + " value=" + value); 775 } 776 777 public Object newRoot(Object root, 778 UnmarshallingContext navigator, 779 String namespaceURI, 780 String localName, 781 Attributes attrs) 782 { 783 if (!localName.equals("connector")) 784 { 785 throw new IllegalStateException ("Unexpected root element: was expecting 'connector' but got '" + localName + "'"); 786 } 787 788 final ConnectorMetaData cmd = new ConnectorMetaData(); 789 String version = attrs.getValue("version"); 790 if (version != null) 791 { 792 cmd.setVersion(version); 793 } 794 return cmd; 795 } 796 797 public Object completeRoot(Object root, UnmarshallingContext ctx, String uri, String name) 798 { 799 return root; 800 } 801 } 802 | Popular Tags |