KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > metadata > BeanMetaData


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.metadata;
23
24 import java.lang.reflect.Method JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.Collection JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.util.HashSet JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.LinkedList JavaDoc;
31 import java.util.Set JavaDoc;
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 JavaDoc;
43
44
45 /**
46  * A common meta data class for the entity, message-driven and session beans.
47  *
48  * @author <a HREF="mailto:sebastien.alborini@m4x.org">Sebastien Alborini</a>
49  * @author <a HREF="mailto:peter.antman@tim.se">Peter Antman</a>
50  * @author <a HREF="mailto:docodan@mvcsoft.com">Daniel OConnor</a>
51  * @author <a HREF="mailto:Scott.Stark@jboss.org">Scott Stark</a>
52  * @author <a HREF="mailto:osh@sparre.dk">Ole Husgaard</a>
53  * @author <a HREF="mailto:bill@burkecentral.com">Bill Burke</a>
54  * @author <a HREF="mailto:criege@riege.com">Christian Riege</a>
55  * @author <a HREF="mailto:Thomas.Diesler@jboss.org">Thomas Diesler</a>
56  * @author <a HREF="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
57  *
58  * @version $Revision: 58474 $
59  */

60 public abstract class BeanMetaData
61    extends MetaData
62 {
63    // Constants -----------------------------------------------------
64

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 JavaDoc LOCAL_INVOKER_PROXY_BINDING = "LOCAL";
69
70    // Attributes ----------------------------------------------------
71
/** The metadata from the toplevel ejb-jar.xml/jboss.xml elements */
72    private ApplicationMetaData application;
73
74    // from ejb-jar.xml
75
private String JavaDoc description;
76    private String JavaDoc displayName;
77    /** The ejb-name element specifies an enterprise bean's name. This name is
78     assigned by the ejb-jar file producer to name the enterprise bean in
79     the ejb-jar file's deployment descriptor. The name must be unique
80     among the names of the enterprise beans in the same ejb-jar file.
81     */

82    private String JavaDoc ejbName;
83    /** The home element contains the fully-qualified name of the enterprise
84     bean's home interface. */

85    private String JavaDoc homeClass;
86    /** The remote element contains the fully-qualified name of the enterprise
87     bean's remote interface. */

88    private String JavaDoc remoteClass;
89    /** The local-home element contains the fully-qualified name of the
90     enterprise bean's local home interface. */

91    private String JavaDoc localHomeClass;
92    /** The local element contains the fully-qualified name of the enterprise
93     bean's local interface */

94    private String JavaDoc localClass;
95    /** The service-endpoint element contains the fully-qualified
96     * name of the bean�s service endpoint interface (SEI) */

97    protected String JavaDoc serviceEndpointClass;
98    /** The ejb-class element contains the fully-qualified name of the
99     enterprise bean's class. */

100    private String JavaDoc ejbClass;
101    /** The type of bean: ENTITY_TYPE, SESSION_TYPE, MDB_TYPE */
102    protected char beanType;
103    /** Is this bean's transactions managed by the container? */
104    protected boolean containerManagedTx = true;
105
106    /** The The env-entry element(s) contains the declaration of an enterprise
107     bean's environment entry */

108    private ArrayList JavaDoc environmentEntries = new ArrayList JavaDoc();
109    /** The The ejb-ref element(s) for the declaration of a reference to an
110     enterprise bean's home */

111    private HashMap JavaDoc ejbReferences = new HashMap JavaDoc();
112    /** The ejb-local-ref element(s) info */
113    private HashMap JavaDoc ejbLocalReferences = new HashMap JavaDoc();
114    /** The HashMap<ServiceRefMetaData> service-ref element(s) info */
115    private HashMap JavaDoc serviceReferences = new HashMap JavaDoc();
116    /** The security-role-ref element(s) info */
117    private ArrayList JavaDoc securityRoleReferences = new ArrayList JavaDoc();
118    /** The security-idemtity element info */
119    private SecurityIdentityMetaData securityIdentity = null;
120    /** */
121    private SecurityIdentityMetaData ejbTimeoutIdentity = null;
122    /** The resource-ref element(s) info */
123    private HashMap JavaDoc resourceReferences = new HashMap JavaDoc();
124    /** The resource-env-ref element(s) info */
125    private HashMap JavaDoc resourceEnvReferences = new HashMap JavaDoc();
126    /** The message destination references */
127    private HashMap JavaDoc messageDestinationReferences = new HashMap JavaDoc();
128    /** The method attributes */
129    private ArrayList JavaDoc methodAttributes = new ArrayList JavaDoc();
130    private ConcurrentReaderHashMap cachedMethodAttributes = new ConcurrentReaderHashMap();
131    /** The assembly-descriptor/method-permission element(s) info */
132    private ArrayList JavaDoc permissionMethods = new ArrayList JavaDoc();
133    /** The assembly-descriptor/container-transaction element(s) info */
134    private ArrayList JavaDoc transactionMethods = new ArrayList JavaDoc();
135    /** A cache mapping methods to transaction attributes. */
136    private ConcurrentReaderHashMap methodTx = new ConcurrentReaderHashMap();
137    /** The assembly-descriptor/exclude-list method(s) */
138    private ArrayList JavaDoc excludedMethods = new ArrayList JavaDoc();
139    /** The invoker names to JNDI name mapping */
140    protected HashMap JavaDoc invokerBindings = null;
141    /** The cluster-config element info */
142    private ClusterConfigMetaData clusterConfig = null;
143
144    /** The JNDI name under with the home interface should be bound */
145    private String JavaDoc jndiName;
146
147    /** The JNDI name under with the local home interface should be bound */
148    private String JavaDoc localJndiName;
149    /** The container configuration name */
150    protected String JavaDoc configurationName;
151    /** The container configuration metadata */
152    private ConfigurationMetaData configuration;
153    /** The custom security proxy class */
154    private String JavaDoc securityProxy;
155
156    /** Is the bean marked as clustered */
157    protected boolean clustered = false;
158    /** Should the bean use by value call semeantics */
159    protected boolean callByValue = false;
160    /** Any object names for services the bean depends on */
161    private Collection JavaDoc depends = new LinkedList JavaDoc();
162
163    /** Describes the security configuration information for the IOR. Optional element. Since 4.0. */
164    private IorSecurityConfigMetaData iorSecurityConfig;
165    /** The jboss port-component binding for a ejb webservice */
166    protected EjbPortComponentMetaData portComponent;
167    /** Whether to throw an exception on a rollback if there is no exception */
168    private boolean exceptionRollback = false;
169    /** Whether timer persistence is enabled */
170    private boolean timerPersistence = true;
171
172    // Static --------------------------------------------------------
173

174    // Constructors --------------------------------------------------
175
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 JavaDoc getDescription()
187    {
188       return description;
189    }
190
191    public void setDescription(String JavaDoc description)
192    {
193       this.description = description;
194    }
195
196    public String JavaDoc getDisplayName()
197    {
198       return displayName;
199    }
200
201    public void setDisplayName(String JavaDoc 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 JavaDoc getHome()
222    {
223       return homeClass;
224    }
225
226    public String JavaDoc getRemote()
227    {
228       return remoteClass;
229    }
230
231    public String JavaDoc getLocalHome()
232    {
233       return localHomeClass;
234    }
235
236    public String JavaDoc getLocal()
237    {
238       return localClass;
239    }
240
241    public String JavaDoc 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 JavaDoc getEjbClass()
257    {
258       return ejbClass;
259    }
260
261    public String JavaDoc getEjbName()
262    {
263       return ejbName;
264    }
265    
266    public void setEjbName(String JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc getInvokerBindings()
304    {
305       if (invokerBindings == null)
306       {
307          // See if there is a container default invoker name
308
String JavaDoc[] defaultNames = configuration.getInvokers();
309          if (defaultNames.length > 0)
310          {
311             invokerBindings = new HashMap JavaDoc();
312             for (int count = 0; count < defaultNames.length; count++)
313             {
314                invokerBindings.put(defaultNames[count], getJndiName());
315             }
316          }
317          else
318          {
319             // Use the hard-coded defaults
320
defaultInvokerBindings();
321          }
322       }
323
324       return invokerBindings.keySet().iterator();
325    }
326
327    public String JavaDoc getInvokerBinding(String JavaDoc invokerName)
328    {
329       if (invokerBindings == null)
330       {
331          defaultInvokerBindings();
332       }
333
334       return (String JavaDoc)invokerBindings.get(invokerName);
335    }
336
337    public void addInvokerBinding(String JavaDoc bindingName, String JavaDoc jndiName)
338    {
339       if(invokerBindings == null)
340       {
341          invokerBindings = new HashMap JavaDoc();
342       }
343       invokerBindings.put(bindingName, jndiName);
344    }
345
346    public EjbRefMetaData getEjbRefByName(String JavaDoc name)
347    {
348       return (EjbRefMetaData)ejbReferences.get(name);
349    }
350
351    public EjbLocalRefMetaData getEjbLocalRefByName(String JavaDoc name)
352    {
353       return (EjbLocalRefMetaData)ejbLocalReferences.get(name);
354    }
355
356    public Iterator JavaDoc getEnvironmentEntries()
357    {
358       return environmentEntries.iterator();
359    }
360
361    public void addEnvironmentEntry(EnvEntryMetaData envEntry)
362    {
363       environmentEntries.add(envEntry);
364    }
365
366    public Iterator JavaDoc getSecurityRoleReferences()
367    {
368       return securityRoleReferences.iterator();
369    }
370
371    public Iterator JavaDoc 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 JavaDoc refName)
382    {
383       return (ResourceRefMetaData)resourceReferences.get(refName);
384    }
385
386    public Iterator JavaDoc 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 JavaDoc refName)
397    {
398       return (ResourceEnvRefMetaData)resourceEnvReferences.get(refName);
399    }
400
401    public Iterator JavaDoc 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 JavaDoc refName)
412    {
413       return (MessageDestinationRefMetaData)messageDestinationReferences.get(refName);
414    }
415
416    /**
417     * @return HashMap<ServiceRefMetaData>
418     */

