1 22 package org.jboss.metadata; 23 24 import org.jboss.deployment.DeploymentException; 25 import org.jboss.mx.util.MBeanServerLocator; 26 import org.w3c.dom.DocumentType ; 27 import org.w3c.dom.Element ; 28 29 import javax.management.MBeanServer ; 30 import javax.management.ObjectName ; 31 import java.net.URL ; 32 import java.net.URLClassLoader ; 33 import java.util.ArrayList ; 34 import java.util.HashMap ; 35 import java.util.HashSet ; 36 import java.util.Iterator ; 37 import java.util.Map ; 38 import java.util.Set ; 39 40 52 public class ApplicationMetaData 53 extends MetaData 54 { 55 public static final int EJB_1x = 1; 56 public static final int EJB_2x = 2; 57 private String description; 58 private String displayName; 59 60 private URL url; 61 62 protected int ejbVersion; 63 protected int ejbMinorVersion; 64 65 private ArrayList beans = new ArrayList (); 66 67 private HashMap wsdlPublishLocationMap = new HashMap (); 68 69 private boolean webServiceDeployment; 70 71 private String configName; 72 73 private String configFile; 74 private String clientJar; 75 76 private ArrayList <RelationMetaData> relationships = new ArrayList <RelationMetaData>(); 77 78 private AssemblyDescriptorMetaData assemblyDescriptor = new AssemblyDescriptorMetaData(); 79 80 private HashMap configurations = new HashMap (); 81 82 private HashMap invokerBindings = new HashMap (); 83 84 private HashMap resources = new HashMap (); 85 private HashMap plugins = new HashMap (); 86 87 private String jmxName; 88 89 private String securityDomain; 90 91 private String unauthenticatedPrincipal; 92 93 private String webServiceContextRoot; 94 95 private boolean enforceEjbRestrictions; 96 97 private boolean excludeMissingMethods = true; 98 99 private boolean exceptionRollback = false; 100 101 private String jaccContextID; 102 103 104 105 private URLClassLoader resourceCl; 106 107 public ApplicationMetaData() 108 { 109 } 110 111 112 public URLClassLoader getResourceCl() 113 { 114 return resourceCl; 115 } 116 117 118 public void setResourceClassLoader(URLClassLoader resourceCl) 119 { 120 this.resourceCl = resourceCl; 121 } 122 123 public String getDescription() 124 { 125 return description; 126 } 127 128 public void setDescription(String description) 129 { 130 this.description = description; 131 } 132 133 public String getDisplayName() 134 { 135 return displayName; 136 } 137 138 public void setDisplayName(String displayName) 139 { 140 this.displayName = displayName; 141 } 142 143 public URL getUrl() 144 { 145 return url; 146 } 147 148 public void setUrl(URL u) 149 { 150 url = u; 151 } 152 153 public boolean isEJB1x() 154 { 155 return ejbVersion == 1; 156 } 157 158 public boolean isEJB2x() 159 { 160 return ejbVersion == 2; 161 } 162 163 public boolean isEJB21() 164 { 165 return ejbVersion == 2 && ejbMinorVersion == 1; 166 } 167 168 public int getEjbMinorVersion() 169 { 170 return ejbMinorVersion; 171 } 172 173 public void setEjbMinorVersion(int ejbMinorVersion) 174 { 175 this.ejbMinorVersion = ejbMinorVersion; 176 } 177 178 public int getEjbVersion() 179 { 180 return ejbVersion; 181 } 182 183 public void setEjbVersion(int ejbVersion) 184 { 185 this.ejbVersion = ejbVersion; 186 } 187 188 public Iterator getEnterpriseBeans() 189 { 190 return beans.iterator(); 191 } 192 193 201 public BeanMetaData getBeanByEjbName(String ejbName) 202 { 203 Iterator iterator = getEnterpriseBeans(); 204 while (iterator.hasNext()) 205 { 206 BeanMetaData current = (BeanMetaData)iterator.next(); 207 if (current.getEjbName().equals(ejbName)) 208 { 209 return current; 210 } 211 } 212 213 return null; 215 } 216 217 public String getConfigFile() 218 { 219 return configFile; 220 } 221 222 public void setConfigFile(String configFile) 223 { 224 this.configFile = configFile; 225 } 226 227 public String getConfigName() 228 { 229 return configName; 230 } 231 232 public void setConfigName(String configName) 233 { 234 this.configName = configName; 235 } 236 237 public String getClientJar() 238 { 239 return clientJar; 240 } 241 242 public void setClientJar(String clientJar) 243 { 244 this.clientJar = clientJar; 245 } 246 247 public HashMap getWsdlPublishLocations() 248 { 249 return wsdlPublishLocationMap; 250 } 251 252 public String getWsdlPublishLocationByName(String name) 253 { 254 return (String )wsdlPublishLocationMap.get(name); 256 } 257 258 public String getWebServiceContextRoot() 259 { 260 return webServiceContextRoot; 261 } 262 263 public void setWebServiceContextRoot(String webServiceContextRoot) 264 { 265 if (webServiceContextRoot.charAt(0) != '/') 266 { 267 webServiceContextRoot = "/" + webServiceContextRoot; 268 } 269 this.webServiceContextRoot = webServiceContextRoot; 270 } 271 272 public boolean isWebServiceDeployment() 273 { 274 return webServiceDeployment; 275 } 276 277 public void setWebServiceDeployment(boolean webServiceDeployment) 278 { 279 this.webServiceDeployment = webServiceDeployment; 280 } 281 282 public void addRelationship(RelationMetaData rmd) 283 { 284 relationships.add(rmd); 285 } 286 290 public Iterator getRelationships() 291 { 292 return relationships.iterator(); 293 } 294 295 public AssemblyDescriptorMetaData getAssemblyDescriptor() 296 { 297 return assemblyDescriptor; 298 } 299 300 public Iterator getConfigurations() 301 { 302 return configurations.values().iterator(); 303 } 304 305 public ConfigurationMetaData getConfigurationMetaDataByName(String name) 306 { 307 return (ConfigurationMetaData)configurations.get(name); 308 } 309 310 public void addInvokerProxyBinding(InvokerProxyBindingMetaData md) 311 { 312 invokerBindings.put(md.getName(), md); 313 } 314 public Iterator getInvokerProxyBindings() 315 { 316 return invokerBindings.values().iterator(); 317 } 318 319 public InvokerProxyBindingMetaData getInvokerProxyBindingMetaDataByName(String name) 320 { 321 return (InvokerProxyBindingMetaData)invokerBindings.get(name); 322 } 323 324 public String getResourceByName(String name) 325 { 326 return (String )resources.get(name); 328 } 329 330 public void mapResource(String name, String value) 331 { 332 resources.put(name, value); 333 } 334 335 public void addPluginData(String pluginName, Object pluginData) 336 { 337 plugins.put(pluginName, pluginData); 338 } 339 340 public Object getPluginData(String pluginName) 341 { 342 return plugins.get(pluginName); 343 } 344 345 public String getJmxName() 346 { 347 return jmxName; 348 } 349 public void setJmxName(String name) 350 { 351 this.jmxName = name; 352 } 353 354 public String getJaccContextID() 355 { 356 return jaccContextID; 357 } 358 public void setJaccContextID(String jaccContextID) 359 { 360 this.jaccContextID = jaccContextID; 361 } 362 363 public String getSecurityDomain() 364 { 365 return securityDomain; 366 } 367 368 371 public void setSecurityDomain(String securityDomain) 372 { 373 this.securityDomain = securityDomain; 374 } 375 376 public String getUnauthenticatedPrincipal() 377 { 378 return unauthenticatedPrincipal; 379 } 380 381 public void setUnauthenticatedPrincipal(String unauthenticatedPrincipal) 382 { 383 this.unauthenticatedPrincipal = unauthenticatedPrincipal; 384 } 385 386 public boolean getEnforceEjbRestrictions() 387 { 388 return enforceEjbRestrictions; 389 } 390 391 public void setEnforceEjbRestrictions(boolean enforceEjbRestrictions) 392 { 393 this.enforceEjbRestrictions = enforceEjbRestrictions; 394 } 395 396 public boolean isExcludeMissingMethods() 397 { 398 return excludeMissingMethods; 399 } 400 401 public void setExcludeMissingMethods(boolean excludeMissingMethods) 402 { 403 this.excludeMissingMethods = excludeMissingMethods; 404 } 405 406 public MessageDestinationMetaData getMessageDestination(String name) 407 { 408 return assemblyDescriptor.getMessageDestinationMetaData(name); 409 } 410 411 public boolean getExceptionRollback() 412 { 413 return exceptionRollback; 414 } 415 public void setExceptionRollback(boolean flag) 416 { 417 this.exceptionRollback = flag; 418 } 419 420 public void addBeanMetaData(BeanMetaData metaData) 421 { 422 beans.add(metaData); 423 } 424 425 431 public void importEjbJarXml(Element element) 432 throws DeploymentException 433 { 434 DocumentType docType = element.getOwnerDocument().getDoctype(); 437 438 if (docType == null) 439 { 440 if ("http://java.sun.com/xml/ns/j2ee".equals(element.getNamespaceURI())) 442 { 443 ejbVersion = 2; 444 ejbMinorVersion = 1; 445 } 446 else 447 { 448 throw new DeploymentException("ejb-jar.xml must either obey " + 450 "the right xml schema or define a valid DOCTYPE!"); 451 } 452 } 453 else 454 { 455 String publicId = docType.getPublicId(); 456 if (publicId == null) 457 { 458 throw new DeploymentException("The DOCTYPE declaration in " + 460 "ejb-jar.xml must define a PUBLIC id"); 461 } 462 463 if (publicId.startsWith("-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0")) 465 { 466 ejbVersion = 2; 467 } 468 else if (publicId.startsWith("-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1")) 469 { 470 ejbVersion = 1; 471 } 472 else 473 { 474 throw new DeploymentException("Unknown PUBLIC id in " + 476 "ejb-jar.xml: " + publicId); 477 } 478 } 479 480 Element enterpriseBeans = getUniqueChild(element, "enterprise-beans"); 482 483 HashMap schemaNameMap = new HashMap (); 485 Iterator iterator = getChildrenByTagName(enterpriseBeans, "entity"); 486 while (iterator.hasNext()) 487 { 488 Element currentEntity = (Element )iterator.next(); 489 EntityMetaData entityMetaData = new EntityMetaData(this); 490 try 491 { 492 entityMetaData.importEjbJarXml(currentEntity); 493 } 494 catch (DeploymentException e) 495 { 496 throw new DeploymentException("Error in ejb-jar.xml " + 497 "for Entity Bean " + entityMetaData.getEjbName() + ": " + 498 e.getMessage()); 499 } 500 501 String abstractSchemaName = entityMetaData.getAbstractSchemaName(); 503 if (abstractSchemaName != null) 504 { 505 if (schemaNameMap.containsKey(abstractSchemaName)) 506 { 507 throw new DeploymentException(entityMetaData.getEjbName() + 509 ": Duplicate abstract-schema name '" + abstractSchemaName + 510 "'. Already defined for Entity '" + 511 ((EntityMetaData)schemaNameMap.get(abstractSchemaName)).getEjbName() + "'."); 512 } 513 schemaNameMap.put(abstractSchemaName, entityMetaData); 514 } 515 516 beans.add(entityMetaData); 517 } 518 519 iterator = getChildrenByTagName(enterpriseBeans, "session"); 521 while (iterator.hasNext()) 522 { 523 Element currentSession = (Element )iterator.next(); 524 SessionMetaData sessionMetaData = new SessionMetaData(this); 525 try 526 { 527 sessionMetaData.importEjbJarXml(currentSession); 528 } 529 catch (DeploymentException e) 530 { 531 throw new DeploymentException("Error in ejb-jar.xml for " + 532 "Session Bean " + sessionMetaData.getEjbName() + ": " + 533 e.getMessage()); 534 } 535 beans.add(sessionMetaData); 536 } 537 538 iterator = getChildrenByTagName(enterpriseBeans, "message-driven"); 540 while (iterator.hasNext()) 541 { 542 Element currentMessageDriven = (Element )iterator.next(); 543 MessageDrivenMetaData messageDrivenMetaData = 544 new MessageDrivenMetaData(this); 545 546 try 547 { 548 messageDrivenMetaData.importEjbJarXml(currentMessageDriven); 549 } 550 catch (DeploymentException e) 551 { 552 throw new DeploymentException("Error in ejb-jar.xml for " + 553 "Message Driven Bean " + 554 messageDrivenMetaData.getEjbName() + ": " + e.getMessage()); 555 } 556 beans.add(messageDrivenMetaData); 557 } 558 559 Set ejbNames = new HashSet (); 561 Iterator beanIt = beans.iterator(); 562 while (beanIt.hasNext()) 563 { 564 BeanMetaData bmd = (BeanMetaData)beanIt.next(); 565 566 String beanName = bmd.getEjbName(); 567 if (ejbNames.contains(beanName)) 568 { 569 throw new DeploymentException("Duplicate definition of an " + 570 "EJB with name '" + beanName + "'."); 571 } 572 573 ejbNames.add(beanName); 574 } 575 576 Element relationshipsElement = getOptionalChild(element, 578 "relationships"); 579 if (relationshipsElement != null) 580 { 581 Set relationNames = new HashSet (); 583 584 iterator = getChildrenByTagName(relationshipsElement, 585 "ejb-relation"); 586 while (iterator.hasNext()) 587 { 588 Element relationElement = (Element )iterator.next(); 589 RelationMetaData relationMetaData = new RelationMetaData(); 590 try 591 { 592 relationMetaData.importEjbJarXml(relationElement); 593 } 594 catch (DeploymentException e) 595 { 596 throw new DeploymentException("Error in ejb-jar.xml " + 597 "for relation " + relationMetaData.getRelationName() + 598 ": " + e.getMessage()); 599 } 600 601 String relationName = relationMetaData.getRelationName(); 604 if (relationName != null) 605 { 606 if (relationNames.contains(relationName)) 607 { 608 throw new DeploymentException("ejb-relation-name must " + 609 "be unique in ejb-jar.xml file: ejb-relation-name is " + 610 relationName); 611 } 612 relationNames.add(relationName); 613 } 614 615 relationships.add(relationMetaData); 616 } 617 } 618 619 Element descrElement = getOptionalChild(element, "assembly-descriptor"); 621 if (descrElement != null) 622 { 623 iterator = getChildrenByTagName(descrElement, "security-role"); 625 while (iterator.hasNext()) 626 { 627 Element securityRole = (Element )iterator.next(); 628 try 629 { 630 String roleName = getElementContent(getUniqueChild(securityRole, "role-name")); 631 SecurityRoleMetaData srMetaData = new SecurityRoleMetaData(roleName); 632 assemblyDescriptor.addSecurityRoleMetaData(srMetaData); 633 } 634 catch (DeploymentException e) 635 { 636 throw new DeploymentException("Error in ejb-jar.xml " + 637 "for security-role: " + e.getMessage()); 638 } 639 } 640 641 iterator = getChildrenByTagName(descrElement, 643 "method-permission"); 644 try 645 { 646 while (iterator.hasNext()) 647 { 648 Element methodPermission = (Element )iterator.next(); 649 Element unchecked = getOptionalChild(methodPermission, 651 "unchecked"); 652 653 boolean isUnchecked = false; 654 Set roles = null; 655 if (unchecked != null) 656 { 657 isUnchecked = true; 658 } 659 else 660 { 661 roles = new HashSet (); 663 Iterator rolesIterator = getChildrenByTagName(methodPermission, "role-name"); 664 while (rolesIterator.hasNext()) 665 { 666 roles.add(getElementContent((Element )rolesIterator.next())); 667 } 668 if (roles.size() == 0) 669 throw new DeploymentException("An unchecked " + 670 "element or one or more role-name elements " + 671 "must be specified in method-permission"); 672 } 673 674 Iterator methods = getChildrenByTagName(methodPermission, 676 "method"); 677 while (methods.hasNext()) 678 { 679 MethodMetaData method = new MethodMetaData(); 681 method.importEjbJarXml((Element )methods.next()); 682 if (isUnchecked) 683 { 684 method.setUnchecked(); 685 } 686 else 687 { 688 method.setRoles(roles); 689 } 690 691 BeanMetaData bean = getBeanByEjbName(method.getEjbName()); 693 if (bean == null) 694 { 695 throw new DeploymentException(method.getEjbName() + 696 " doesn't exist"); 697 } 698 bean.addPermissionMethod(method); 699 } 700 } 701 } 702 catch (DeploymentException e) 703 { 704 throw new DeploymentException("Error in ejb-jar.xml, " + 705 "in method-permission: " + e.getMessage()); 706 } 707 708 iterator = getChildrenByTagName(descrElement, 710 "container-transaction"); 711 try 712 { 713 while (iterator.hasNext()) 714 { 715 Element containerTransaction = (Element )iterator.next(); 716 717 String type = getElementContent(getUniqueChild(containerTransaction, "trans-attribute")); 719 byte transactionType = MethodMetaData.getTransactionAttribute(type); 720 721 Iterator methods = getChildrenByTagName(containerTransaction, "method"); 723 while (methods.hasNext()) 724 { 725 MethodMetaData method = new MethodMetaData(); 727 method.importEjbJarXml((Element )methods.next()); 728 method.setTransactionType(transactionType); 729 730 BeanMetaData bean = getBeanByEjbName(method.getEjbName()); 732 if (bean == null) 733 { 734 throw new DeploymentException("bean " + 735 method.getEjbName() + " doesn't exist"); 736 } 737 bean.addTransactionMethod(method); 738 } 739 } 740 } 741 catch (DeploymentException e) 742 { 743 throw new DeploymentException("Error in ejb-jar.xml, " + 744 "in <container-transaction>: " + e.getMessage()); 745 } 746 747 Element excludeList = getOptionalChild(descrElement, 749 "exclude-list"); 750 if (excludeList != null) 751 { 752 iterator = getChildrenByTagName(excludeList, "method"); 753 while (iterator.hasNext()) 754 { 755 Element methodInf = (Element )iterator.next(); 756 MethodMetaData method = new MethodMetaData(); 758 method.importEjbJarXml(methodInf); 759 method.setExcluded(); 760 761 BeanMetaData bean = getBeanByEjbName(method.getEjbName()); 763 if (bean == null) 764 { 765 throw new DeploymentException("bean " + 766 method.getEjbName() + " doesn't exist"); 767 } 768 bean.addExcludedMethod(method); 769 } 770 } 771 772 iterator = getChildrenByTagName(descrElement, "message-destination"); 774 while (iterator.hasNext()) 775 { 776 Element messageDestination = (Element )iterator.next(); 777 try 778 { 779 MessageDestinationMetaData messageDestinationMetaData = new MessageDestinationMetaData(); 780 messageDestinationMetaData.importEjbJarXml(messageDestination); 781 assemblyDescriptor.addMessageDestinationMetaData(messageDestinationMetaData); 782 } 783 catch (Throwable t) 784 { 785 throw new DeploymentException("Error in ejb-jar.xml " + 786 "for message destination: " + t.getMessage()); 787 } 788 } 789 } 790 } 791 792 public void importJbossXml(Element element) 793 throws DeploymentException 794 { 795 Iterator iterator; 796 797 799 Element enforce = getOptionalChild(element, "enforce-ejb-restrictions"); 801 if (enforce != null) 802 { 803 String tmp = getElementContent(enforce); 804 enforceEjbRestrictions = Boolean.valueOf(tmp).booleanValue(); 805 } 806 807 Element jmxNameElement = getOptionalChild(element, 809 "jmx-name"); 810 if (jmxNameElement != null) 811 { 812 jmxName = getElementContent(jmxNameElement); 813 } 814 815 exceptionRollback = MetaData.getOptionalChildBooleanContent(element, "exception-on-rollback", false); 817 818 Element securityDomainElement = getOptionalChild(element, 820 "security-domain"); 821 if (securityDomainElement != null) 822 { 823 securityDomain = getElementContent(securityDomainElement); 824 } 825 826 excludeMissingMethods = MetaData.getOptionalChildBooleanContent(element, 828 "missing-method-permissions-excluded-mode", true); 829 830 Element unauth = getOptionalChild(element, 832 "unauthenticated-principal"); 833 if (unauth != null) 834 { 835 unauthenticatedPrincipal = getElementContent(unauth); 836 } 837 else 838 { 839 setDefaultUnauthenticatedPrincipal(); 840 } 841 842 Element invokerConfs = getOptionalChild(element, 844 "invoker-proxy-bindings"); 845 if (invokerConfs != null) 846 { 847 iterator = getChildrenByTagName(invokerConfs, 848 "invoker-proxy-binding"); 849 850 while (iterator.hasNext()) 851 { 852 Element invoker = (Element )iterator.next(); 853 String invokerName = getElementContent(getUniqueChild(invoker, "name")); 854 855 InvokerProxyBindingMetaData invokerMetaData = 858 getInvokerProxyBindingMetaDataByName(invokerName); 859 860 if (invokerMetaData == null) 862 { 863 invokerMetaData = new InvokerProxyBindingMetaData(invokerName); 864 invokerBindings.put(invokerName, invokerMetaData); 865 } 866 867 try 868 { 869 invokerMetaData.importJbossXml(invoker); 870 } 871 catch (DeploymentException e) 872 { 873 throw new DeploymentException("Error in jboss.xml " + 874 "for invoker-proxy-binding " + invokerMetaData.getName() + 875 ": " + e.getMessage()); 876 } 877 } 878 } 879 880 Element confs = getOptionalChild(element, "container-configurations"); 883 if (confs != null) 884 { 885 iterator = getChildrenByTagName(confs, "container-configuration"); 886 887 while (iterator.hasNext()) 888 { 889 Element conf = (Element )iterator.next(); 890 String confName = getElementContent(getUniqueChild(conf, 891 "container-name")); 892 String parentConfName = conf.getAttribute("extends"); 893 if (parentConfName != null && parentConfName.trim().length() == 0) 894 { 895 parentConfName = null; 896 } 897 898 ConfigurationMetaData configurationMetaData = null; 904 if (parentConfName != null) 905 { 906 configurationMetaData = getConfigurationMetaDataByName(parentConfName); 907 if (configurationMetaData == null) 908 { 909 throw new DeploymentException("Failed to find " + 910 "parent config=" + parentConfName); 911 } 912 913 configurationMetaData = 915 (ConfigurationMetaData)configurationMetaData.clone(); 916 configurations.put(confName, configurationMetaData); 917 } 918 919 if (configurationMetaData == null) 920 { 921 configurationMetaData = 922 getConfigurationMetaDataByName(confName); 923 } 924 925 if (configurationMetaData == null) 927 { 928 configurationMetaData = new ConfigurationMetaData(confName); 929 configurations.put(confName, configurationMetaData); 930 } 931 932 try 933 { 934 configurationMetaData.importJbossXml(conf); 935 } 936 catch (DeploymentException e) 937 { 938 throw new DeploymentException("Error in jboss.xml " + 939 "for container-configuration " + 940 configurationMetaData.getName() + ": " + e.getMessage()); 941 } 942 } 943 } 944 945 Element webservices = getOptionalChild(element, "webservices"); 946 if (webservices != null) 947 { 948 Element contextRoot = getOptionalChild(webservices, "context-root"); 949 if (contextRoot != null) 950 { 951 webServiceContextRoot = getElementContent(contextRoot); 952 if (webServiceContextRoot.charAt(0) != '/') 953 webServiceContextRoot = "/" + webServiceContextRoot; 954 } 955 iterator = getChildrenByTagName(webservices, "webservice-description"); 956 while (iterator.hasNext()) 957 { 958 Element wsd = (Element )iterator.next(); 959 String wsdName = getElementContent(getUniqueChild(wsd, "webservice-description-name")); 960 configName = MetaData.getOptionalChildContent(wsd, "config-name"); 961 configFile = MetaData.getOptionalChildContent(wsd, "config-file"); 962 String wsdlPublishLocation = getOptionalChildContent(wsd, "wsdl-publish-location"); 963 wsdlPublishLocationMap.put(wsdName, wsdlPublishLocation); 964 } 965 } 966 Element entBeans = getOptionalChild(element, "enterprise-beans"); 968 if (entBeans != null) 969 { 970 String ejbName = null; 971 try 972 { 973 iterator = getChildrenByTagName(entBeans, "entity"); 975 while (iterator.hasNext()) 976 { 977 Element bean = (Element )iterator.next(); 978 ejbName = getElementContent(getUniqueChild(bean, "ejb-name")); 979 BeanMetaData beanMetaData = getBeanByEjbName(ejbName); 980 if (beanMetaData == null) 981 { 982 throw new DeploymentException("found in jboss.xml " + 983 "but not in ejb-jar.xml"); 984 } 985 beanMetaData.importJbossXml(bean); 986 } 987 988 iterator = getChildrenByTagName(entBeans, "session"); 990 while (iterator.hasNext()) 991 { 992 Element bean = (Element )iterator.next(); 993 ejbName = getElementContent(getUniqueChild(bean, "ejb-name")); 994 BeanMetaData beanMetaData = getBeanByEjbName(ejbName); 995 if (beanMetaData == null) 996 { 997 throw new DeploymentException("found in jboss.xml " + 998 "but not in ejb-jar.xml"); 999 } 1000 beanMetaData.importJbossXml(bean); 1001 } 1002 1003 iterator = getChildrenByTagName(entBeans, "message-driven"); 1005 while (iterator.hasNext()) 1006 { 1007 Element bean = (Element )iterator.next(); 1008 ejbName = getElementContent(getUniqueChild(bean, "ejb-name")); 1009 BeanMetaData beanMetaData = getBeanByEjbName(ejbName); 1010 if (beanMetaData == null) 1011 { 1012 throw new DeploymentException("found in jboss.xml " + 1013 "but not in ejb-jar.xml"); 1014 } 1015 beanMetaData.importJbossXml(bean); 1016 } 1017 } 1018 catch (DeploymentException e) 1019 { 1020 throw new DeploymentException("Error in jboss.xml for " + 1021 "Bean " + ejbName + ": " + e.getMessage()); 1022 1023 } 1025 } 1026 1027 Element descrElement = getOptionalChild(element, "assembly-descriptor"); 1029 if (descrElement != null) 1030 { 1031 iterator = getChildrenByTagName(descrElement, "security-role"); 1033 while (iterator.hasNext()) 1034 { 1035 Element securityRole = (Element )iterator.next(); 1036 String roleName = getElementContent(getUniqueChild(securityRole, "role-name")); 1037 SecurityRoleMetaData securityRoleMetaData = assemblyDescriptor.getSecurityRoleByName(roleName); 1038 if (securityRoleMetaData == null) 1039 { 1040 securityRoleMetaData = new SecurityRoleMetaData(roleName); 1042 assemblyDescriptor.addSecurityRoleMetaData(securityRoleMetaData); 1043 } 1044 1045 Iterator itPrincipalNames = getChildrenByTagName(securityRole, "principal-name"); 1046 while (itPrincipalNames.hasNext()) 1047 { 1048 String principalName = getElementContent((Element )itPrincipalNames.next()); 1049 securityRoleMetaData.addPrincipalName(principalName); 1050 } 1051 } 1052 1053 iterator = getChildrenByTagName(descrElement, "message-destination"); 1055 while (iterator.hasNext()) 1056 { 1057 Element messageDestination = (Element )iterator.next(); 1058 try 1059 { 1060 String messageDestinationName = getUniqueChildContent(messageDestination, "message-destination-name"); 1061 MessageDestinationMetaData messageDestinationMetaData = getMessageDestination(messageDestinationName); 1062 if (messageDestinationMetaData == null) 1063 throw new DeploymentException("message-destination " + messageDestinationName + " found in jboss.xml but not in ejb-jar.xml"); 1064 messageDestinationMetaData.importJbossXml(messageDestination); 1065 } 1066 catch (Throwable t) 1067 { 1068 throw new DeploymentException("Error in ejb-jar.xml " + 1069 "for message destination: " + t.getMessage()); 1070 } 1071 } 1072 } 1073 1074 Element resmans = getOptionalChild(element, "resource-managers"); 1076 if (resmans != null) 1077 { 1078 iterator = getChildrenByTagName(resmans, "resource-manager"); 1079 try 1080 { 1081 while (iterator.hasNext()) 1082 { 1083 Element resourceManager = (Element )iterator.next(); 1084 String resName = getElementContent(getUniqueChild(resourceManager, "res-name")); 1085 1086 String jndi = getElementContent(getOptionalChild(resourceManager, "res-jndi-name")); 1087 1088 String url = getElementContent(getOptionalChild(resourceManager, "res-url")); 1089 1090 if (jndi != null && url == null) 1091 { 1092 resources.put(resName, jndi); 1093 } 1094 else if (jndi == null && url != null) 1095 { 1096 resources.put(resName, url); 1097 } 1098 else 1099 { 1100 throw new DeploymentException(resName + 1101 " : expected res-url or res-jndi-name tag"); 1102 } 1103 } 1104 } 1105 catch (DeploymentException e) 1106 { 1107 throw new DeploymentException("Error in jboss.xml, in " + 1108 "resource-manager: " + e.getMessage()); 1109 } 1110 } 1111 } 1112 1113 public void setDefaultUnauthenticatedPrincipal() 1114 { 1115 try 1116 { 1117 MBeanServer server = MBeanServerLocator.locateJBoss(); 1118 ObjectName oname = new ObjectName ("jboss.security:service=JaasSecurityManager"); 1119 unauthenticatedPrincipal = (String )server.getAttribute(oname, "DefaultUnauthenticatedPrincipal"); 1120 } 1121 catch (Exception e) 1122 { 1123 log.error("Cannot obtain unauthenticated principal"); 1124 } 1125 } 1126 1127 public void addContainerConfiguration(ConfigurationMetaData container) 1128 { 1129 String name = container.getName(); 1130 if(name == null) 1131 { 1132 throw new IllegalStateException ("Container configuration must have a non-null name!"); 1133 } 1134 configurations.put(name, container); 1135 } 1136 1137 1141 public void mergeSecurityRoles(Map <String , SecurityRoleMetaData> applRoles) 1142 { 1143 this.assemblyDescriptor.mergeSecurityRoles(applRoles); 1144 } 1145} 1146 1147 1150 | Popular Tags |