| 1 22 package org.jboss.metadata; 23 24 import java.lang.reflect.Method ; 25 import java.util.ArrayList ; 26 import java.util.Collection ; 27 import java.util.HashMap ; 28 import java.util.HashSet ; 29 import java.util.Iterator ; 30 import java.util.LinkedList ; 31 import java.util.Set ; 32 33 import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap; 34 35 import org.jboss.deployment.DeploymentException; 36 import org.jboss.invocation.InvocationType; 37 import org.jboss.webservice.metadata.serviceref.ServiceRefMetaData; 38 import org.jboss.mx.util.ObjectNameFactory; 39 import org.jboss.security.AnybodyPrincipal; 40 import org.jboss.security.NobodyPrincipal; 41 import org.jboss.security.SimplePrincipal; 42 import org.w3c.dom.Element ; 43 44 45 60 public abstract class BeanMetaData 61 extends MetaData 62 { 63 65 public static final char SESSION_TYPE = 'S'; 66 public static final char ENTITY_TYPE = 'E'; 67 public static final char MDB_TYPE = 'M'; 68 public static final String LOCAL_INVOKER_PROXY_BINDING = "LOCAL"; 69 70 72 private ApplicationMetaData application; 73 74 private String description; 76 private String displayName; 77 82 private String ejbName; 83 85 private String homeClass; 86 88 private String remoteClass; 89 91 private String localHomeClass; 92 94 private String localClass; 95 97 protected String serviceEndpointClass; 98 100 private String ejbClass; 101 102 protected char beanType; 103 104 protected boolean containerManagedTx = true; 105 106 108 private ArrayList environmentEntries = new ArrayList (); 109 111 private HashMap ejbReferences = new HashMap (); 112 113 private HashMap ejbLocalReferences = new HashMap (); 114 115 private HashMap serviceReferences = new HashMap (); 116 117 private ArrayList securityRoleReferences = new ArrayList (); 118 119 private SecurityIdentityMetaData securityIdentity = null; 120 121 private SecurityIdentityMetaData ejbTimeoutIdentity = null; 122 123 private HashMap resourceReferences = new HashMap (); 124 125 private HashMap resourceEnvReferences = new HashMap (); 126 127 private HashMap messageDestinationReferences = new HashMap (); 128 129 private ArrayList methodAttributes = new ArrayList (); 130 private ConcurrentReaderHashMap cachedMethodAttributes = new ConcurrentReaderHashMap(); 131 132 private ArrayList permissionMethods = new ArrayList (); 133 134 private ArrayList transactionMethods = new ArrayList (); 135 136 private ConcurrentReaderHashMap methodTx = new ConcurrentReaderHashMap(); 137 138 private ArrayList excludedMethods = new ArrayList (); 139 140 protected HashMap invokerBindings = null; 141 142 private ClusterConfigMetaData clusterConfig = null; 143 144 145 private String jndiName; 146 147 148 private String localJndiName; 149 150 protected String configurationName; 151 152 private ConfigurationMetaData configuration; 153 154 private String securityProxy; 155 156 157 protected boolean clustered = false; 158 159 protected boolean callByValue = false; 160 161 private Collection depends = new LinkedList (); 162 163 164 private IorSecurityConfigMetaData iorSecurityConfig; 165 166 protected EjbPortComponentMetaData portComponent; 167 168 private boolean exceptionRollback = false; 169 170 private boolean timerPersistence = true; 171 172 174 public BeanMetaData(ApplicationMetaData app, char beanType) 176 { 177 this.application = app; 178 this.beanType = beanType; 179 } 180 181 public void setBeanType(char beanType) 182 { 183 this.beanType = beanType; 184 } 185 186 public String getDescription() 187 { 188 return description; 189 } 190 191 public void setDescription(String description) 192 { 193 this.description = description; 194 } 195 196 public String getDisplayName() 197 { 198 return displayName; 199 } 200 201 public void setDisplayName(String displayName) 202 { 203 this.displayName = displayName; 204 } 205 206 public boolean isSession() 207 { 208 return beanType == SESSION_TYPE; 209 } 210 211 public boolean isMessageDriven() 212 { 213 return beanType == MDB_TYPE; 214 } 215 216 public boolean isEntity() 217 { 218 return beanType == ENTITY_TYPE; 219 } 220 221 public String getHome() 222 { 223 return homeClass; 224 } 225 226 public String getRemote() 227 { 228 return remoteClass; 229 } 230 231 public String getLocalHome() 232 { 233 return localHomeClass; 234 } 235 236 public String getLocal() 237 { 238 return localClass; 239 } 240 241 public String getServiceEndpoint() 242 { 243 return serviceEndpointClass; 244 } 245 246 public EjbPortComponentMetaData getPortComponent() 247 { 248 return portComponent; 249 } 250 251 public void setPortComponent(EjbPortComponentMetaData portComponent) 252 { 253 this.portComponent = portComponent; 254 } 255 256 public String getEjbClass() 257 { 258 return ejbClass; 259 } 260 261 public String getEjbName() 262 { 263 return ejbName; 264 } 265 266 public void setEjbName(String ejbName) 267 { 268 this.ejbName = ejbName; 269 } 270 271 public boolean isContainerManagedTx() 272 { 273 return containerManagedTx; 274 } 275 276 public boolean isBeanManagedTx() 277 { 278 return !containerManagedTx; 279 } 280 281 public Iterator getEjbReferences() 282 { 283 return ejbReferences.values().iterator(); 284 } 285 286 public void addEjbReference(EjbRefMetaData ref) 287 { 288 ejbReferences.put(ref.getName(), ref); 289 } 290 291 public Iterator getEjbLocalReferences() 292 { 293 return ejbLocalReferences.values().iterator(); 294 } 295 296 public void addEjbLocalReference(EjbLocalRefMetaData ref) 297 { 298 ejbLocalReferences.put(ref.getName(), ref); 299 } 300 301 protected abstract void defaultInvokerBindings(); 302 303 public Iterator getInvokerBindings() 304 { 305 if (invokerBindings == null) 306 { 307 String [] defaultNames = configuration.getInvokers(); 309 if (defaultNames.length > 0) 310 { 311 invokerBindings = new HashMap (); 312 for (int count = 0; count < defaultNames.length; count++) 313 { 314 invokerBindings.put(defaultNames[count], getJndiName()); 315 } 316 } 317 else 318 { 319 defaultInvokerBindings(); 321 } 322 } 323 324 return invokerBindings.keySet().iterator(); 325 } 326 327 public String getInvokerBinding(String invokerName) 328 { 329 if (invokerBindings == null) 330 { 331 defaultInvokerBindings(); 332 } 333 334 return (String )invokerBindings.get(invokerName); 335 } 336 337 public void addInvokerBinding(String bindingName, String jndiName) 338 { 339 if(invokerBindings == null) 340 { 341 invokerBindings = new HashMap (); 342 } 343 invokerBindings.put(bindingName, jndiName); 344 } 345 346 public EjbRefMetaData getEjbRefByName(String name) 347 { 348 return (EjbRefMetaData)ejbReferences.get(name); 349 } 350 351 public EjbLocalRefMetaData getEjbLocalRefByName(String name) 352 { 353 return (EjbLocalRefMetaData)ejbLocalReferences.get(name); 354 } 355 356 public Iterator getEnvironmentEntries() 357 { 358 return environmentEntries.iterator(); 359 } 360 361 public void addEnvironmentEntry(EnvEntryMetaData envEntry) 362 { 363 environmentEntries.add(envEntry); 364 } 365 366 public Iterator getSecurityRoleReferences() 367 { 368 return securityRoleReferences.iterator(); 369 } 370 371 public Iterator getResourceReferences() 372 { 373 return resourceReferences.values().iterator(); 374 } 375 376 public void addResourceReference(ResourceRefMetaData resRef) 377 { 378 resourceReferences.put(resRef.getRefName(), resRef); 379 } 380 381 public ResourceRefMetaData getResourceReference(String refName) 382 { 383 return (ResourceRefMetaData)resourceReferences.get(refName); 384 } 385 386 public Iterator getResourceEnvReferences() 387 { 388 return resourceEnvReferences.values().iterator(); 389 } 390 391 public void addResourceEnvReference(ResourceEnvRefMetaData resEnvRef) 392 { 393 resourceEnvReferences.put(resEnvRef.getRefName(), resEnvRef); 394 } 395 396 public ResourceEnvRefMetaData getResourceEnvReference(String refName) 397 { 398 return (ResourceEnvRefMetaData)resourceEnvReferences.get(refName); 399 } 400 401 public Iterator getMessageDestinationReferences() 402 { 403 return messageDestinationReferences.values().iterator(); 404 } 405 406 public void addMessageDestinationReference(MessageDestinationRefMetaData ref) 407 { 408 messageDestinationReferences.put(ref.getRefName(), ref); 409 } 410 411 public MessageDestinationRefMetaData getMessageDestinationReference(String refName) 412 { 413 return (MessageDestinationRefMetaData)messageDestinationReferences.get(refName); 414 } 415 416 419 public HashMap getServiceReferences() 420 { 421 return serviceReferences; 422 } 423 424 public void addServiceReference(ServiceRefMetaData ref) 425 { 426 serviceReferences.put(ref.getServiceRefName(), ref); 427 } 428 429 public String getJndiName() 430 { 431 if (jndiName == null) 433 { 434 jndiName = ejbName; 435 } 436 return jndiName; 437 } 438 439 443 public String getLocalJndiName() 444 { 445 if (localJndiName == null) 446 { 447 localJndiName = "local/" + ejbName + '@' + System.identityHashCode(ejbName); 449 } 450 return localJndiName; 451 } 452 453 456 public String getContainerObjectNameJndiName() 457 { 458 return getHome() != null ? getJndiName() : getLocalJndiName(); 459 } 460 461 public String getConfigurationName() 462 { 463 if (configurationName == null) 464 { 465 configurationName = getDefaultConfigurationName(); 466 } 467 return configurationName; 468 } 469 470 public ConfigurationMetaData getContainerConfiguration() 471 { 472 if (configuration == null) 473 { 474 String configName = getConfigurationName(); 475 configuration = application.getConfigurationMetaDataByName(configName); 476 if (configuration == null) 477 throw new IllegalStateException ("Container config not found " + configName); 478 } 479 return configuration; 480 } 481 482 public String getSecurityProxy() 483 { 484 return securityProxy; 485 } 486 487 public SecurityIdentityMetaData getSecurityIdentityMetaData() 488 { 489 return securityIdentity; 490 } 491 492 public void setSecurityIdentityMetaData(SecurityIdentityMetaData securityIdentity) 493 { 494 this.securityIdentity = securityIdentity; 495 } 496 497 public SecurityIdentityMetaData getEjbTimeoutIdentity() 498 { 499 return ejbTimeoutIdentity; 500 } 501 502 public ApplicationMetaData getApplicationMetaData() 503 { 504 return application; 505 } 506 507 public abstract String getDefaultConfigurationName(); 508 509 public Iterator getTransactionMethods() 510 { 511 return transactionMethods.iterator(); 512 } 513 514 public Iterator getPermissionMethods() 515 { 516 return permissionMethods.iterator(); 517 } 518 519 public Iterator getExcludedMethods() 520 { 521 return excludedMethods.iterator(); 522 } 523 524 public void addTransactionMethod(MethodMetaData method) 525 { 526 transactionMethods.add(method); 527 } 528 529 public void addPermissionMethod(MethodMetaData method) 530 { 531 if (method.isUnchecked()) 534 { 535 permissionMethods.add(0, method); 536 } 537 else 538 { 539 permissionMethods.add(method); 540 } 541 } 542 543 public void addExcludedMethod(MethodMetaData method) 544 { 545 excludedMethods.add(method); 546 } 547 548 public byte getMethodTransactionType(String methodName, Class [] params, InvocationType iface) 549 { 550 byte result = TX_UNKNOWN; 552 553 MethodMetaData bestMatch = null; 554 Iterator iterator = getTransactionMethods(); 555 while (iterator.hasNext()) 556 { 557 MethodMetaData m = (MethodMetaData)iterator.next(); 558 if (m.patternMatches(methodName, params, iface)) 559 { 560 561 if (bestMatch == null) 563 { 564 bestMatch = m; 565 } 566 else 567 { 568 if (bestMatch.getMethodName().equals("*")) 570 { 571 bestMatch = m; 572 } 573 if (m.getMethodParams().length > 0) 575 { 576 bestMatch = m; 577 break; 578 } 579 } 580 } 581 } 582 583 if (bestMatch != null) 584 { 585 result = bestMatch.getTransactionType(); 586 } 587 588 return result; 589 } 590 591 public byte getTransactionMethod(Method m, InvocationType iface) 593 { 594 if (m == null) 595 return MetaData.TX_SUPPORTS; 596 597 Byte b = (Byte )methodTx.get(m); 598 if (b != null) return b.byteValue(); 599 600 byte result = getMethodTransactionType(m.getName(), m.getParameterTypes(), iface); 601 602 if (result == MetaData.TX_UNKNOWN) 604 result = MetaData.TX_REQUIRED; 605 606 methodTx.put(m, new Byte (result)); 607 return result; 608 } 609 610 public Collection getDepends() 611 { 612 Collection allDepends = new LinkedList (depends); 613 allDepends.addAll(getContainerConfiguration().getDepends()); 614 return allDepends; 615 } 616 617 623 private MethodAttributes methodAttributesForMethod(String methodName) 624 { 625 if (methodName == null) 626 methodName = "*null*"; 627 628 MethodAttributes ma = 629 (MethodAttributes)cachedMethodAttributes.get(methodName); 630 631 if (ma == null) 632 { 633 Iterator iterator = methodAttributes.iterator(); 634 while (iterator.hasNext() && ma == null) 635 { 636 ma = (MethodAttributes)iterator.next(); 637 if (!ma.patternMatches(methodName)) 638 { 639 ma = null; 640 } 641 } 642 if (ma == null) 643 { 644 ma = MethodAttributes.kDefaultMethodAttributes; 645 } 646 647 cachedMethodAttributes.put(methodName, ma); 648 } 649 return ma; 650 } 651 652 655 public boolean isMethodReadOnly(String methodName) 656 { 657 return methodAttributesForMethod(methodName).readOnly; 658 } 659 660 public boolean isMethodReadOnly(Method method) 661 { 662 if (method == null) 663 { 664 return false; 665 } 666 return methodAttributesForMethod(method.getName()).readOnly; 667 } 668 669 672 public int getTransactionTimeout(String methodName) 673 { 674 return methodAttributesForMethod(methodName).txTimeout; 675 } 676 677 public int getTransactionTimeout(Method method) 678 { 679 if (method == null) 680 return 0; 681 return getTransactionTimeout(method.getName()); 682 } 683 684 695 public Set getMethodPermissions(String methodName, Class [] params, 696 InvocationType iface) 697 { 698 Set result = new HashSet (); 699 Iterator iterator = getExcludedMethods(); 702 while (iterator.hasNext()) 703 { 704 MethodMetaData m = (MethodMetaData)iterator.next(); 705 if (m.patternMatches(methodName, params, iface)) 706 { 707 712 result.add(NobodyPrincipal.NOBODY_PRINCIPAL); 713 return result; 714 } 715 } 716 717 iterator = getPermissionMethods(); 719 while (iterator.hasNext()) 720 { 721 MethodMetaData m = (MethodMetaData)iterator.next(); 722 if (m.patternMatches(methodName, params, iface)) 723 { 724 728 if (m.isUnchecked()) 729 { 730 result.clear(); 731 result.add(AnybodyPrincipal.ANYBODY_PRINCIPAL); 732 break; 733 } 734 else 736 { 737 Iterator rolesIterator = m.getRoles().iterator(); 738 while (rolesIterator.hasNext()) 739 { 740 String roleName = (String )rolesIterator.next(); 741 result.add(new SimplePrincipal(roleName)); 742 } 743 } 744 } 745 } 746 747 if (this.isExcludeMissingMethods() == false) 748 { 749 if (result.isEmpty()) 751 { 752 result.add(AnybodyPrincipal.ANYBODY_PRINCIPAL); 753 } 754 } 755 756 return result; 757 } 758 759 767 public boolean hasMethodPermission(String methodName, Class [] params, 768 InvocationType iface) 769 { 770 Iterator iterator = getExcludedMethods(); 772 while (iterator.hasNext()) 773 { 774 MethodMetaData m = (MethodMetaData)iterator.next(); 775 if (m.patternMatches(methodName, params, iface)) 776 { 777 return true; 778 } 779 } 780 781 iterator = getPermissionMethods(); 783 while (iterator.hasNext()) 784 { 785 MethodMetaData m = (MethodMetaData)iterator.next(); 786 if (m.patternMatches(methodName, params, iface)) 787 { 788 return true; 789 } 790 } 791 792 return false; 793 } 794 795 public boolean isClustered() 797 { 798 return this.clustered; 799 } 800 801 public boolean isCallByValue() 802 { 803 return callByValue; 804 } 805 806 public boolean isExcludeMissingMethods() 807 { 808 return application.isExcludeMissingMethods(); 809 } 810 811 public ClusterConfigMetaData getClusterConfigMetaData() 812 { 813 if (clusterConfig == null) 814 { 815 clusterConfig = getContainerConfiguration().getClusterConfigMetaData(); 816 if (clusterConfig == null) 817 { 818 clusterConfig = new ClusterConfigMetaData(); 819 } 820 822 clusterConfig.init(this); 823 } 824 return this.clusterConfig; 825 } 826 827 public IorSecurityConfigMetaData getIorSecurityConfigMetaData() 828 { 829 return iorSecurityConfig; 830 } 831 832 public boolean getExceptionRollback() 833 { 834 return exceptionRollback; 835 } 836 837 public boolean getTimerPersistence() 838 { 839 return timerPersistence; 840 } 841 842 public ApplicationMetaData getApplication() 843 { 844 return application; 845 } 846 847 public void setApplication(ApplicationMetaData application) 848 { 849 this.application = application; 850 } 851 852 public ClusterConfigMetaData getClusterConfig() 853 { 854 return clusterConfig; 855 } 856 857 public void setClusterConfig(ClusterConfigMetaData clusterConfig) 858 { 859 this.clusterConfig = clusterConfig; 860 } 861 862 public void setHome(String homeClass) 863 { 864 this.homeClass = homeClass; 865 } 866 867 public IorSecurityConfigMetaData getIorSecurityConfig() 868 { 869 return iorSecurityConfig; 870 } 871 872 public void setIorSecurityConfig(IorSecurityConfigMetaData iorSecurityConfig) 873 { 874 this.iorSecurityConfig = iorSecurityConfig; 875 } 876 877 public void setLocal(String localClass) 878 { 879 this.localClass = localClass; 880 } 881 882 public void setLocalHome(String localHomeClass) 883 { 884 this.localHomeClass = localHomeClass; 885 } 886 887 public ArrayList getMethodAttributes() 888 { 889 return methodAttributes; 890 } 891 892 public void setMethodAttributes(ArrayList methodAttributes) 893 { 894 this.methodAttributes = methodAttributes; 895 } 896 897 public ConcurrentReaderHashMap getMethodTx() 898 { 899 return methodTx; 900 } 901 902 public void setMethodTx(ConcurrentReaderHashMap methodTx) 903 { 904 this.methodTx = methodTx; 905 } 906 907 public void setRemote(String remoteClass) 908 { 909 this.remoteClass = remoteClass; 910 } 911 912 public String getServiceEndpointClass() 913 { 914 return serviceEndpointClass; 915 } 916 917 public void setServiceEndpointClass(String serviceEndpointClass) 918 { 919 this.serviceEndpointClass = serviceEndpointClass; 920 } 921 922 public void setCallByValue(boolean callByValue) 923 { 924 this.callByValue = callByValue; 925 } 926 927 public void setClustered(boolean clustered) 928 { 929 this.clustered = clustered; 930 } 931
|