KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > EjbDescriptor


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.deployment;
25
26 import java.util.*;
27 import java.lang.reflect.Method JavaDoc;
28 import java.lang.reflect.Field JavaDoc;
29 import java.util.logging.*;
30 import com.sun.logging.*;
31
32 import static com.sun.enterprise.deployment.LifecycleCallbackDescriptor.CallbackType;
33 import static com.sun.enterprise.deployment.LifecycleCallbackDescriptor.CallbackType.*;
34 import com.sun.enterprise.deployment.types.EjbReference;
35 import com.sun.enterprise.deployment.types.EjbReferenceContainer;
36 import com.sun.enterprise.deployment.types.ResourceEnvReferenceContainer;
37 import com.sun.enterprise.deployment.types.ResourceReferenceContainer;
38 import com.sun.enterprise.deployment.types.ServiceReferenceContainer;
39 import com.sun.enterprise.deployment.types.MessageDestinationReference;
40 import com.sun.enterprise.deployment.types.MessageDestinationReferencer;
41 import com.sun.enterprise.deployment.types.MessageDestinationReferenceContainer;
42
43 import com.sun.enterprise.util.BeanMethodCalculator;
44 import com.sun.enterprise.util.LocalStringManagerImpl;
45 import com.sun.enterprise.deployment.util.LogDomains;
46
47 // Ludo 12/10/2001: IAS specific info needed here because we cannot have multi-inheritance in Java and that iAS specific
48
// info is needed in some/all of the sub-classes of EjBDescriptor:
49
import com.sun.enterprise.deployment.runtime.IASEjbExtraDescriptors;
50
51
52 import com.sun.enterprise.deployment.util.EjbVisitor;
53 import com.sun.enterprise.deployment.util.DescriptorVisitor;
54 import com.sun.enterprise.deployment.util.InterceptorBindingTranslator;
55 import com.sun.enterprise.deployment.util.InterceptorBindingTranslator.TranslationResults;
56
57 /**
58  * This abstract class encapsulates the meta-information describing
59  * Entity, Session and MessageDriven EJBs.
60  *
61  * @author Danny Coward
62  * @author Sanjeev Krishnan
63  */