419    public HashMap JavaDoc 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 JavaDoc getJndiName()
430    {
431       // jndiName may be set in jboss.xml
432
if (jndiName == null)
433       {
434          jndiName = ejbName;
435       }
436       return jndiName;
437    }
438
439    /**
440     * Gets the JNDI name under with the local home interface should be bound.
441     * The default is local/&lt;ejbName&gt;
442     */

443    public String JavaDoc getLocalJndiName()
444    {
445       if (localJndiName == null)
446       {
447          // Generate a unique name based on ejbName + identityHashCode
448
localJndiName = "local/" + ejbName + '@' + System.identityHashCode(ejbName);
449       }
450       return localJndiName;
451    }
452
453    /**
454     * Gets the container jndi name used in the object name
455     */

456    public String JavaDoc getContainerObjectNameJndiName()
457    {
458       return getHome() != null ? getJndiName() : getLocalJndiName();
459    }
460
461    public String JavaDoc 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 JavaDoc configName = getConfigurationName();
475          configuration = application.getConfigurationMetaDataByName(configName);
476          if (configuration == null)
477             throw new IllegalStateException JavaDoc("Container config not found " + configName);
478       }
479       return configuration;
480    }
481
482    public String JavaDoc 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 JavaDoc getDefaultConfigurationName();
508
509    public Iterator JavaDoc getTransactionMethods()
510    {
511       return transactionMethods.iterator();
512    }
513
514    public Iterator JavaDoc getPermissionMethods()
515    {
516       return permissionMethods.iterator();
517    }
518
519    public Iterator JavaDoc 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       // Insert unchecked methods into the front of the list to speed
532
// up their validation
533
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 JavaDoc methodName, Class JavaDoc[] params, InvocationType iface)
549    {
550       // default value
551
byte result = TX_UNKNOWN;
552
553       MethodMetaData bestMatch = null;
554       Iterator JavaDoc iterator = getTransactionMethods();
555       while (iterator.hasNext())
556       {
557          MethodMetaData m = (MethodMetaData)iterator.next();
558          if (m.patternMatches(methodName, params, iface))
559          {
560
561             // this is the first match
562
if (bestMatch == null)
563             {
564                bestMatch = m;
565             }
566             else
567             {
568                // this is a better match because the name is more precise
569
if (bestMatch.getMethodName().equals("*"))
570                {
571                   bestMatch = m;
572                }
573                // this is a better match because now we have parameters, we cant get any better
574
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    // This should be cached, since this method is called very often
592
public byte getTransactionMethod(Method JavaDoc m, InvocationType iface)
593    {
594       if (m == null)
595          return MetaData.TX_SUPPORTS;
596
597       Byte JavaDoc b = (Byte JavaDoc)methodTx.get(m);
598       if (b != null) return b.byteValue();
599
600       byte result = getMethodTransactionType(m.getName(), m.getParameterTypes(), iface);
601
602       // provide default if method is not found in descriptor
603
if (result == MetaData.TX_UNKNOWN)
604          result = MetaData.TX_REQUIRED;
605
606       methodTx.put(m, new Byte JavaDoc(result));
607       return result;
608    }
609
610    public Collection JavaDoc getDepends()
611    {
612       Collection JavaDoc allDepends = new LinkedList JavaDoc(depends);
613       allDepends.addAll(getContainerConfiguration().getDepends());
614       return allDepends;
615    }
616
617    /**
618     * Checks meta data to obtain the Method Attributes of a bean's method:
619     * method attributes are read-only, idempotent and potentially other
620     * ones as well.
621     * These jboss-specific method attributes are described in jboss.xml
622     */

623    private MethodAttributes methodAttributesForMethod(String JavaDoc 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 JavaDoc 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    /**
653     * Is this method a read-only method described in jboss.xml?
654     */

655    public boolean isMethodReadOnly(String JavaDoc methodName)
656    {
657       return methodAttributesForMethod(methodName).readOnly;
658    }
659
660    public boolean isMethodReadOnly(Method JavaDoc method)
661    {
662       if (method == null)
663       {
664          return false;
665       }
666       return methodAttributesForMethod(method.getName()).readOnly;
667    }
668
669    /**
670     * Get the transaction timeout for the method
671     */

672    public int getTransactionTimeout(String JavaDoc methodName)
673    {
674       return methodAttributesForMethod(methodName).txTimeout;
675    }
676
677    public int getTransactionTimeout(Method JavaDoc method)
678    {
679       if (method == null)
680          return 0;
681       return getTransactionTimeout(method.getName());
682    }
683
684    /**
685     * A somewhat tedious method that builds a Set<Principal> of the roles
686     * that have been assigned permission to execute the indicated method. The
687     * work performed is tedious because of the wildcard style of declaring
688     * method permission allowed in the ejb-jar.xml descriptor. This method is
689     * called by the Container.getMethodPermissions() when it fails to find the
690     * prebuilt set of method roles in its cache.
691     *
692     * @return The Set<Principal> for the application domain roles that
693     * caller principal's are to be validated against.
694     */

695    public Set JavaDoc getMethodPermissions(String JavaDoc methodName, Class JavaDoc[] params,
696                                    InvocationType iface)
697    {
698       Set JavaDoc result = new HashSet JavaDoc();
699       // First check the excluded method list as this takes priority over
700
// all other assignments
701
Iterator JavaDoc iterator = getExcludedMethods();
702       while (iterator.hasNext())
703       {
704          MethodMetaData m = (MethodMetaData)iterator.next();
705          if (m.patternMatches(methodName, params, iface))
706          {
707             /* No one is allowed to execute this method so add a role that
708                fails to equate to any Principal or Principal name and return.
709                We don't return null to differentiate between an explicit
710                assignment of no access and no assignment information.
711             */

712             result.add(NobodyPrincipal.NOBODY_PRINCIPAL);
713             return result;
714          }
715       }
716
717       // Check the permissioned methods list
718
iterator = getPermissionMethods();
719       while (iterator.hasNext())
720       {
721          MethodMetaData m = (MethodMetaData)iterator.next();
722          if (m.patternMatches(methodName, params, iface))
723          {
724             /* If this is an unchecked method anyone can access it so
725                set the result set to a role that equates to any Principal or
726                Principal name and return.
727             */

728             if (m.isUnchecked())
729             {
730                result.clear();
731                result.add(AnybodyPrincipal.ANYBODY_PRINCIPAL);
732                break;
733             }
734             // Else, add all roles
735
else
736             {
737                Iterator JavaDoc rolesIterator = m.getRoles().iterator();
738                while (rolesIterator.hasNext())
739                {
740                   String JavaDoc roleName = (String JavaDoc)rolesIterator.next();
741                   result.add(new SimplePrincipal(roleName));
742                }
743             }
744          }
745       }
746
747       if (this.isExcludeMissingMethods() == false)
748       {
749          // If no permissions were assigned to the method, anybody can access it
750
if (result.isEmpty())
751          {
752             result.add(AnybodyPrincipal.ANYBODY_PRINCIPAL);
753          }
754       }
755
756       return result;
757    }
758
759    /** Check to see if there was a method-permission or exclude-list statement
760     * for the given method.
761     *
762     * @param methodName - the method name
763     * @param params - the method parameter signature
764     * @param iface - the method interface type
765     * @return true if a matching method permission exists, false if no match
766     */

767    public boolean hasMethodPermission(String JavaDoc methodName, Class JavaDoc[] params,
768                                       InvocationType iface)
769    {
770       // First check the excluded method list as this takes priority
771
Iterator JavaDoc 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       // Check the permissioned methods list
782
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    // Cluster configuration methods
796
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          /* All beans associated with a container are the same type
821             so this can be done more than once without harm */

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 JavaDoc 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 JavaDoc localClass)
878    {
879       this.localClass = localClass;
880    }
881
882    public void setLocalHome(String JavaDoc localHomeClass)
883    {
884       this.localHomeClass = localHomeClass;
885    }
886
887    public ArrayList JavaDoc getMethodAttributes()
888    {
889       return methodAttributes;
890    }
891
892    public void setMethodAttributes(ArrayList JavaDoc 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 JavaDoc remoteClass)
908    {
909       this.remoteClass = remoteClass;
910    }
911
912    public String JavaDoc getServiceEndpointClass()
913    {
914       return serviceEndpointClass;
915    }
916
917    public void setServiceEndpointClass(String JavaDoc 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
932    public void setConfigurationName(String JavaDoc configurationName)
933    {
934       this.configurationName = configurationName;
935    }
936
937    public void setContainerManagedTx(boolean containerManagedTx)
938    {
939       this.containerManagedTx = containerManagedTx;
940    }
941
942    public void setDepends(Collection JavaDoc depends)
943    {
944       this.depends = depends;
945    }
946
947    public void setEjbClass(String JavaDoc ejbClass)
948    {
949       this.ejbClass = ejbClass;
950    }
951
952    public void setEjbLocalReferences(HashMap JavaDoc ejbLocalReferences)
953    {
954       this.ejbLocalReferences = ejbLocalReferences;
955    }
956
957    public void setEjbReferences(HashMap JavaDoc ejbReferences)
958    {
959       this.ejbReferences = ejbReferences;
960    }
961
962    public void setEjbTimeoutIdentity(SecurityIdentityMetaData ejbTimeoutIdentity)
963    {
964       this.ejbTimeoutIdentity = ejbTimeoutIdentity;
965    }
966
967    public void setEnvironmentEntries(ArrayList JavaDoc environmentEntries)
968    {
969       this.environmentEntries = environmentEntries;
970    }
971
972    public void setExceptionRollback(boolean exceptionRollback)
973    {
974       this.exceptionRollback = exceptionRollback;
975    }
976
977    public void setExcludedMethods(ArrayList JavaDoc excludedMethods)
978    {
979       this.excludedMethods = excludedMethods;
980    }
981
982    public void setInvokerBindings(HashMap JavaDoc invokerBindings)
983    {
984       this.invokerBindings = invokerBindings;
985    }
986
987    public void setJndiName(String JavaDoc jndiName)
988    {
989       this.jndiName = jndiName;
990    }
991
992    public void setLocalJndiName(String JavaDoc localJndiName)
993    {
994       this.localJndiName = localJndiName;
995    }
996
997    public void setMessageDestinationReferences(HashMap JavaDoc messageDestinationReferences)
998    {
999       this.messageDestinationReferences = messageDestinationReferences;
1000   }
1001
1002   public void setPermissionMethods(ArrayList JavaDoc permissionMethods)
1003   {
1004      this.permissionMethods = permissionMethods;
1005   }
1006
1007   public void setResourceEnvReferences(HashMap JavaDoc resourceEnvReferences)
1008   {
1009      this.resourceEnvReferences = resourceEnvReferences;
1010   }
1011
1012   public void setResourceReferences(HashMap JavaDoc resourceReferences)
1013   {
1014      this.resourceReferences = resourceReferences;
1015   }
1016
1017   public void setSecurityProxy(String JavaDoc securityProxy)
1018   {
1019      this.securityProxy = securityProxy;
1020   }
1021
1022   public void setSecurityRoleReferences(ArrayList JavaDoc securityRoleReferences)
1023   {
1024      this.securityRoleReferences = securityRoleReferences;
1025   }
1026
1027   public void setServiceReferences(HashMap JavaDoc serviceReferences)
1028   {
1029      this.serviceReferences = serviceReferences;
1030   }
1031
1032   public void setTimerPersistence(boolean timerPersistence)
1033   {
1034      this.timerPersistence = timerPersistence;
1035   }
1036
1037   public void setTransactionMethods(ArrayList JavaDoc transactionMethods)
1038   {
1039      this.transactionMethods = transactionMethods;
1040   }
1041
1042   /** Called to parse the ejb-jar.xml enterprise-beans child ejb elements
1043    * @param element one of session/entity/message-driven
1044    * @throws DeploymentException
1045    */

1046   public void importEjbJarXml(Element JavaDoc element)
1047      throws DeploymentException
1048   {
1049      // set the ejb-name
1050
ejbName = getElementContent(getUniqueChild(element, "ejb-name"));
1051
1052      // Set the interfaces classes for all types but MessageDriven
1053
if (isMessageDriven() == false)
1054      {
1055         homeClass = getElementContent(getOptionalChild(element, "home"));
1056         remoteClass = getElementContent(getOptionalChild(element, "remote"));
1057         localHomeClass = getElementContent(getOptionalChild(element,
1058            "local-home"));
1059         localClass = getElementContent(getOptionalChild(element, "local"));
1060      }
1061      ejbClass = getElementContent(getUniqueChild(element, "ejb-class"));
1062
1063      // set the environment entries
1064
Iterator JavaDoc iterator = getChildrenByTagName(element, "env-entry");
1065
1066      while (iterator.hasNext())
1067      {
1068         Element JavaDoc envEntry = (Element JavaDoc)iterator.next();
1069
1070         EnvEntryMetaData envEntryMetaData = new EnvEntryMetaData();
1071         envEntryMetaData.importEjbJarXml(envEntry);
1072
1073         environmentEntries.add(envEntryMetaData);
1074      }
1075
1076      // set the ejb references
1077
iterator = getChildrenByTagName(element, "ejb-ref");
1078
1079      while (iterator.hasNext())
1080      {
1081         Element JavaDoc ejbRef = (Element JavaDoc)iterator.next();
1082
1083         EjbRefMetaData ejbRefMetaData = new EjbRefMetaData();
1084         ejbRefMetaData.importEjbJarXml(ejbRef);
1085
1086         ejbReferences.put(ejbRefMetaData.getName(), ejbRefMetaData);
1087      }
1088
1089      // set the ejb local references
1090
iterator = getChildrenByTagName(element, "ejb-local-ref");
1091
1092      while (iterator.hasNext())
1093      {
1094         Element JavaDoc ejbLocalRef = (Element JavaDoc)iterator.next();
1095
1096         EjbLocalRefMetaData ejbLocalRefMetaData = new EjbLocalRefMetaData();
1097         ejbLocalRefMetaData.importEjbJarXml(ejbLocalRef);
1098
1099         ejbLocalReferences.put(ejbLocalRefMetaData.getName(),
1100            ejbLocalRefMetaData);
1101      }
1102
1103      // Parse the service-ref elements
1104
iterator = MetaData.getChildrenByTagName(element, "service-ref");
1105      while (iterator.hasNext())
1106      {
1107         Element JavaDoc serviceRef = (Element JavaDoc)iterator.next();
1108         if (ServiceRefMetaData.isValidDoctype(serviceRef))
1109         {
1110            ServiceRefMetaData refMetaData = new ServiceRefMetaData(application.getResourceCl());
1111            refMetaData.importStandardXml(serviceRef);
1112            serviceReferences.put(refMetaData.getServiceRefName(), refMetaData);
1113         }
1114      }
1115
1116      // set the security roles references
1117
iterator = getChildrenByTagName(element, "security-role-ref");
1118
1119      while (iterator.hasNext())
1120      {
1121         Element JavaDoc secRoleRef = (Element JavaDoc)iterator.next();
1122         SecurityRoleRefMetaData securityRoleRefMetaData = new SecurityRoleRefMetaData();
1123         securityRoleRefMetaData.importEjbJarXml(secRoleRef);
1124         securityRoleReferences.add(securityRoleRefMetaData);
1125      }
1126
1127      // The security-identity element
1128
Element JavaDoc securityIdentityElement = getOptionalChild(element,
1129         "security-identity");
1130      if (securityIdentityElement != null)
1131      {
1132         securityIdentity = new SecurityIdentityMetaData();
1133         securityIdentity.importEjbJarXml(securityIdentityElement);
1134      }
1135
1136      // set the resource references
1137
iterator = getChildrenByTagName(element, "resource-ref");
1138
1139      while (iterator.hasNext())
1140      {
1141         Element JavaDoc resourceRef = (Element JavaDoc)iterator.next();
1142
1143         ResourceRefMetaData resourceRefMetaData = new ResourceRefMetaData();
1144         resourceRefMetaData.importEjbJarXml(resourceRef);
1145
1146         resourceReferences.put(resourceRefMetaData.getRefName(),
1147            resourceRefMetaData);
1148      }
1149
1150      // Parse the resource-env-ref elements
1151
iterator = getChildrenByTagName(element, "resource-env-ref");
1152      while (iterator.hasNext())
1153      {
1154         Element JavaDoc resourceRef = (Element JavaDoc)iterator.next();
1155         ResourceEnvRefMetaData refMetaData = new ResourceEnvRefMetaData();
1156         refMetaData.importEjbJarXml(resourceRef);
1157         resourceEnvReferences.put(refMetaData.getRefName(), refMetaData);
1158      }
1159
1160      // set the message destination references
1161
iterator = getChildrenByTagName(element, "message-destination-ref");
1162      while (iterator.hasNext())
1163      {
1164         Element JavaDoc messageDestinationRef = (Element JavaDoc)iterator.next();
1165
1166         MessageDestinationRefMetaData messageDestinationRefMetaData = new MessageDestinationRefMetaData();
1167         messageDestinationRefMetaData.importEjbJarXml(messageDestinationRef);
1168
1169         messageDestinationReferences.put(messageDestinationRefMetaData.getRefName(), messageDestinationRefMetaData);
1170      }
1171   }
1172
1173   /** Called to parse the jboss.xml enterprise-beans child ejb elements
1174    * @param element one of session/entity/message-driven
1175    * @throws DeploymentException
1176    */

1177   public void importJbossXml(Element JavaDoc element) throws DeploymentException
1178   {
1179      // we must not set defaults here, this might never be called
1180

1181      // set the jndi name, (optional)
1182
jndiName = getElementContent(getOptionalChild(element, "jndi-name"));
1183
1184      // set the JNDI name under with the local home interface should be
1185
// bound (optional)
1186
localJndiName = getElementContent(getOptionalChild(element, "local-jndi-name"));
1187
1188      // Determine if the bean should use by value call semantics
1189
String JavaDoc callByValueElt = getElementContent(getOptionalChild(element, "call-by-value"), (callByValue ? "True" : "False"));
1190      callByValue = callByValueElt.equalsIgnoreCase("True");
1191
1192      // set the configuration (optional)
1193
configurationName = getElementContent(getOptionalChild(element, "configuration-name"));
1194      if (configurationName != null && getApplicationMetaData().getConfigurationMetaDataByName(configurationName) == null)
1195      {
1196         throw new DeploymentException("configuration '" + configurationName + "' not found in standardjboss.xml or jboss.xml");
1197      }
1198
1199      // Get the security proxy
1200
securityProxy = getElementContent(getOptionalChild(element, "security-proxy"), securityProxy);
1201
1202      // Throw an exception when marked rollback with no exception thrown
1203
exceptionRollback = MetaData.getOptionalChildBooleanContent(element, "exception-on-rollback", false);
1204
1205      // Whether to persist ejb timers across redeployments
1206
timerPersistence = MetaData.getOptionalChildBooleanContent(element, "timer-persistence", true);
1207      
1208      // update the resource references (optional)
1209
Iterator JavaDoc iterator = getChildrenByTagName(element, "resource-ref");
1210      while (iterator.hasNext())
1211      {
1212         Element JavaDoc resourceRef = (Element JavaDoc)iterator.next();
1213         String JavaDoc resRefName = getElementContent(getUniqueChild(resourceRef, "res-ref-name"));
1214         ResourceRefMetaData resourceRefMetaData = (ResourceRefMetaData)resourceReferences.get(resRefName);
1215
1216         if (resourceRefMetaData == null)
1217         {
1218            throw new DeploymentException("resource-ref " + resRefName + " found in jboss.xml but not in ejb-jar.xml");
1219         }
1220         resourceRefMetaData.importJbossXml(resourceRef);
1221      }
1222
1223      // Set the resource-env-ref deployed jndi names
1224
iterator = getChildrenByTagName(element, "resource-env-ref");
1225      while (iterator.hasNext())
1226      {
1227         Element JavaDoc resourceRef = (Element JavaDoc)iterator.next();
1228         String JavaDoc resRefName = getElementContent(getUniqueChild(resourceRef, "resource-env-ref-name"));
1229         ResourceEnvRefMetaData refMetaData = (ResourceEnvRefMetaData)resourceEnvReferences.get(resRefName);
1230         if (refMetaData == null)
1231         {
1232            throw new DeploymentException("resource-env-ref " + resRefName + " found in jboss.xml but not in ejb-jar.xml");
1233         }
1234         refMetaData.importJbossXml(resourceRef);
1235      }
1236
1237      // update the message destination references (optional)
1238
iterator = getChildrenByTagName(element, "message-destination-ref");
1239      while (iterator.hasNext())
1240      {
1241         Element JavaDoc messageDestinationRef = (Element JavaDoc)iterator.next();
1242         String JavaDoc messageDestinationRefName = getElementContent(getUniqueChild(messageDestinationRef, "message-destination-ref-name"));
1243         MessageDestinationRefMetaData messageDestinationRefMetaData = (MessageDestinationRefMetaData)messageDestinationReferences.get(messageDestinationRefName);
1244         if (messageDestinationRefMetaData == null)
1245            throw new DeploymentException("message-destination-ref " + messageDestinationRefName + " found in jboss.xml but not in ejb-jar.xml");
1246         messageDestinationRefMetaData.importJbossXml(messageDestinationRef);
1247      }
1248
1249      // set the external ejb-references (optional)
1250
iterator = getChildrenByTagName(element, "ejb-ref");
1251      while (iterator.hasNext())
1252      {
1253         Element JavaDoc ejbRef = (Element JavaDoc)iterator.next();
1254         String JavaDoc ejbRefName = getElementContent(getUniqueChild(ejbRef, "ejb-ref-name"));
1255         EjbRefMetaData ejbRefMetaData = getEjbRefByName(ejbRefName);
1256         if (ejbRefMetaData == null)
1257         {
1258            throw new DeploymentException("ejb-ref " + ejbRefName + " found in jboss.xml but not in ejb-jar.xml");
1259         }
1260         ejbRefMetaData.importJbossXml(ejbRef);
1261      }
1262
1263
1264      //handle the ejb-local-ref elements
1265
iterator = getChildrenByTagName(element, "ejb-local-ref");
1266      while (iterator.hasNext())
1267      {
1268         Element JavaDoc ejbLocalRef = (Element JavaDoc)iterator.next();
1269         String JavaDoc ejbLocalRefName = getElementContent(getUniqueChild(ejbLocalRef, "ejb-ref-name"));
1270
1271         EjbLocalRefMetaData ejbLocalRefMetaData = getEjbLocalRefByName(ejbLocalRefName);
1272         if (ejbLocalRefMetaData == null)
1273         {
1274            throw new DeploymentException("ejb-local-ref " + ejbLocalRefName + " found in jboss.xml but not in ejb-jar.xml");
1275         }
1276         ejbLocalRefMetaData.importJbossXml(ejbLocalRef);
1277      }
1278
1279      // Parse the service-ref elements
1280
iterator = MetaData.getChildrenByTagName(element, "service-ref");
1281      while (iterator.hasNext())
1282      {
1283         Element JavaDoc serviceRef = (Element JavaDoc)iterator.next();
1284         String JavaDoc serviceRefName = MetaData.getUniqueChildContent(serviceRef, "service-ref-name");
1285         ServiceRefMetaData refMetaData = (ServiceRefMetaData)serviceReferences.get(serviceRefName);
1286         if (refMetaData == null && ServiceRefMetaData.isValidDoctype(serviceRef))
1287         {
1288            throw new DeploymentException("service-ref " + serviceRefName + " found in jboss.xml but not in ejb-jar.xml");
1289         }
1290         if (refMetaData != null)
1291            refMetaData.importJBossXml(serviceRef);
1292      }
1293
1294      // Get the security identity
1295
Element JavaDoc securityIdentityElement = getOptionalChild(element, "security-identity");
1296      if (securityIdentityElement != null)
1297      {
1298         if (securityIdentity == null)
1299            throw new DeploymentException(ejbName + ", security-identity in jboss.xml has no match in ejb-jar.xml");
1300         String JavaDoc runAsPrincipal = getElementContent(getUniqueChild(securityIdentityElement,
1301            "run-as-principal"), securityIdentity.getRunAsPrincipalName());
1302         securityIdentity.setRunAsPrincipalName(runAsPrincipal);
1303      }
1304
1305      // Get the ejbTimeout caller identity
1306
Element JavaDoc ejbTimeoutIdentityElement = getOptionalChild(element, "ejb-timeout-identity");
1307      if (ejbTimeoutIdentityElement != null)
1308      {
1309         ejbTimeoutIdentity = new SecurityIdentityMetaData();
1310         String JavaDoc runAsPrincipal = getElementContent(getUniqueChild(ejbTimeoutIdentityElement,
1311                 "run-as-principal"), null);
1312         ejbTimeoutIdentity.setRunAsRoleName("ejbTimeout");
1313         if( runAsPrincipal != null && runAsPrincipal.length() > 0 )
1314            ejbTimeoutIdentity.setRunAsPrincipalName(runAsPrincipal);
1315         else
1316            ejbTimeoutIdentity.setUseCallerIdentity(true);
1317      }
1318
1319      // Method attributes of the bean
1320
Element JavaDoc mas = getOptionalChild(element, "method-attributes");
1321      if (mas != null)
1322      {
1323         // read in the read-only methods
1324
iterator = getChildrenByTagName(mas, "method");
1325         while (iterator.hasNext())
1326         {
1327            MethodAttributes ma = new MethodAttributes();
1328            Element JavaDoc maNode = (Element JavaDoc)iterator.next();
1329            ma.pattern = getElementContent(getUniqueChild(maNode, "method-name"));
1330            ma.readOnly = getOptionalChildBooleanContent(maNode, "read-only");
1331            ma.idempotent = getOptionalChildBooleanContent(maNode, "idempotent");
1332            String JavaDoc txTimeout = getOptionalChildContent(maNode, "transaction-timeout");
1333            try
1334            {
1335               if (txTimeout != null && txTimeout.length() > 0)
1336                  ma.txTimeout = Integer.parseInt(txTimeout);
1337            }
1338            catch (Exception JavaDoc ignore)
1339            {
1340               log.debug("Ignoring transaction-timeout '" + txTimeout + "'", ignore);
1341            }
1342            methodAttributes.add(ma);
1343         }
1344      }
1345
1346      // Invokers
1347
// If no invoker bindings have been defined they will be defined
1348
// in EntityMetaData, or SessionMetaData
1349
Element JavaDoc inv = getOptionalChild(element, "invoker-bindings");
1350      if (inv != null)
1351      {
1352         // read in the read-only methods
1353
iterator = getChildrenByTagName(inv, "invoker");
1354         invokerBindings = new HashMap JavaDoc();
1355         while (iterator.hasNext())
1356         {
1357            Element JavaDoc node = (Element JavaDoc)iterator.next();
1358            String JavaDoc invokerBindingName = getUniqueChildContent(node, "invoker-proxy-binding-name");
1359            String JavaDoc jndiBinding = getOptionalChildContent(node, "jndi-name");
1360
1361            if (jndiBinding == null)
1362            {
1363               jndiBinding = getJndiName(); // default to jndiName
1364
}
1365            invokerBindings.put(invokerBindingName, jndiBinding);
1366
1367            // set the external ejb-references (optional)
1368
Iterator JavaDoc ejbrefiterator = getChildrenByTagName(node, "ejb-ref");
1369            while (ejbrefiterator.hasNext())
1370            {
1371               Element JavaDoc ejbRef = (Element JavaDoc)ejbrefiterator.next();
1372               String JavaDoc ejbRefName = getElementContent(getUniqueChild(ejbRef, "ejb-ref-name"));
1373               EjbRefMetaData ejbRefMetaData = getEjbRefByName(ejbRefName);
1374               if (ejbRefMetaData == null)
1375               {
1376                  throw new DeploymentException("ejb-ref " + ejbRefName + " found in jboss.xml but not in ejb-jar.xml");
1377               }
1378               ejbRefMetaData.importJbossXml(invokerBindingName, ejbRef);
1379            }
1380         }
1381      }
1382
1383      // Determine if the bean is to be deployed in the cluster (more
1384
// advanced config will be added in the future)
1385
String JavaDoc clusteredElt = getElementContent(getOptionalChild(element, "clustered"), (clustered ? "True" : "False"));
1386      clustered = clusteredElt.equalsIgnoreCase("True");
1387
1388      Element JavaDoc clusterConfigElement = getOptionalChild(element, "cluster-config");
1389      if (clusterConfigElement != null)
1390      {
1391         this.clusterConfig = new ClusterConfigMetaData();
1392         clusterConfig.init(this);
1393         clusterConfig.importJbossXml(clusterConfigElement);
1394      }
1395
1396      //Get depends object names
1397
for (Iterator JavaDoc dependsElements = getChildrenByTagName(element, "depends"); dependsElements.hasNext();)
1398      {
1399         Element JavaDoc dependsElement = (Element JavaDoc)dependsElements.next();
1400         String JavaDoc dependsName = getElementContent(dependsElement);
1401         depends.add(ObjectNameFactory.create(dependsName));
1402      } // end of for ()
1403

1404      // ior-security-config optional element
1405
Element JavaDoc iorSecurityConfigEl = getOptionalChild(element, "ior-security-config");
1406      if (iorSecurityConfigEl != null)
1407      {
1408         iorSecurityConfig = new IorSecurityConfigMetaData(iorSecurityConfigEl);
1409      }
1410
1411   }
1412}
1413
Popular Tags