64
65 public abstract class EjbDescriptor extends EjbAbstractDescriptor
66     implements WritableJndiNameEnvironment,
67                 EjbReferenceContainer,
68                 ResourceEnvReferenceContainer,
69                 ResourceReferenceContainer,
70                 ServiceReferenceContainer,
71                 MessageDestinationReferenceContainer
72 {
73     /** Indicates the bean will manage its own transactions.*/
74     final public static String JavaDoc BEAN_TRANSACTION_TYPE = "Bean";
75     /** Indicates the bean expects the server to manage its transactions.*/
76     final public static String JavaDoc CONTAINER_TRANSACTION_TYPE = "Container";
77
78     // Used in <transaction-scope> element in XML
79
final public static String JavaDoc LOCAL_TRANSACTION_SCOPE = "Local";
80     final public static String JavaDoc DISTRIBUTED_TRANSACTION_SCOPE = "Distributed";
81
82     protected String JavaDoc transactionType = null;
83     protected boolean usesDefaultTransaction = false;
84     private Hashtable methodContainerTransactions = null;
85     private Hashtable permissionedMethodsByPermission = null;
86     private HashMap methodPermissionsFromDD = null;
87     private Set<EnvironmentProperty> environmentProperties =
88             new HashSet<EnvironmentProperty>();
89     private Set<EjbReference> ejbReferences =
90             new HashSet<EjbReference>();
91     private Set<JmsDestinationReferenceDescriptor> jmsDestReferences =
92             new HashSet<JmsDestinationReferenceDescriptor>();
93     private Set<MessageDestinationReferenceDescriptor> messageDestReferences =
94             new HashSet<MessageDestinationReferenceDescriptor>();
95     private Set<ResourceReferenceDescriptor> resourceReferences =
96             new HashSet<ResourceReferenceDescriptor>();
97     private Set<ServiceReferenceDescriptor> serviceReferences =
98             new HashSet<ServiceReferenceDescriptor>();
99
100     private Set<LifecycleCallbackDescriptor> postConstructDescs =
101         new HashSet<LifecycleCallbackDescriptor>();
102     private Set<LifecycleCallbackDescriptor> preDestroyDescs =
103         new HashSet<LifecycleCallbackDescriptor>();
104     private Set<LifecycleCallbackDescriptor> aroundInvokeDescs =
105         new HashSet<LifecycleCallbackDescriptor>();
106
107     private Set<EntityManagerFactoryReferenceDescriptor>
108         entityManagerFactoryReferences =
109         new HashSet<EntityManagerFactoryReferenceDescriptor>();
110
111     private Set<EntityManagerReferenceDescriptor>
112         entityManagerReferences =
113         new HashSet<EntityManagerReferenceDescriptor>();
114
115     private Set roleReferences = new HashSet();
116     private EjbBundleDescriptor bundleDescriptor;
117     // private EjbIORConfigurationDescriptor iorConfigDescriptor = new EjbIORConfigurationDescriptor();
118
private Set iorConfigDescriptors = new OrderedSet();
119     //private Set methodDescriptors = new HashSet();
120
private String JavaDoc ejbClassName;
121
122     // EjbRefs from all components in this app who point to me
123
private Set ejbReferencersPointingToMe = new HashSet();
124
125     // For EJB2.0
126
protected Boolean JavaDoc usesCallerIdentity = null;
127     protected String JavaDoc securityIdentityDescription;
128     protected boolean isDistributedTxScope = true;
129     protected RunAsIdentityDescriptor runAsIdentity = null;
130
131     // sets of method descriptor that can be of style 1 or style 2
132
// we initialize it so we force at least on method conversion
133
// to fill up unspecified method with the unchecked permission
134
private Map styledMethodDescriptors = new HashMap();
135     
136     private long uniqueId;
137     private String JavaDoc remoteHomeImplClassName;
138     private String JavaDoc ejbObjectImplClassName;
139     private String JavaDoc localHomeImplClassName;
140     private String JavaDoc ejbLocalObjectImplClassName;
141
142     private MethodDescriptor timedObjectMethod;
143
144
145     //
146
// The set of all interceptor classes applicable to this bean. This
147
// includes any interceptor class that is present at *either* the class
148
// level or method-level.
149
//
150
private Set<EjbInterceptor> allInterceptorClasses =
151         new HashSet<EjbInterceptor>();
152
153     // Ordered list of class-level interceptors for this bean.
154
private List<EjbInterceptor> interceptorChain =
155         new LinkedList<EjbInterceptor>();
156
157     //
158
// Interceptor info per business method. If the map does not
159
// contain an entry for the business method, there is no method-specific
160
// interceptor information for that method. In that case the standard
161
// class-level interceptor information applies.
162
//
163
// If there is an entry for the business method, the corresponding list
164
// represents the *complete* ordered list of interceptor classes for that
165
// method. An empty list would mean all the interceptors have been
166
// disabled for that particular business method.
167
//
168
private Map<MethodDescriptor, List<EjbInterceptor>> methodInterceptorsMap =
169         new HashMap<MethodDescriptor, List<EjbInterceptor>>();
170     
171     private static LocalStringManagerImpl localStrings =
172         new LocalStringManagerImpl(EjbDescriptor.class);
173
174     static Logger _logger = LogDomains.getLogger(LogDomains.DPL_LOGGER);
175
176     private IASEjbExtraDescriptors iASEjbExtraDescriptors= new IASEjbExtraDescriptors(); // Ludo 12/10/2001 extra DTD info only for iAS
177

178     /**
179      * returns the extra iAS specific info (not in the RI DID) in the iAS DTD.
180      * no setter. You have to modify some fields of the returned object to change it.
181      * TODO: check if we need to clone it in the Copy Constructor...
182      */

183     public IASEjbExtraDescriptors getIASEjbExtraDescriptors(){
184         return iASEjbExtraDescriptors;
185     }
186         
187     /**
188      * Default constructor.
189      */

190     protected EjbDescriptor() {
191     }
192     
193     public EjbDescriptor(EjbDescriptor other) {
194     super(other);
195     this.transactionType = other.transactionType;
196     this.methodContainerTransactions = new Hashtable(other.getMethodContainerTransactions());
197     this.permissionedMethodsByPermission = new Hashtable(other.getPermissionedMethodsByPermission());
198     this.getEnvironmentProperties().addAll(other.getEnvironmentProperties());
199     this.getEjbReferenceDescriptors().addAll(other.getEjbReferenceDescriptors());
200     this.getJmsDestinationReferenceDescriptors().addAll(other.getJmsDestinationReferenceDescriptors());
201         this.getMessageDestinationReferenceDescriptors().addAll(other.getMessageDestinationReferenceDescriptors());
202     this.getResourceReferenceDescriptors().addAll(other.getResourceReferenceDescriptors());
203         this.getServiceReferenceDescriptors().addAll(other.getServiceReferenceDescriptors());
204     this.getRoleReferences().addAll(other.getRoleReferences());
205     this.getIORConfigurationDescriptors().addAll(other.getIORConfigurationDescriptors());
206     this.transactionType = other.transactionType;
207     this.ejbClassName = other.ejbClassName;
208         this.usesCallerIdentity = other.usesCallerIdentity;
209         this.bundleDescriptor = other.bundleDescriptor;
210     }
211
212     /**
213      * Sets the classname of the ejb.
214      */

215     public void setEjbClassName(String JavaDoc ejbClassName) {
216     this.ejbClassName = ejbClassName;
217     }
218     /**
219      * Returns the classname of the ejb.
220      */

221     public String JavaDoc getEjbClassName() {
222     return this.ejbClassName;
223     }
224     /** IASRI 4725194
225      * Returns the Execution class ,which is same as the user-specified class
226      * in case of Message,Session and Bean Managed Persistence Entity Beans
227      * but is different for Container Mananged Persistence Entity Bean
228      * Therefore,the implementation in the base class is to return
229      * getEjbClassName() and the method is redefined in IASEjbCMPDescriptor.
230      *
231      */

232     public String JavaDoc getEjbImplClassName() {
233         return this.getEjbClassName();
234     }
235     
236     /**
237      * Sets the remote home implementation classname of the ejb.
238      */

239     public void setRemoteHomeImplClassName(String JavaDoc name) {
240     this.remoteHomeImplClassName = name;
241     }
242     /**
243      * Returns the classname of the remote home impl.
244      */

245     public String JavaDoc getRemoteHomeImplClassName() {
246     return this.remoteHomeImplClassName;
247     }
248
249     /**
250      * Sets the Local home implementation classname of the ejb.
251      */

252     public void setLocalHomeImplClassName(String JavaDoc name) {
253     this.localHomeImplClassName = name;
254     }
255     /**
256      * Returns the classname of the Local home impl.
257      */

258     public String JavaDoc getLocalHomeImplClassName() {
259     return this.localHomeImplClassName;
260     }
261
262
263     /**
264      * Sets the EJBLocalObject implementation classname of the ejb.
265      */

266     public void setEJBLocalObjectImplClassName(String JavaDoc name) {
267     this.ejbLocalObjectImplClassName = name;
268     }
269     /**
270      * Returns the classname of the EJBLocalObject impl.
271      */

272     public String JavaDoc getEJBLocalObjectImplClassName() {
273     return this.ejbLocalObjectImplClassName;
274     }
275
276
277     /**
278      * Sets the EJBObject implementation classname of the ejb.
279      */

280     public void setEJBObjectImplClassName(String JavaDoc name) {
281     this.ejbObjectImplClassName = name;
282     }
283     /**
284      * Returns the classname of the EJBObject impl.
285      */

286     public String JavaDoc getEJBObjectImplClassName() {
287     return this.ejbObjectImplClassName;
288     }
289
290     /**
291      * The transaction type of this ejb.
292      */

293     public String JavaDoc getTransactionType() {
294     return this.transactionType;
295     }
296     
297     /**
298      * Set the transaction type of this ejb.
299      */

300     public abstract void setTransactionType(String JavaDoc transactionType);
301
302     /**
303      * Returns the set of transaction attributes that can be assigned
304      * to methods of this ejb when in CMT mode. Elements are of type
305      * ContainerTransaction
306      *
307      */

308     public Vector getPossibleTransactionAttributes() {
309         Vector txAttributes = new Vector();
310         txAttributes.add(new ContainerTransaction
311             (ContainerTransaction.MANDATORY, ""));
312         txAttributes.add(new ContainerTransaction
313             (ContainerTransaction.NEVER, ""));
314         txAttributes.add(new ContainerTransaction
315             (ContainerTransaction.NOT_SUPPORTED, ""));
316         txAttributes.add(new ContainerTransaction
317             (ContainerTransaction.REQUIRED, ""));
318         txAttributes.add(new ContainerTransaction
319             (ContainerTransaction.REQUIRES_NEW, ""));
320         txAttributes.add(new ContainerTransaction
321             (ContainerTransaction.SUPPORTS, ""));
322         return txAttributes;
323     }
324
325     public boolean isTimedObject() {
326         return (timedObjectMethod != null);
327     }
328
329     public MethodDescriptor getEjbTimeoutMethod() {
330         return timedObjectMethod;
331     }
332
333     public void setEjbTimeoutMethod(MethodDescriptor method) {
334         timedObjectMethod = method;
335     }
336
337     public Set<LifecycleCallbackDescriptor>
338             getPostConstructDescriptors() {
339         if (postConstructDescs == null) {
340             postConstructDescs =
341                 new HashSet<LifecycleCallbackDescriptor>();
342         }
343         return postConstructDescs;
344     }
345             
346     public void addPostConstructDescriptor(LifecycleCallbackDescriptor
347             postConstructDesc) {
348         String JavaDoc className = postConstructDesc.getLifecycleCallbackClass();
349         boolean found = false;
350         for (LifecycleCallbackDescriptor next :
351              getPostConstructDescriptors()) {
352             if (next.getLifecycleCallbackClass().equals(className)) {
353                 found = true;
354                 break;
355             }
356         }
357         if (!found) {
358             getPostConstructDescriptors().add(postConstructDesc);
359         }
360     }
361
362     public LifecycleCallbackDescriptor
363             getPostConstructDescriptorByClass(String JavaDoc className) {
364         return bundleDescriptor.getPostConstructDescriptorByClass
365             (className, this);
366     }
367
368     public boolean hasPostConstructMethod() {
369         return (getPostConstructDescriptors().size() > 0);
370     }
371
372     public Set<LifecycleCallbackDescriptor>
373             getPreDestroyDescriptors() {
374         if (preDestroyDescs == null) {
375             preDestroyDescs =
376                 new HashSet<LifecycleCallbackDescriptor>();
377         }
378         return preDestroyDescs;
379     }
380             
381     public void addPreDestroyDescriptor(LifecycleCallbackDescriptor
382             preDestroyDesc) {
383         String JavaDoc className = preDestroyDesc.getLifecycleCallbackClass();
384         boolean found = false;
385         for (LifecycleCallbackDescriptor next :
386              getPreDestroyDescriptors()) {
387             if (next.getLifecycleCallbackClass().equals(className)) {
388                 found = true;
389                 break;
390             }
391         }
392         if (!found) {
393             getPreDestroyDescriptors().add(preDestroyDesc);
394         }
395     }
396
397     public LifecycleCallbackDescriptor
398             getPreDestroyDescriptorByClass(String JavaDoc className) {
399         return bundleDescriptor.getPreDestroyDescriptorByClass
400             (className, this);
401     }
402
403     public boolean hasPreDestroyMethod() {
404         return (getPreDestroyDescriptors().size() > 0);
405     }
406
407     public Set<LifecycleCallbackDescriptor> getAroundInvokeDescriptors() {
408         if (aroundInvokeDescs == null) {
409             aroundInvokeDescs =
410                 new HashSet<LifecycleCallbackDescriptor>();
411         }
412         return aroundInvokeDescs;
413     }
414             
415     public void addAroundInvokeDescriptor(LifecycleCallbackDescriptor
416             aroundInvokeDesc) {
417         String JavaDoc className = aroundInvokeDesc.getLifecycleCallbackClass();
418         boolean found = false;
419         for (LifecycleCallbackDescriptor next :
420              getAroundInvokeDescriptors()) {
421             if (next.getLifecycleCallbackClass().equals(className)) {
422                 found = true;
423                 break;
424             }
425         }
426         if (!found) {
427             getAroundInvokeDescriptors().add(aroundInvokeDesc);
428         }
429     }
430
431     public LifecycleCallbackDescriptor
432             getAroundInvokeDescriptorByClass(String JavaDoc className) {
433
434         for (LifecycleCallbackDescriptor next :
435                  getAroundInvokeDescriptors()) {
436             if (next.getLifecycleCallbackClass().equals(className)) {
437                 return next;
438             }
439         }
440         return null;
441     }
442
443     public boolean hasAroundInvokeMethod() {
444         return (getAroundInvokeDescriptors().size() > 0);
445     }
446
447     /**
448      * Since ejb-class is optional, in some cases the lifecycle-class
449      * for AroundInvoke, PostConstruct, etc. methods on the bean-class
450      * is not known at processing time and must be applied lazily. As such,
451      * this method should only be called if the ejb-class has been set
452      * on this EjbDescriptor.
453      */

454     public void applyDefaultClassToLifecycleMethods() {
455         Set<LifecycleCallbackDescriptor> lifecycleMethods =
456             new HashSet<LifecycleCallbackDescriptor>();
457         lifecycleMethods.addAll(getAroundInvokeDescriptors());
458         lifecycleMethods.addAll(getPostConstructDescriptors());
459         lifecycleMethods.addAll(getPreDestroyDescriptors());
460         if( getType().equals(EjbSessionDescriptor.TYPE) ) {
461             EjbSessionDescriptor sfulDesc = (EjbSessionDescriptor) this;
462             lifecycleMethods.addAll(sfulDesc.getPrePassivateDescriptors());
463             lifecycleMethods.addAll(sfulDesc.getPostActivateDescriptors());
464         }
465         for(LifecycleCallbackDescriptor next : lifecycleMethods) {
466             if( next.getLifecycleCallbackClass() == null ) {
467                 next.setLifecycleCallbackClass(getEjbClassName());
468             }
469         }
470     }
471
472     /**
473      * Derive all interceptors that are applicable to this bean.
474      */

475     public void applyInterceptors(InterceptorBindingTranslator
476                                   bindingTranslator) {
477
478         // Apply this ejb to the ordered set of all interceptor bindings
479
// for this ejb-jar. The results will contain all interceptor
480
// information that applies to the ejb. There is no notion of
481
// default interceptors within the results. Default interceptors
482
// are used during the translation process but once we derive
483
// the per-ejb interceptor information there is only a notion of
484
// class-level ordering and method-level ordering. Any applicable
485
// default interceptors will have been applied to the class-level.
486
TranslationResults results = bindingTranslator.apply(getName());
487
488         allInterceptorClasses.clear();
489         allInterceptorClasses.addAll(results.allInterceptorClasses);
490
491         interceptorChain.clear();
492         interceptorChain.addAll(results.classInterceptorChain);
493
494         methodInterceptorsMap.clear();
495         methodInterceptorsMap.putAll(results.methodInterceptorsMap);
496         
497         for (EjbInterceptor interceptor : allInterceptorClasses) {
498             for (Object JavaDoc ejbRefObj : interceptor.getEjbReferenceDescriptors()) {
499                 addEjbReferenceDescriptor((EjbReference)ejbRefObj);
500             }
501
502             for (Object JavaDoc msgDestRefObj :
503                     interceptor.getMessageDestinationReferenceDescriptors()) {
504                 addMessageDestinationReferenceDescriptor(
505                     (MessageDestinationReferenceDescriptor)msgDestRefObj);
506             }
507
508             for (Object JavaDoc envPropObj : interceptor.getEnvironmentProperties()) {
509                 addEnvironmentProperty((EnvironmentProperty)envPropObj);
510             }
511
512             for (Object JavaDoc servRefObj :
513                     interceptor.getServiceReferenceDescriptors()) {
514                 addServiceReferenceDescriptor(
515                 (ServiceReferenceDescriptor)servRefObj);
516             }
517
518             for (Object JavaDoc resRefObj :
519                     interceptor.getResourceReferenceDescriptors()) {
520                 addResourceReferenceDescriptor(
521                     (ResourceReferenceDescriptor)resRefObj);
522             }
523
524             for (Object JavaDoc jmsDestRefObj:
525                     interceptor.getJmsDestinationReferenceDescriptors()) {
526                 addJmsDestinationReferenceDescriptor(
527             (JmsDestinationReferenceDescriptor)jmsDestRefObj);
528             }
529
530             for (EntityManagerFactoryReferenceDescriptor entMgrFacRef :
531                     interceptor.getEntityManagerFactoryReferenceDescriptors()) {
532                 addEntityManagerFactoryReferenceDescriptor(entMgrFacRef);
533             }
534
535             for (EntityManagerReferenceDescriptor entMgrRef :
536                     interceptor.getEntityManagerReferenceDescriptors()) {
537                 addEntityManagerReferenceDescriptor(entMgrRef);
538             }
539         }
540     }
541
542     /**
543      * Return an unordered set of interceptor descriptors for this bean.
544      * This list does not include interceptor info for the bean
545      * class itself, even if the bean class declares AroundInvoke methods
546      * and/or callbacks.
547      */

548     public Set<EjbInterceptor> getInterceptorClasses() {
549         return new HashSet<EjbInterceptor>(allInterceptorClasses);
550     }
551
552     /**
553      * Return an unordered set of the names of all interceptor classes
554      * for this bean. This list does not include the name of the bean
555      * class itself, even if the bean class declares AroundInvoke methods
556      * and/or callbacks.
557      */

558     public Set<String JavaDoc> getInterceptorClassNames() {
559
560         HashSet<String JavaDoc> classNames = new HashSet<String JavaDoc>();
561
562         for (EjbInterceptor ei : getInterceptorClasses()) {
563             classNames.add(ei.getInterceptorClassName());
564         }
565
566         return classNames;
567     }
568
569     public Map<MethodDescriptor, List<EjbInterceptor>>
570         getMethodInterceptorsMap() {
571         return new HashMap<MethodDescriptor, List<EjbInterceptor>>
572             (methodInterceptorsMap);
573     }
574
575     public List<EjbInterceptor> getInterceptorChain() {
576         return new LinkedList<EjbInterceptor>( interceptorChain );
577     }
578
579     /**
580      * Return the ordered list of interceptor info for AroundInvoke behavior
581      * of a particular business method. This list *does* include the info
582      * on any bean class interceptor. If present, this would always be the
583      * last element in the list because of the precedence defined by the spec.
584      */

585     public List<EjbInterceptor> getAroundInvokeInterceptors
586         (MethodDescriptor businessMethod)
587     {
588
589         LinkedList<EjbInterceptor> aroundInvokeInterceptors =
590             new LinkedList<EjbInterceptor>();
591
592         List<EjbInterceptor> classOrMethodInterceptors =
593             methodInterceptorsMap.get(businessMethod);
594         if( classOrMethodInterceptors == null ) {
595             classOrMethodInterceptors = interceptorChain;
596         }
597
598         for (EjbInterceptor next : classOrMethodInterceptors) {
599             if (next.getAroundInvokeDescriptors().size() > 0) {
600                 aroundInvokeInterceptors.add(next);
601             }
602         }
603
604         if( hasAroundInvokeMethod() ) {
605             
606             EjbInterceptor interceptorInfo = new EjbInterceptor();
607             interceptorInfo.setFromBeanClass(true);
608             interceptorInfo.addAroundInvokeDescriptors(getAroundInvokeDescriptors());
609             interceptorInfo.setInterceptorClassName(getEjbImplClassName());
610
611             aroundInvokeInterceptors.add(interceptorInfo);
612         }
613
614         return aroundInvokeInterceptors;
615     }
616
617     /**
618      * Return the ordered list of interceptor info for a particular
619      * callback event type. This list *does* include the info
620      * on any bean class callback. If present, this would always be the
621      * last element in the list because of the precedence defined by the spec.
622      */

623     public List<EjbInterceptor> getCallbackInterceptors(CallbackType type) {
624
625         LinkedList<EjbInterceptor> callbackInterceptors =
626             new LinkedList<EjbInterceptor>();
627
628         for (EjbInterceptor next : interceptorChain) {
629             if (next.getCallbackDescriptors(type).size() > 0) {
630                 callbackInterceptors.add(next);
631             }
632         }
633         
634         EjbInterceptor beanClassCallbackInfo = null;
635
636         switch(type) {
637         case POST_CONSTRUCT :
638
639             if( hasPostConstructMethod() ) {
640                 beanClassCallbackInfo = new EjbInterceptor();
641                 beanClassCallbackInfo.setFromBeanClass(true);
642                 beanClassCallbackInfo.addCallbackDescriptors
643                     (type, getPostConstructDescriptors());
644             }
645             break;
646
647         case PRE_DESTROY :
648
649             if( hasPreDestroyMethod() ) {
650                 beanClassCallbackInfo = new EjbInterceptor();
651                 beanClassCallbackInfo.setFromBeanClass(true);
652                 beanClassCallbackInfo.addCallbackDescriptors
653                     (type, getPreDestroyDescriptors());
654             }
655             break;
656
657         case PRE_PASSIVATE :
658
659             if( ((EjbSessionDescriptor)this).hasPrePassivateMethod() ) {
660                 beanClassCallbackInfo = new EjbInterceptor();
661                 beanClassCallbackInfo.setFromBeanClass(true);
662                 beanClassCallbackInfo.addCallbackDescriptors(type,
663                     ((EjbSessionDescriptor)this).getPrePassivateDescriptors());
664             }
665
666             break;
667
668         case POST_ACTIVATE :
669
670             if( ((EjbSessionDescriptor)this).hasPostActivateMethod() ) {
671                 beanClassCallbackInfo = new EjbInterceptor();
672                 beanClassCallbackInfo.setFromBeanClass(true);
673                 beanClassCallbackInfo.addCallbackDescriptors(type,
674                     ((EjbSessionDescriptor)this).getPostActivateDescriptors());
675             }
676
677             break;
678
679         }
680
681         if( beanClassCallbackInfo != null ) {
682             
683             beanClassCallbackInfo.setInterceptorClassName
684                 (getEjbImplClassName());
685             callbackInterceptors.add(beanClassCallbackInfo);
686
687         }
688
689         return callbackInterceptors;
690     }
691         
692
693     /**
694      * Gets the transaction scope of this ejb.
695      * @return true if bean has distributed tx scope (default).
696      */

697     public boolean isDistributedTransactionScope() {
698     return isDistributedTxScope;
699     }
700     
701     /**
702      * Set the transaction scope of this ejb.
703      */

704     public void setDistributedTransactionScope(boolean scope)
705     {
706     isDistributedTxScope = scope;
707     }
708
709
710     /**
711      * Set the usesCallerIdentity flag
712      */

713     public void setUsesCallerIdentity(boolean flag)
714     {
715     usesCallerIdentity = flag;
716     }
717
718     /**
719      * Get the usesCallerIdentity flag
720      * @return Boolean.TRUE if this bean uses caller identity
721      * null if this is called before validator visit
722      */

723     public Boolean JavaDoc getUsesCallerIdentity()
724     {
725     return usesCallerIdentity;
726     }
727
728
729     /**
730      * Get the description field of security-identity
731      */

732     public String JavaDoc getSecurityIdentityDescription()
733     {
734     if ( securityIdentityDescription == null )
735         securityIdentityDescription = "";
736     return securityIdentityDescription;
737     }
738
739     /**
740      * Set the description field of security-identity
741      */

742     public void setSecurityIdentityDescription(String JavaDoc s)
743     {
744     securityIdentityDescription = s;
745     }
746
747
748     public void setRunAsIdentity(RunAsIdentityDescriptor desc)
749     {
750     if ( usesCallerIdentity == null || usesCallerIdentity )
751         throw new IllegalStateException JavaDoc("Cannot set RunAs identity when using caller identity");
752     this.runAsIdentity = desc;
753     }
754
755     public RunAsIdentityDescriptor getRunAsIdentity()
756     {
757     if ( usesCallerIdentity == null || usesCallerIdentity )
758         throw new IllegalStateException JavaDoc("Cannot get RunAs identity when using caller identity");
759     return runAsIdentity;
760     }
761     
762     /**
763      * Have default method transaction if isBoundsChecking is on.
764      */

765     public void setUsesDefaultTransaction() {
766         usesDefaultTransaction = true;
767     }
768
769     /**
770      * @return a state to indicate whether default method transaction is used
771      * if isBoundsChecking is on.
772      */

773     public boolean isUsesDefaultTransaction() {
774         return usesDefaultTransaction;
775     }
776      
777     /**
778      * Return a copy of the mapping held internally of method descriptors to container transaction objects.
779      */

780     public Hashtable getMethodContainerTransactions() {
781     if (this.methodContainerTransactions == null) {
782         this.methodContainerTransactions = new Hashtable();
783     }
784     return methodContainerTransactions;
785     }
786     
787     /**
788      * Sets the container transaction for the given method descriptor.
789      * Throws an Illegal argument if this ejb has transaction type BEAN_TRANSACTION_TYPE.
790      */

791     public void setContainerTransactionFor(MethodDescriptor methodDescriptor, ContainerTransaction containerTransaction) {
792     ContainerTransaction oldValue = this.getContainerTransactionFor(methodDescriptor);
793     if (oldValue == null || (oldValue != null && !(oldValue.equals(containerTransaction)))) {
794             String JavaDoc transactionType = this.getTransactionType();
795             if (transactionType == null) {
796                 setTransactionType(CONTAINER_TRANSACTION_TYPE);
797                 transactionType = CONTAINER_TRANSACTION_TYPE;
798             } else if (BEAN_TRANSACTION_TYPE.equals(transactionType)) {
799         throw new IllegalArgumentException JavaDoc(localStrings.getLocalString(
800                                            "enterprise.deployment.exceptiontxattrbtnotspecifiedinbeanwithtxtype",
801                                            "Method level transaction attributes may not be specified on a bean with transaction type {0}", new Object JavaDoc[] {EjbSessionDescriptor.BEAN_TRANSACTION_TYPE}));
802         }
803         //_logger.log(Level.FINE,"put " + methodDescriptor + " " + containerTransaction);
804
getMethodContainerTransactions().put(methodDescriptor, containerTransaction);
805     }
806     }
807     
808     private void removeContainerTransactionFor(MethodDescriptor methodDescriptor) {
809         getMethodContainerTransactions().remove(methodDescriptor);
810     }
811     
812     /**
813     * Sets the container transactions for all the method descriptors of this ejb. The Hashtable is keyed
814     * by method descriptor and the values are the corresponding container transaction objects..
815     * Throws an Illegal argument if this ejb has transaction type BEAN_TRANSACTION_TYPE.
816     */

817     public void setMethodContainerTransactions(Hashtable methodContainerTransactions) {
818     if (methodContainerTransactions == null || methodContainerTransactions.isEmpty()) {
819         methodContainerTransactions = null;
820     } else {
821         for (Enumeration e = methodContainerTransactions.keys(); e.hasMoreElements();) {
822         MethodDescriptor methodDescriptor = (MethodDescriptor) e.nextElement();
823         ContainerTransaction containerTransaction =
824             (ContainerTransaction) methodContainerTransactions.get(methodDescriptor);
825         setContainerTransactionFor(methodDescriptor, containerTransaction);
826         }
827     }
828     }
829     
830     Set getAllMethodDescriptors() {
831     Set allMethodDescriptors = new HashSet();
832     for (Enumeration e = getMethodContainerTransactions().keys(); e.hasMoreElements();) {
833         allMethodDescriptors.add(e.nextElement());
834     }
835     for (Iterator e = this.getPermissionedMethodsByPermission().keySet().iterator(); e.hasNext();) {
836         MethodPermission nextPermission = (MethodPermission) e.next();
837         Set permissionedMethods = (Set) this.getPermissionedMethodsByPermission().get(nextPermission);
838         for (Iterator itr = permissionedMethods.iterator(); itr.hasNext();) {
839         allMethodDescriptors.add(itr.next());
840         }
841     }
842     return allMethodDescriptors;
843     }
844
845     
846     /**
847     * Fetches the assigned container transaction object for the given method object or null.
848     */

849     public ContainerTransaction getContainerTransactionFor(MethodDescriptor methodDescriptor) {
850     ContainerTransaction containerTransaction = null;
851     if (this.needToConvertMethodContainerTransactions()) {
852         this.convertMethodContainerTransactions();
853     }
854     containerTransaction = (ContainerTransaction) this.getMethodContainerTransactions().get(methodDescriptor);
855     if (containerTransaction == null) {
856         if (this.isBoundsChecking() && usesDefaultTransaction) {
857         containerTransaction = new ContainerTransaction(ContainerTransaction.REQUIRED, "");
858                 this.getMethodContainerTransactions().put(methodDescriptor, containerTransaction);
859         } else {
860         containerTransaction = null;
861         }
862     }
863     return containerTransaction;
864     }
865     
866     private boolean needToConvertMethodContainerTransactions() {
867     if (this.getEjbBundleDescriptor() != null) {
868         for (Enumeration e = this.getMethodContainerTransactions().keys(); e.hasMoreElements();) {
869         MethodDescriptor md = (MethodDescriptor) e.nextElement();
870         if (!md.isExact()) {
871             return true;
872         }
873         }
874     }
875     return false;
876     }
877     
878     
879     private void convertMethodContainerTransactions() {
880     // container transactions first
881
//Hashtable transactions = this.getMethodContainerTransactions();
882
//_logger.log(Level.FINE,"Pre conversion = " + transactions);
883
Hashtable convertedTransactions = new Hashtable();
884         convertMethodContainerTransactionsOfStyle(1, convertedTransactions);
885         convertMethodContainerTransactionsOfStyle(2, convertedTransactions);
886         convertMethodContainerTransactionsOfStyle(3, convertedTransactions);
887     //_logger.log(Level.FINE,"Post conversion = " + convertedTransactions);
888
this.methodContainerTransactions = convertedTransactions;
889     }
890     
891     private void convertMethodContainerTransactionsOfStyle( int requestedStyleForConversion, Hashtable convertedMethods) {
892         
893     Collection transactionMethods = this.getTransactionMethodDescriptors();
894     Hashtable transactions = this.getMethodContainerTransactions();
895         for (Enumeration e=transactions.keys();e.hasMoreElements();) {
896             MethodDescriptor md = (MethodDescriptor) e.nextElement();
897             if (md.getStyle()==requestedStyleForConversion) {
898             ContainerTransaction ct = (ContainerTransaction) getMethodContainerTransactions().get(md);
899             for (Enumeration mds = md.doStyleConversion(this, transactionMethods).elements(); mds.hasMoreElements();) {
900             MethodDescriptor next = (MethodDescriptor) mds.nextElement();
901             convertedMethods.put(next, new ContainerTransaction(ct));
902             }
903             }
904         }
905     }
906
907     /**
908     * returns a ContainerTransaction if all the transactional methods on
909     * the ejb descriptor have the same transaction type else return null
910     */

911     public ContainerTransaction getContainerTransaction() {
912     Vector transactionalMethods = new Vector(this.getTransactionMethodDescriptors());
913     MethodDescriptor md = (MethodDescriptor) transactionalMethods.firstElement();
914     if (md != null) {
915         ContainerTransaction first = this.getContainerTransactionFor(md);
916         for (Enumeration e = transactionalMethods.elements(); e.hasMoreElements();) {
917         MethodDescriptor next = (MethodDescriptor) e.nextElement();
918         ContainerTransaction nextCt = this.getContainerTransactionFor(next);
919         if (nextCt != null && !nextCt.equals(first)) {
920             return null;
921         }
922         }
923         return first;
924     }
925     return null;
926     }
927     
928     public Set getIORConfigurationDescriptors() {
929     return iorConfigDescriptors;
930     }
931
932     public void addIORConfigurationDescriptor(EjbIORConfigurationDescriptor val)
933     {
934     iorConfigDescriptors.add(val);
935     this.changed();
936     }
937    
938     /**
939     * @eturn the set of roles to which have been assigned method permissions.
940     */

941     public Set getPermissionedRoles() {
942         if (needToConvertMethodPermissions()) {
943         convertMethodPermissions();
944     }
945     Set allPermissionedRoles = new HashSet();
946     for (Iterator i = this.getPermissionedMethodsByPermission().keySet().iterator(); i.hasNext();) {
947             MethodPermission pm = (MethodPermission) i.next();
948             if (pm.isRoleBased()) {
949             allPermissionedRoles.add(pm.getRole());
950             }
951     }
952     return allPermissionedRoles;
953     }
954     
955     /**
956      * @return the Map of MethodPermission (keys) that have been assigned to
957      * MethodDescriptors (elements)
958      */

959     public Map getPermissionedMethodsByPermission() {
960         if (permissionedMethodsByPermission==null) {
961             permissionedMethodsByPermission = new Hashtable();
962         }
963         return permissionedMethodsByPermission;
964     }
965     
966     /**
967      * Add a new method permission to a method or a set of methods
968      *
969      * @param mp is the new method permission to assign
970      * @param md describe the method or set of methods this permission apply to
971      */

972     public void addPermissionedMethod(MethodPermission mp, MethodDescriptor md) {
973     if (getEjbBundleDescriptor() == null) {
974         throw new IllegalArgumentException JavaDoc(localStrings.getLocalString(
975                                        "enterprise.deployment.exceptioncannotaddrolesdescriptor",
976                                        "Cannot add roles when the descriptor is not part of a bundle"));
977     }
978         if (mp.isRoleBased()) {
979             if (!getEjbBundleDescriptor().getRoles().contains(mp.getRole())) {
980                 throw new IllegalArgumentException JavaDoc(localStrings.getLocalString(
981                            "enterprise.deployment.exceptioncannotaddrolesbundle",
982                            "Cannot add roles when the bundle does not have them"));
983             }
984         }
985         
986         if (md.isExact()) {
987             updateMethodPermissionForMethod(mp, md);
988         } else {
989             addMethodPermissionForStyledMethodDescriptor(mp, md);
990         }
991     
992     saveMethodPermissionFromDD(mp,md);
993     }
994
995     /**
996      * Keep a record of all the Method Permissions exactly as they were in the DD
997      */

998     private void saveMethodPermissionFromDD(MethodPermission mp,
999                         MethodDescriptor md) {
1000
1001    if (methodPermissionsFromDD==null) {
1002        methodPermissionsFromDD = new HashMap();
1003    }
1004
1005    // we organize by permission, makes it easier...
1006
// Use Array List as apposed to HashMap or Table because MethodDescriptor
1007
// Equality once did not take into account differences in
1008
// method interface, and will process sequentially.
1009
ArrayList descriptors = (ArrayList) methodPermissionsFromDD.get(mp);
1010    if (descriptors == null)
1011        descriptors = new ArrayList();
1012    descriptors.add(md);
1013    methodPermissionsFromDD.put(mp, descriptors);
1014    }
1015
1016    /**
1017     * Get a record of all the Method Permissions exactly as they were in the`DD
1018     */

1019    public HashMap getMethodPermissionsFromDD() {
1020    return methodPermissionsFromDD;
1021    }
1022
1023    private void addMethodPermissionForMethod(MethodPermission mp, MethodDescriptor md) {
1024                
1025        if (getPermissionedMethodsByPermission().containsKey(mp)) {
1026        Set alreadyPermissionedMethodsForThisRole = (Set) getPermissionedMethodsByPermission().get(mp);
1027        alreadyPermissionedMethodsForThisRole.add(md);
1028        this.getPermissionedMethodsByPermission().put(mp, alreadyPermissionedMethodsForThisRole);
1029    } else {
1030        Set permissionedMethodsForThisRole = new HashSet();
1031        permissionedMethodsForThisRole.add(md);
1032        this.getPermissionedMethodsByPermission().put(mp, permissionedMethodsForThisRole);
1033        }
1034        this.changed();
1035    }
1036    
1037    /**
1038     * Remove a method permission from a method or a set of methods
1039     *
1040     * @param mp is the method permission to remove
1041     * @param md describe the method or set of methods this permission apply to
1042     */

1043    public void removePermissionedMethod(MethodPermission mp, MethodDescriptor md) {
1044    if (this.getEjbBundleDescriptor() == null) {
1045        throw new IllegalArgumentException JavaDoc(localStrings.getLocalString(
1046                                       "enterprise.deployment.exceptioncanotaddrolesdescriptor",
1047                                       "Cannot add roles when the descriptor is not part of a bundle"));
1048    }
1049        if (mp.isRoleBased()) {
1050        if (!getEjbBundleDescriptor().getRoles().contains(mp.getRole())) {
1051                throw new IllegalArgumentException JavaDoc(localStrings.getLocalString(
1052                                       "enterprise.deployment.exceptioncannotaddrolesbndledoesnothave",
1053                                       "Cannot add roles when the bundle does not have them"));
1054            }
1055        }
1056        
1057    if (this.getPermissionedMethodsByPermission().containsKey(mp)) {
1058            Set alreadyPermissionedMethodsForThisRole = (Set) this.getPermissionedMethodsByPermission().get(mp);
1059        alreadyPermissionedMethodsForThisRole.remove(md);
1060        this.getPermissionedMethodsByPermission().put(mp, alreadyPermissionedMethodsForThisRole);
1061            }
1062    this.changed();
1063    }
1064    
1065    /**
1066     * add a style 1 or 2 in our tables
1067     */

1068    private void addMethodPermissionForStyledMethodDescriptor(MethodPermission mp, MethodDescriptor md) {
1069        
1070        if (styledMethodDescriptors==null) {
1071            styledMethodDescriptors = new HashMap();
1072        }
1073        
1074        // we organize per method descriptors, makes it easier...
1075
Set permissions = (Set) styledMethodDescriptors.get(md);
1076        if (permissions==null)
1077            permissions = new HashSet();
1078        permissions.add(mp);
1079        styledMethodDescriptors.put(md, permissions);
1080    }
1081    
1082    /**
1083     * @return a map of permission to style 1 or 2 method descriptors
1084     */

1085    public Map getStyledPermissionedMethodsByPermission() {
1086        if (styledMethodDescriptors==null) {
1087            return null;
1088        }
1089        
1090        // the current info is structured as MethodDescriptors as keys to
1091
// method permission, let's reverse this to make the Map using the
1092
// method permission as a key.
1093
Map styledMethodDescriptorsByPermission = new HashMap();
1094        for (Iterator mdIterator=styledMethodDescriptors.keySet().iterator();mdIterator.hasNext();) {
1095            MethodDescriptor md = (MethodDescriptor) mdIterator.next();
1096            Set methodPermissions = (Set) styledMethodDescriptors.get(md);
1097            for (Iterator mpIterator = methodPermissions.iterator(); mpIterator.hasNext();) {
1098                MethodPermission mp = (MethodPermission) mpIterator.next();
1099                
1100                Set methodDescriptors = (Set) styledMethodDescriptorsByPermission.get(mp);
1101                if (methodDescriptors == null) {
1102                    methodDescriptors = new HashSet();
1103                }
1104                methodDescriptors.add(md);
1105                styledMethodDescriptorsByPermission.put(mp, methodDescriptors);
1106            }
1107        }
1108        return styledMethodDescriptorsByPermission;
1109    }
1110
1111    /**
1112     * @return a Set of method descriptors for all the methods associated
1113     * with an unchecked method permission
1114     */

1115    public Set getUncheckedMethodDescriptors (){
1116    if (needToConvertMethodPermissions()) {
1117        convertMethodPermissions();
1118    }
1119    return (Set) getPermissionedMethodsByPermission().get(MethodPermission.getUncheckedMethodPermission());
1120    }
1121    
1122    /**
1123     * @return a Set of method descriptors for all the methoda assoicated
1124     * with an excluded method permission
1125     */

1126    public Set getExcludedMethodDescriptors (){
1127        if (needToConvertMethodPermissions()) {
1128        convertMethodPermissions();
1129    }
1130    return (Set) getPermissionedMethodsByPermission().get(MethodPermission.getExcludedMethodPermission());
1131    }
1132    
1133    /**
1134     * convert all style 1 and style 2 method descriptors contained in
1135     * our tables into style 3 method descriptors.
1136     */

1137    private void convertMethodPermissions() {
1138                
1139        if (styledMethodDescriptors==null)
1140            return;
1141        
1142        Set allMethods = getMethodDescriptors();
1143        Set unpermissionedMethods = getMethodDescriptors();
1144        
1145        Set methodDescriptors = styledMethodDescriptors.keySet();
1146        for (Iterator styledMdItr = methodDescriptors.iterator();styledMdItr.hasNext();) {
1147            MethodDescriptor styledMd = (MethodDescriptor) styledMdItr.next();
1148            
1149            // Get the new permissions we are trying to set for this
1150
// method(s)
1151
Set newPermissions = (Set) styledMethodDescriptors.get(styledMd);
1152            
1153            // Convert to style 3 method descriptors
1154
Vector mds = styledMd.doStyleConversion(this, allMethods);
1155            for (Iterator mdItr = mds.iterator(); mdItr.hasNext();) {
1156                MethodDescriptor md = (MethodDescriptor) mdItr.next();
1157                                
1158                // remove it from the list of unpermissioned methods.
1159
// it will be used at the end to set all remaining methods
1160
// with the unchecked method permission
1161
unpermissionedMethods.remove(md);
1162                
1163                // iterator over the new set of method permissions for that
1164
// method descriptor and update the table
1165
for (Iterator newPermissionsItr = newPermissions.iterator();newPermissionsItr.hasNext();) {
1166                    MethodPermission newMp = (MethodPermission) newPermissionsItr.next();
1167                    updateMethodPermissionForMethod(newMp, md);
1168                }
1169            }
1170        }
1171        
1172        // All remaining methods should now be defined as unchecked...
1173
MethodPermission mp = MethodPermission.getUncheckedMethodPermission();
1174        Iterator iterator = unpermissionedMethods.iterator();
1175        while(iterator.hasNext()) {
1176            MethodDescriptor md = (MethodDescriptor) iterator.next();
1177            if (getMethodPermissions(md).isEmpty()) {
1178                addMethodPermissionForMethod(mp, md);
1179            }
1180        }
1181        
1182        // finally we reset the list of method descriptors that need style conversion
1183
styledMethodDescriptors = null;
1184    }
1185    
1186    private void dumpMethodPermissions() {
1187        _logger.log(Level.FINE,"For Bean " + getName());
1188        Map allPermissions = getPermissionedMethodsByPermission();
1189        Set permissions = allPermissions.keySet();
1190        for (Iterator permissionsIterator = permissions.iterator();permissionsIterator.hasNext();) {
1191            MethodPermission mp = (MethodPermission) permissionsIterator.next();
1192            _logger.log(Level.FINE," Method Permission : " + mp);
1193            Set allMethods = (Set) getPermissionedMethodsByPermission().get(mp);
1194            for (Iterator methodIterator = allMethods.iterator();methodIterator.hasNext();) {
1195                MethodDescriptor md = (MethodDescriptor) methodIterator.next();
1196               _logger.log(Level.FINE," -> " + md);
1197            }
1198        }
1199    }
1200
1201    /**
1202     * Update a method descriptor set of method permission with a new method permission
1203     * The new method permission is added to the list of existing method permissions
1204     * given it respect the EJB 2.0 paragraph 21.3.2 on priorities of method permissions
1205     *
1206     * @param mp is the method permission to be added
1207     * @param md is the method descriptor (style3 only) to add the method permission to
1208     */

1209    private void updateMethodPermissionForMethod(MethodPermission mp, MethodDescriptor md) {
1210        
1211        // Get the current set of method permissions for that method
1212
Set oldPermissions = getMethodPermissions(md);
1213        
1214        if (oldPermissions.isEmpty()) {
1215            // this is easy, just add the new one
1216
addMethodPermissionForMethod(mp, md);
1217            return;
1218        }
1219        
1220        // The order of method permssion setting is very important
1221
// EJB 2.0 Spec 21.3.2
1222
// excluded method permission is always used when multiple methos permission are present
1223
// unchecked is considered like a role based method permission and is added to the list
1224
// therefore making the method callable by anyone.
1225

1226        if (mp.isExcluded()) {
1227            // Excluded methods takes precedence on any other form of method permission
1228
// remove all existing method permission...
1229
for (Iterator oldPermissionsItr = oldPermissions.iterator();oldPermissionsItr.hasNext();) {
1230                MethodPermission oldMp = (MethodPermission) oldPermissionsItr.next();
1231                removePermissionedMethod(oldMp, md);
1232            }
1233            // add the excluded
1234
addMethodPermissionForMethod(mp, md);
1235        } else {
1236            if (mp.isUnchecked()) {
1237                // we are trying to add an unchecked method permisison, all role-based
1238
// method permission should be removed since unchecked is now used, if a
1239
// particular method has an excluded method permision, we do not add it
1240
for (Iterator oldPermissionsItr = oldPermissions.iterator();oldPermissionsItr.hasNext();) {
1241                    MethodPermission oldMp = (MethodPermission) oldPermissionsItr.next();
1242                    if (!oldMp.isExcluded()) {
1243                        removePermissionedMethod(oldMp, md);
1244                        addMethodPermissionForMethod(mp, md);
1245                    }
1246                }
1247            } else {
1248                // we are trying to add a role based method permission. Check that
1249
// unchecked or excluded method permissions have not been set
1250
// and add it to the current list of role based permission
1251
for (Iterator oldPermissionsItr = oldPermissions.iterator();oldPermissionsItr.hasNext();) {
1252                    MethodPermission oldMp = (MethodPermission) oldPermissionsItr.next();
1253                    if (!oldMp.isExcluded()) {
1254                        if (!oldMp.isUnchecked()) {
1255                            addMethodPermissionForMethod(mp, md);
1256                        }
1257                    }
1258                }
1259            }
1260        }
1261    }
1262       
1263    /**
1264     * @return true if we have unconverted style 1 or style 2 method descriptors
1265     */

1266     private boolean needToConvertMethodPermissions() {
1267        return styledMethodDescriptors!=null;
1268    }
1269    
1270    /**
1271     * @return the set of method permission assigned to a ejb method descriptor.
1272     */

1273    public Set getMethodPermissionsFor(MethodDescriptor methodDescriptor) {
1274    
1275    if (needToConvertMethodPermissions()) {
1276        convertMethodPermissions();
1277    }
1278        return getMethodPermissions(methodDescriptor);
1279    }
1280    
1281    private Set getMethodPermissions(MethodDescriptor methodDescriptor) {
1282        
1283    Set methodPermissionsForMethod = new HashSet();
1284    for (Iterator e = this.getPermissionedMethodsByPermission().keySet().iterator(); e.hasNext();) {
1285        MethodPermission nextPermission = (MethodPermission) e.next();
1286        Set permissionedMethods = (Set) this.getPermissionedMethodsByPermission().get(nextPermission);
1287        for (Iterator itr = permissionedMethods.iterator(); itr.hasNext();) {
1288        MethodDescriptor md = (MethodDescriptor) itr.next();
1289        if (md.equals(methodDescriptor)) {
1290            methodPermissionsForMethod.add(nextPermission);
1291        }
1292        }
1293    }
1294    return methodPermissionsForMethod;
1295    }
1296    
1297    
1298    /**
1299    * Return the set of ejb references this ejb declares.
1300    */

1301    public Set<EjbReference> getEjbReferenceDescriptors() {
1302    return ejbReferences;
1303    }
1304    /**
1305    * Adds a reference to another ejb to me.
1306    */

1307    
1308    public void addEjbReferenceDescriptor(EjbReference ejbReference) {
1309    ejbReferences.add(ejbReference);
1310    ejbReference.setReferringBundleDescriptor(getEjbBundleDescriptor());
1311    }
1312    
1313    public void removeEjbReferenceDescriptor(EjbReference ejbReference) {
1314    ejbReferences.remove(ejbReference);
1315    ejbReference.setReferringBundleDescriptor(null);
1316    }
1317
1318    public Set<ServiceReferenceDescriptor> getServiceReferenceDescriptors() {
1319        return serviceReferences;
1320    }
1321
1322    public void addServiceReferenceDescriptor(ServiceReferenceDescriptor
1323                                              serviceRef) {
1324        serviceRef.setBundleDescriptor(getEjbBundleDescriptor());
1325        serviceReferences.add(serviceRef);
1326    }
1327
1328    public void removeServiceReferenceDescriptor(ServiceReferenceDescriptor
1329                                                 serviceRef) {
1330        serviceReferences.remove(serviceRef);
1331    }
1332    
1333    /**
1334     * Looks up an service reference with the given name.
1335     * Throws an IllegalArgumentException if it is not found.
1336     */

1337    public ServiceReferenceDescriptor getServiceReferenceByName(String JavaDoc name) {
1338    for (Iterator itr = this.getServiceReferenceDescriptors().iterator();
1339             itr.hasNext();) {
1340        ServiceReferenceDescriptor srd = (ServiceReferenceDescriptor)
1341                itr.next();
1342        if (srd.getName().equals(name)) {
1343        return srd;
1344        }
1345    }
1346    throw new IllegalArgumentException JavaDoc("This ejb has no service refernce by the name " + name);
1347    }
1348
1349    public Set<MessageDestinationReferenceDescriptor> getMessageDestinationReferenceDescriptors() {
1350        return messageDestReferences;
1351    }
1352
1353    public void addMessageDestinationReferenceDescriptor
1354        (MessageDestinationReferenceDescriptor messageDestRef) {
1355        if( getEjbBundleDescriptor() != null ) {
1356            messageDestRef.setReferringBundleDescriptor
1357                (getEjbBundleDescriptor());
1358        }
1359        messageDestReferences.add(messageDestRef);
1360    }
1361
1362    public void removeMessageDestinationReferenceDescriptor
1363        (MessageDestinationReferenceDescriptor msgDestRef) {
1364        messageDestReferences.remove(msgDestRef);
1365    }
1366    
1367    /**
1368     * Looks up an message destination reference with the given name.
1369     * Throws an IllegalArgumentException if it is not found.
1370     */

1371    public MessageDestinationReferenceDescriptor
1372        getMessageDestinationReferenceByName(String JavaDoc name) {
1373        
1374    for (MessageDestinationReferenceDescriptor mdr : messageDestReferences) {
1375        if (mdr.getName().equals(name)) {
1376        return mdr;
1377        }
1378    }
1379    throw new IllegalArgumentException JavaDoc("This ejb has no message destination reference by the name " + name);
1380    }
1381    
1382    /**
1383    * Return the set of JMS destination references this ejb declares.
1384    */

1385    public Set<JmsDestinationReferenceDescriptor> getJmsDestinationReferenceDescriptors() {
1386    return jmsDestReferences;
1387    }
1388
1389    public void addJmsDestinationReferenceDescriptor(JmsDestinationReferenceDescriptor jmsDestReference) {
1390    jmsDestReferences.add(jmsDestReference);
1391    }
1392    
1393    public void removeJmsDestinationReferenceDescriptor(JmsDestinationReferenceDescriptor jmsDestReference) {
1394    jmsDestReferences.remove(jmsDestReference);
1395    }
1396
1397    /**
1398    * Return the set of resource references this ejb declares.
1399    */

1400    public Set<ResourceReferenceDescriptor> getResourceReferenceDescriptors() {
1401    return resourceReferences;
1402    }
1403    
1404    /** Adds a resource reference to me.
1405    */

1406    public void addResourceReferenceDescriptor(ResourceReferenceDescriptor resourceReference) {
1407    resourceReferences.add(resourceReference);
1408    }
1409    
1410    /**
1411    * Removes the given resource reference from me.
1412    */

1413    public void removeResourceReferenceDescriptor(ResourceReferenceDescriptor resourceReference) {
1414    resourceReferences.remove(resourceReference);
1415    }
1416    
1417    
1418    /**
1419    * Return the set of resource references this ejb declares that have been resolved..
1420    */

1421    public Set<ResourceReferenceDescriptor> getResourceReferenceDescriptors(boolean resolved) {
1422    Set<ResourceReferenceDescriptor> toReturn = new HashSet<ResourceReferenceDescriptor>();
1423    for (Iterator itr = this.getResourceReferenceDescriptors().iterator(); itr.hasNext();) {
1424        ResourceReferenceDescriptor next = (ResourceReferenceDescriptor) itr.next();
1425        if (next.isResolved() == resolved) {
1426        toReturn.add(next);
1427        }
1428    }
1429    return toReturn;
1430    }
1431    
1432    /**
1433    * Returns the environment property object searching on the supplied key.
1434    * throws an illegal argument exception if no such environment property exists.
1435    */

1436    public EnvironmentProperty getEnvironmentPropertyByName(String JavaDoc name) {
1437    for (Iterator itr = this.getEnvironmentProperties().iterator(); itr.hasNext();) {
1438        EnvironmentProperty ev = (EnvironmentProperty) itr.next();
1439        if (ev.getName().equals(name)) {
1440        return ev;
1441        }
1442    }
1443    throw new IllegalArgumentException JavaDoc(localStrings.getLocalString(
1444                "enterprise.deployment.exceptionbeanhasnoenvpropertybyname",
1445                "This bean {0} has no environment property by the name of {1}",
1446                new Object JavaDoc[] {getName(), name}));
1447    }
1448    
1449    /**
1450    * Return a reference to another ejb by the same name or throw an IllegalArgumentException.
1451    */

1452    public EjbReference getEjbReference(String JavaDoc name) {
1453    for (Iterator itr = this.getEjbReferenceDescriptors().iterator(); itr.hasNext();) {
1454        EjbReference er = (EjbReference) itr.next();
1455        if (er.getName().equals(name)) {
1456        return er;
1457        }
1458    }
1459    throw new IllegalArgumentException JavaDoc(localStrings.getLocalString(
1460                "enterprise.deployment.exceptionbeanhasnoejbrefbyname",
1461                "This bean {0} has no ejb reference by the name of {1}",
1462                new Object JavaDoc[] {getName(), name}));
1463    }
1464    
1465    
1466    /**
1467    * Return a reference to another ejb by the same name or throw an IllegalArgumentException.
1468    */

1469    public EjbReferenceDescriptor getEjbReferenceByName(String JavaDoc name) {
1470        return (EjbReferenceDescriptor) getEjbReference(name);
1471    }
1472
1473   /**
1474    * Return a reference to another ejb by the same name or throw an IllegalArgumentException.
1475    */

1476    public JmsDestinationReferenceDescriptor getJmsDestinationReferenceByName(String JavaDoc name) {
1477    for (Iterator itr = this.getJmsDestinationReferenceDescriptors().iterator(); itr.hasNext();) {
1478        JmsDestinationReferenceDescriptor jdr = (JmsDestinationReferenceDescriptor) itr.next();
1479        if (jdr.getName().equals(name)) {
1480        return jdr;
1481        }
1482    }
1483    throw new IllegalArgumentException JavaDoc(localStrings.getLocalString(
1484                "enterprise.deployment.exceptionbeanhasnojmsdestrefbyname",
1485                "This bean {0} has no JMS destination reference by the name of {1}",
1486                new Object JavaDoc[] {getName(), name}));
1487    }
1488    
1489    /**
1490    * Replaces the an environment proiperty with another one.
1491    */

1492    
1493    public void replaceEnvironmentProperty(EnvironmentProperty oldOne, EnvironmentProperty newOne) {
1494    environmentProperties.remove(oldOne);
1495    environmentProperties.add(newOne);
1496    }
1497    
1498    /**
1499    * Removes the given environment property from me.
1500    */

1501    
1502    public void removeEnvironmentProperty(EnvironmentProperty environmentProperty) {
1503    this.getEnvironmentProperties().remove(environmentProperty);
1504    this.changed();
1505    }
1506    
1507    
1508    void removeRole(Role role) {
1509    //this.getPermissionedRoles().remove(role);
1510
this.getPermissionedMethodsByPermission().remove(new MethodPermission(role));
1511    Set roleReferences = new HashSet(this.getRoleReferences());
1512    for (Iterator itr = roleReferences.iterator(); itr.hasNext();) {
1513        RoleReference roleReference = (RoleReference) itr.next();
1514        if (roleReference.getRole().equals(role)) {
1515        roleReference.setValue("");
1516        }
1517    }
1518    }
1519    
1520    /**
1521    * Return the resource object corresponding to the supplied name or throw an illegal argument exception.
1522    */

1523    public ResourceReferenceDescriptor getResourceReferenceByName(String JavaDoc name) {
1524    for (Iterator itr = this.getResourceReferenceDescriptors().iterator(); itr.hasNext();) {
1525        ResourceReferenceDescriptor next = (ResourceReferenceDescriptor) itr.next();
1526        if (next.getName().equals(name)) {
1527        return next;
1528        }
1529    }
1530    throw new IllegalArgumentException JavaDoc(localStrings.getLocalString(
1531                "enterprise.deployment.exceptionbeanhasnoresourcerefbyname",
1532                "This bean {0} has no resource reference by the name of {1}",
1533                new Object JavaDoc[] {getName(), name}));
1534    }
1535    
1536    /**
1537    * Returns true if this ejb descriptor has resource references that are resolved.
1538    */

1539    public boolean hasResolvedResourceReferences() {
1540    if (!this.getResourceReferenceDescriptors().isEmpty()) {
1541        return false;
1542    } else {
1543        for (Iterator itr = this.getResourceReferenceDescriptors().iterator(); itr.hasNext();) {
1544        ResourceReferenceDescriptor resourceReference = (ResourceReferenceDescriptor) itr.next();
1545        if (resourceReference.isResolved()) {
1546            return true;
1547        }
1548        }
1549    }
1550    return false;
1551    }
1552
1553
1554    public Set<EntityManagerFactoryReferenceDescriptor>
1555        getEntityManagerFactoryReferenceDescriptors() {
1556        
1557        return entityManagerFactoryReferences;
1558    }
1559
1560    /**
1561     * Return the entity manager factory reference descriptor corresponding to
1562     * the given name.
1563     */

1564    public EntityManagerFactoryReferenceDescriptor
1565        getEntityManagerFactoryReferenceByName(String JavaDoc name) {
1566    for (EntityManagerFactoryReferenceDescriptor next :
1567             getEntityManagerFactoryReferenceDescriptors()) {
1568
1569        if (next.getName().equals(name)) {
1570        return next;
1571        }
1572    }
1573    throw new IllegalArgumentException JavaDoc(localStrings.getLocalString(
1574                "enterprise.deployment.exceptionbeanhasnoentitymgrfactoryrefbyname",
1575                "This ejb {0} has no entity manager factory reference by the name of {1}",
1576                new Object JavaDoc[] {getName(), name}));
1577    }
1578
1579    public void addEntityManagerFactoryReferenceDescriptor
1580        (EntityManagerFactoryReferenceDescriptor reference) {
1581        
1582        if( getEjbBundleDescriptor() != null ) {
1583            reference.setReferringBundleDescriptor
1584                (getEjbBundleDescriptor());
1585        }
1586        entityManagerFactoryReferences.add(reference);
1587    }
1588
1589    public Set<EntityManagerReferenceDescriptor>
1590            getEntityManagerReferenceDescriptors() {
1591        
1592        return entityManagerReferences;
1593    }
1594
1595    /**
1596     * Return the entity manager factory reference descriptor corresponding to
1597     * the given name.
1598     */

1599    public EntityManagerReferenceDescriptor
1600        getEntityManagerReferenceByName(String JavaDoc name) {
1601    for (EntityManagerReferenceDescriptor next :
1602             getEntityManagerReferenceDescriptors()) {
1603
1604        if (next.getName().equals(name)) {
1605        return next;
1606        }
1607    }
1608    throw new IllegalArgumentException JavaDoc(localStrings.getLocalString(
1609                "enterprise.deployment.exceptionbeanhasnoentitymgrrefbyname",
1610                "This ejb {0} has no entity manager reference by the name of {1}",
1611                new Object JavaDoc[] {getName(), name}));
1612    }
1613
1614    public void addEntityManagerReferenceDescriptor
1615        (EntityManagerReferenceDescriptor reference) {
1616        if( getEjbBundleDescriptor() != null ) {
1617            reference.setReferringBundleDescriptor
1618                (getEjbBundleDescriptor());
1619        }
1620        this.getEntityManagerReferenceDescriptors().add(reference);
1621    }
1622
1623    
1624    /**
1625    * Return a copy of the structure holding the environ,ent properties.
1626    */

1627    public Set<EnvironmentProperty> getEnvironmentProperties() {
1628    return environmentProperties;
1629    }
1630    
1631    
1632    /**
1633    * Add the supplied environment property to the ejb descriptor's list.
1634    */

1635    public void addEnvironmentProperty(EnvironmentProperty environmentProperty) {
1636    if (environmentProperties.contains(environmentProperty)) {
1637        replaceEnvironmentProperty(environmentProperty, environmentProperty);
1638    } else {
1639        environmentProperties.add(environmentProperty);
1640    }
1641    }
1642    
1643    /**
1644    * Return a copy of the role references set.
1645    */

1646    public Set<RoleReference> getRoleReferences() {
1647    if (roleReferences == null) {
1648        roleReferences = new HashSet();
1649    }
1650    return roleReferences;
1651    }
1652    
1653    /**
1654    * Adds a role reference.
1655    */

1656    
1657    public void addRoleReference(RoleReference roleReference) {
1658    //_logger.log(Level.FINE,"add " + roleReference);
1659
this.getRoleReferences().add(roleReference);
1660    this.changed();
1661    }
1662    
1663    /**
1664    * Removes a role reference.
1665    */

1666    
1667    public void removeRoleReference(RoleReference roleReference) {
1668    this.getRoleReferences().remove(roleReference);
1669    this.changed();
1670    }
1671    
1672    /**
1673    * Returns a matching role reference by name or throw an IllegalArgumentException.
1674    */

1675    public RoleReference getRoleReferenceByName(String JavaDoc roleReferenceName) {
1676    for (Iterator itr = this.getRoleReferences().iterator(); itr.hasNext();) {
1677        RoleReference nextRR = (RoleReference) itr.next();
1678        if (nextRR.getName().equals( roleReferenceName )) {
1679        return nextRR;
1680        }
1681    }
1682    return null;
1683    }
1684
1685    public List<InjectionCapable>
1686        getInjectableResourcesByClass(String JavaDoc className) {
1687        return bundleDescriptor.getInjectableResourcesByClass
1688            (className, this);
1689    }
1690
1691    public InjectionInfo getInjectionInfoByClass(String JavaDoc className) {
1692        return bundleDescriptor.getInjectionInfoByClass(className, this);
1693    }
1694
1695    /**
1696    * Gets the containing ejb bundle descriptor..
1697    */

1698    public EjbBundleDescriptor getEjbBundleDescriptor() {
1699    return bundleDescriptor;
1700    }
1701    
1702    public void setEjbBundleDescriptor(EjbBundleDescriptor bundleDescriptor) {
1703    this.bundleDescriptor = bundleDescriptor;
1704    }
1705
1706    /**
1707    * Gets the application to which this ejb descriptor belongs.
1708    */

1709    public Application getApplication() {
1710    if (getEjbBundleDescriptor() != null) {
1711        return getEjbBundleDescriptor().getApplication();
1712    }
1713    return null;
1714    }
1715    
1716    /**
1717    * Returns the full set of method descriptors I have (from all the methods on my home and remote interfaces).
1718    *
1719    */

1720    public Set getMethodDescriptors() {
1721        
1722    ClassLoader JavaDoc classLoader = getEjbBundleDescriptor().getClassLoader();
1723        Set methods = new HashSet();
1724    
1725        try {
1726            if (isRemoteInterfacesSupported()) {
1727                addAllInterfaceMethodsIn(methods, classLoader.loadClass(getHomeClassName()), MethodDescriptor.EJB_HOME);
1728                addAllInterfaceMethodsIn(methods, classLoader.loadClass(getRemoteClassName()), MethodDescriptor.EJB_REMOTE);
1729            }
1730
1731            if (isRemoteBusinessInterfacesSupported()) {
1732                for(String JavaDoc intf : getRemoteBusinessClassNames()) {
1733                    addAllInterfaceMethodsIn(methods, classLoader.loadClass(intf), MethodDescriptor.EJB_REMOTE);
1734                }
1735            }
1736
1737            if (isLocalInterfacesSupported()) {
1738                addAllInterfaceMethodsIn(methods, classLoader.loadClass(getLocalHomeClassName()), MethodDescriptor.EJB_LOCALHOME);
1739                addAllInterfaceMethodsIn(methods, classLoader.loadClass(getLocalClassName()), MethodDescriptor.EJB_LOCAL);
1740            }
1741
1742            if (isLocalBusinessInterfacesSupported()) {
1743                for(String JavaDoc intf : getLocalBusinessClassNames()) {
1744                    addAllInterfaceMethodsIn(methods, classLoader.loadClass(intf), MethodDescriptor.EJB_LOCAL);
1745                }
1746            }
1747
1748            if (hasWebServiceEndpointInterface()) {
1749                addAllInterfaceMethodsIn(methods, classLoader.loadClass(getWebServiceEndpointInterfaceName()), MethodDescriptor.EJB_WEB_SERVICE);
1750            }
1751        } catch (Throwable JavaDoc t) {
1752            /*
1753        t.printStackTrace();
1754        _logger.log(Level.SEVERE,localStrings.getLocalString(
1755                               "enterprise.deployment.errorloadingclass",
1756                               "Error loading class {0}", new Object [] {"(EjbDescriptor.getMethods())"}));
1757        */

1758          _logger.log(Level.SEVERE,"enterprise.deployment.backend.methodClassLoadFailure",new Object JavaDoc [] {"(EjbDescriptor.getMethods())"});
1759                                                           
1760        throw new RuntimeException JavaDoc(t);
1761    }
1762        return methods;
1763    }
1764 
1765    /**
1766     * Returns the full set of transactional business method descriptors I have.
1767     */

1768    public Set getTxBusinessMethodDescriptors() {
1769        Set txBusMethods = getBusinessMethodDescriptors();
1770        if (isTimedObject()) {
1771            txBusMethods.add(getEjbTimeoutMethod());
1772        }
1773        return txBusMethods;
1774    }
1775
1776    /**
1777     * Returns the full set of security business method descriptors I have.
1778     */

1779    public Set getSecurityBusinessMethodDescriptors() {
1780        return getBusinessMethodDescriptors();
1781    }
1782
1783    /**
1784     * Returns the full set of business method descriptors I have
1785     */

1786    private Set getBusinessMethodDescriptors() {
1787
1788        ClassLoader JavaDoc classLoader = getEjbBundleDescriptor().getClassLoader();
1789
1790        Set methods = new HashSet();
1791    
1792        try {
1793            if (isRemoteInterfacesSupported()) {
1794                addAllInterfaceMethodsIn(methods, classLoader.loadClass(getRemoteClassName()), MethodDescriptor.EJB_REMOTE);
1795            }
1796
1797            if (isRemoteBusinessInterfacesSupported()) {
1798                for(String JavaDoc intf : getRemoteBusinessClassNames()) {
1799                    addAllInterfaceMethodsIn(methods, classLoader.loadClass(intf), MethodDescriptor.EJB_REMOTE);
1800                }
1801            }
1802
1803            if (isLocalInterfacesSupported()) {
1804                addAllInterfaceMethodsIn(methods, classLoader.loadClass(getLocalClassName()), MethodDescriptor.EJB_LOCAL);
1805            }
1806
1807            if (isLocalBusinessInterfacesSupported()) {
1808                for(String JavaDoc intf : getLocalBusinessClassNames()) {
1809                    addAllInterfaceMethodsIn(methods, classLoader.loadClass(intf), MethodDescriptor.EJB_LOCAL);
1810                }
1811            }
1812
1813            if (hasWebServiceEndpointInterface()) {
1814                addAllInterfaceMethodsIn(methods, classLoader.loadClass(getWebServiceEndpointInterfaceName()), MethodDescriptor.EJB_WEB_SERVICE);
1815            }
1816        } catch (Throwable JavaDoc t) {
1817            _logger.log(Level.SEVERE,"enterprise.deployment.backend.methodClassLoadFailure",new Object JavaDoc [] {"(EjbDescriptor.getBusinessMethodDescriptors())"});
1818                                                           
1819        throw new RuntimeException JavaDoc(t);
1820    }
1821        return methods;
1822    }
1823 
1824    protected void addAllInterfaceMethodsIn(Collection methodDescriptors, Class JavaDoc c, String JavaDoc methodIntf) {
1825        Method JavaDoc[] methods = c.getMethods();
1826        for (int i=0;i<methods.length;i++) {
1827            methodDescriptors.add(new MethodDescriptor(methods[i], methodIntf));
1828        }
1829    }
1830        
1831    /**
1832     * @return the collection of MethodDescriptors to which ContainerTransactions
1833     * may be assigned.
1834     **/

1835    public Collection getTransactionMethodDescriptors() {
1836
1837        return getTransactionMethods(getEjbBundleDescriptor().getClassLoader());
1838    }
1839    
1840    /**
1841     * @return a collection of MethodDescriptor for methods which may
1842     * have a associated transaction attribute
1843     */

1844    protected Collection getTransactionMethods(ClassLoader JavaDoc classLoader) {
1845
1846    try {
1847            return BeanMethodCalculator.getTransactionalMethodsFor(this,classLoader);
1848    } catch (Throwable JavaDoc t) {
1849        
1850          _logger.log(Level.SEVERE,"enterprise.deployment.backend.methodClassLoadFailure",new Object JavaDoc [] {"(EjbDescriptor.getMethods())"});
1851
1852      throw new RuntimeException JavaDoc(t);
1853    }
1854    }
1855    
1856    /**
1857    * Return the set of method objects on my home and remote interfaces.
1858    */

1859    
1860    public Vector getMethods() {
1861    return getMethods(getEjbBundleDescriptor().getClassLoader());
1862    }
1863
1864    
1865    /**
1866    * Return the ejb method objects, i.e. the methods on the home and remote interfaces.
1867    */

1868    public Vector getMethods(ClassLoader JavaDoc classLoader) {
1869    try {
1870            return BeanMethodCalculator.getMethodsFor(this, classLoader);
1871    } catch (Throwable JavaDoc t) {
1872          _logger.log(Level.SEVERE,"enterprise.deployment.backend.methodClassLoadFailure",new Object JavaDoc [] {"(EjbDescriptor.getMethods())"});
1873        throw new RuntimeException JavaDoc(t);
1874    }
1875    }
1876    
1877    /**
1878    * Return a Vector of the Field objetcs of this ejb.
1879    */

1880    public Vector getFields() {
1881    Vector fieldsVector = new Vector();
1882    Class JavaDoc ejb = null;
1883    try {
1884        ClassLoader JavaDoc cl = getEjbBundleDescriptor().getClassLoader();
1885        ejb = cl.loadClass(this.getEjbClassName());
1886    } catch (Throwable JavaDoc t) {
1887          _logger.log(Level.SEVERE,"enterprise.deployment.backend.methodClassLoadFailure",new Object JavaDoc[] {this.getEjbClassName()});
1888
1889        return fieldsVector;
1890    }
1891    Field JavaDoc[] fields = ejb.getFields();
1892    for (int i = 0; i < fields.length; i++) {
1893        fieldsVector.addElement(fields[i]);
1894    }
1895    return fieldsVector;
1896    
1897    }
1898
1899    public Vector getFieldDescriptors() {
1900        Vector fields = this.getFields();
1901        Vector fieldDescriptors = new Vector();
1902        for(int fieldIndex = 0; fieldIndex < fields.size(); fieldIndex++) {
1903            Field JavaDoc field = (Field JavaDoc) fields.elementAt(fieldIndex);
1904            fieldDescriptors.insertElementAt(new FieldDescriptor(field) , fieldIndex);
1905        }
1906        return fieldDescriptors;
1907    }
1908        
1909    void doMethodDescriptorConversions() throws Exception JavaDoc {
1910    // container transactions first
1911
Hashtable transactions = this.getMethodContainerTransactions();
1912    //_logger.log(Level.FINE,"Pre conversion = " + transactions);
1913
Hashtable convertedTransactions = new Hashtable();
1914    Collection transactionMethods = this.getTransactionMethodDescriptors();
1915    for (Enumeration e = transactions.keys(); e.hasMoreElements();) {
1916        MethodDescriptor md = (MethodDescriptor) e.nextElement();
1917        ContainerTransaction ct = (ContainerTransaction) transactions.get(md);
1918        for (Enumeration mds = md.doStyleConversion(this, transactionMethods).elements(); mds.hasMoreElements();) {
1919        MethodDescriptor next = (MethodDescriptor) mds.nextElement();
1920        convertedTransactions.put(next, new ContainerTransaction(ct));
1921        }
1922    }
1923    //_logger.log(Level.FINE,"Post conversion = " + convertedTransactions);
1924
setMethodContainerTransactions(convertedTransactions);
1925    
1926        convertMethodPermissions();
1927    }
1928 
1929    public void removeEjbReferencer(EjbReferenceDescriptor ref)
1930    {
1931    ejbReferencersPointingToMe.remove(ref);
1932    }
1933
1934    // called from EjbReferenceDescriptor.setEjbDescriptor
1935
void addEjbReferencer(EjbReferenceDescriptor ref)
1936    {
1937    ejbReferencersPointingToMe.add(ref);
1938    }
1939
1940    // called from EjbEntityDescriptor.replaceEntityDescriptor etc
1941
public Set getAllEjbReferencers()
1942    {
1943    return ejbReferencersPointingToMe;
1944    }
1945
1946
1947    // Called from EjbBundleDescriptor only
1948
public void setUniqueId(long id)
1949    {
1950    uniqueId = id;
1951    }
1952
1953    public long getUniqueId()
1954    {
1955    return uniqueId;
1956    }
1957
1958
1959    /**
1960    * Call to notify my listeners of a state change.
1961    */

1962    
1963    public void changed() {
1964    if (this.getEjbBundleDescriptor() != null) {
1965        this.getEjbBundleDescriptor().changed();
1966    } else {
1967        super.changed();
1968    }
1969    }
1970    
1971    /**
1972    * Returns a formatted String of the attributes of this object.
1973    */

1974    public void print(StringBuffer JavaDoc toStringBuffer) {
1975    super.print(toStringBuffer);
1976    toStringBuffer.append("\n ejbClassName ").append(ejbClassName);
1977    toStringBuffer.append("\n transactionType ").append(transactionType);
1978    toStringBuffer.append("\n methodContainerTransactions ").append(getMethodContainerTransactions());
1979    toStringBuffer.append("\n environmentProperties ");
1980        if(environmentProperties != null)
1981            printDescriptorSet(environmentProperties,toStringBuffer);
1982    toStringBuffer.append("\n ejbReferences ");
1983        if(ejbReferences != null)
1984            printDescriptorSet(ejbReferences,toStringBuffer);
1985        toStringBuffer.append("\n jmsDestReferences ");
1986        if(jmsDestReferences != null)
1987            printDescriptorSet(jmsDestReferences,toStringBuffer);
1988        toStringBuffer.append("\n messageDestReferences ");
1989        if(messageDestReferences != null)
1990            printDescriptorSet(messageDestReferences,toStringBuffer);
1991    toStringBuffer.append("\n resourceReferences ");
1992        if(resourceReferences != null)
1993            printDescriptorSet(resourceReferences,toStringBuffer);
1994    toStringBuffer.append("\n serviceReferences ");
1995        if(serviceReferences != null)
1996            printDescriptorSet(serviceReferences,toStringBuffer);
1997    toStringBuffer.append("\n roleReferences ");
1998        if(roleReferences != null)
1999            printDescriptorSet(roleReferences,toStringBuffer);
2000    for (Iterator e = this.getPermissionedMethodsByPermission().keySet().iterator(); e.hasNext();) {
2001        MethodPermission nextPermission = (MethodPermission) e.next();
2002        toStringBuffer.append("\n method-permission->method: ");
2003            nextPermission.print(toStringBuffer);
2004            toStringBuffer.append(" -> ").append(this.getPermissionedMethodsByPermission().get(nextPermission));
2005    }
2006    }
2007    private void printDescriptorSet(Set descSet, StringBuffer JavaDoc sbuf){
2008        for(Iterator itr = descSet.iterator(); itr.hasNext();){
2009            Object JavaDoc obj = itr.next();
2010            if(obj instanceof Descriptor)
2011                ((Descriptor)obj).print(sbuf);
2012            else
2013                sbuf.append(obj);
2014        }
2015    }
2016    
2017    /**
2018     * visit the descriptor and all sub descriptors with a DOL visitor implementation
2019     *
2020     * @param a visitor to traverse the descriptors
2021     */

2022    public void visit(DescriptorVisitor aVisitor) {
2023        if (aVisitor instanceof EjbVisitor) {
2024            visit((EjbVisitor) aVisitor);
2025        } else {
2026            super.visit(aVisitor);
2027        }
2028    }
2029    
2030    /**
2031     * visit the descriptor and all sub descriptors with a DOL visitor implementation
2032     *
2033     * @param a visitor to traverse the descriptors
2034     */

2035    public void visit(EjbVisitor aVisitor) {
2036        aVisitor.accept(this);
2037
2038        // Visit all injectables first. In some cases, basic type information
2039
// has to be derived from target inject method or inject field.
2040
for(InjectionCapable injectable :
2041                bundleDescriptor.getInjectableResources(this)) {
2042            aVisitor.accept(injectable);
2043        }
2044
2045        for (Iterator itr = ejbReferences.iterator();itr.hasNext();) {
2046            EjbReference aRef = (EjbReference) itr.next();
2047            aVisitor.accept(aRef);
2048        }
2049    for (Iterator e = getPermissionedMethodsByPermission().keySet().iterator(); e.hasNext();) {
2050        MethodPermission nextPermission = (MethodPermission) e.next();
2051            Set methods = (Set) getPermissionedMethodsByPermission().get(nextPermission);
2052            aVisitor.accept( nextPermission, methods.iterator()) ;
2053    }
2054        if (getStyledPermissionedMethodsByPermission()!=null) {
2055            for (Iterator e = getStyledPermissionedMethodsByPermission().keySet().iterator(); e.hasNext();) {
2056                MethodPermission nextPermission = (MethodPermission) e.next();
2057                Set methods = (Set) getStyledPermissionedMethodsByPermission().get(nextPermission);
2058                aVisitor.accept( nextPermission, methods.iterator()) ;
2059            }
2060        }
2061        for (Iterator e = getRoleReferences().iterator();e.hasNext();) {
2062            RoleReference roleRef = (RoleReference) e.next();
2063            aVisitor.accept( roleRef);
2064        }
2065        for (Iterator e=getMethodContainerTransactions().keySet().iterator();e.hasNext();) {
2066            MethodDescriptor md = (MethodDescriptor) e.next();
2067            ContainerTransaction ct = (ContainerTransaction) getMethodContainerTransactions().get(md);
2068            aVisitor.accept(md, ct);
2069        }
2070        for (Iterator e=getEnvironmentProperties().iterator();e.hasNext();) {
2071            EnvironmentProperty envProp = (EnvironmentProperty) e.next();
2072            aVisitor.accept(envProp);
2073        }
2074        
2075        for (Iterator it=getResourceReferenceDescriptors().iterator();
2076             it.hasNext();) {
2077            ResourceReferenceDescriptor next =
2078                (ResourceReferenceDescriptor) it.next();
2079            aVisitor.accept(next);
2080        }
2081
2082        for (Iterator it=getJmsDestinationReferenceDescriptors().iterator();
2083             it.hasNext();) {
2084            JmsDestinationReferenceDescriptor next =
2085                (JmsDestinationReferenceDescriptor) it.next();
2086            aVisitor.accept(next);
2087        }
2088
2089        for (Iterator it=getMessageDestinationReferenceDescriptors().iterator();
2090             it.hasNext();) {
2091            MessageDestinationReferencer next =
2092                (MessageDestinationReferencer) it.next();
2093            aVisitor.accept(next);
2094        }
2095
2096        // If this is a message bean, it can be a message destination
2097
// referencer as well.
2098
if( getType().equals(EjbMessageBeanDescriptor.TYPE) ) {
2099            MessageDestinationReferencer msgDestReferencer =
2100                (MessageDestinationReferencer) this;
2101            if( msgDestReferencer.getMessageDestinationLinkName() != null ) {
2102                aVisitor.accept(msgDestReferencer);
2103            }
2104        }
2105
2106        Set serviceRefs = getServiceReferenceDescriptors();
2107        for (Iterator itr = serviceRefs.iterator();itr.hasNext();) {
2108            aVisitor.accept((ServiceReferenceDescriptor) itr.next());
2109        }
2110    }
2111
2112
2113
2114    
2115}
2116    
2117
Popular Tags