KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_ejb > deployment > api > BeanDesc


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999-2004 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: BeanDesc.java,v 1.59 2005/07/13 06:29:45 durieuxp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas_ejb.deployment.api;
27
28 import java.lang.reflect.Modifier JavaDoc;
29 import java.rmi.RemoteException JavaDoc;
30 import java.util.ArrayList JavaDoc;
31 import java.util.Arrays JavaDoc;
32 import java.util.Comparator JavaDoc;
33 import java.util.HashMap JavaDoc;
34 import java.util.Iterator JavaDoc;
35 import java.util.LinkedList JavaDoc;
36 import java.util.List JavaDoc;
37 import java.util.Properties JavaDoc;
38
39 import org.omg.CSI.ITTAbsent;
40 import org.omg.CSI.ITTAnonymous;
41 import org.omg.CSI.ITTDistinguishedName;
42 import org.omg.CSI.ITTPrincipalName;
43 import org.omg.CSI.ITTX509CertChain;
44 import org.omg.CSIIOP.Confidentiality;
45 import org.omg.CSIIOP.EstablishTrustInClient;
46 import org.omg.CSIIOP.EstablishTrustInTarget;
47 import org.omg.CSIIOP.IdentityAssertion;
48 import org.omg.CSIIOP.Integrity;
49
50 import org.objectweb.carol.util.csiv2.SasComponent;
51 import org.objectweb.carol.util.csiv2.struct.AsStruct;
52 import org.objectweb.carol.util.csiv2.struct.SasStruct;
53 import org.objectweb.carol.util.csiv2.struct.TransportStruct;
54
55 import org.objectweb.jonas_ejb.container.BeanFactory;
56 import org.objectweb.jonas_ejb.container.TraceEjb;
57 import org.objectweb.jonas_ejb.deployment.xml.AsContextMapping;
58 import org.objectweb.jonas_ejb.deployment.xml.AssemblyDescriptor;
59 import org.objectweb.jonas_ejb.deployment.xml.CommonEjb;
60 import org.objectweb.jonas_ejb.deployment.xml.ContainerTransaction;
61 import org.objectweb.jonas_ejb.deployment.xml.IorSecurityConfigMapping;
62 import org.objectweb.jonas_ejb.deployment.xml.JonasCommonEjb;
63 import org.objectweb.jonas_ejb.deployment.xml.Method;
64 import org.objectweb.jonas_ejb.deployment.xml.MethodPermission;
65 import org.objectweb.jonas_ejb.deployment.xml.SasContextMapping;
66 import org.objectweb.jonas_ejb.deployment.xml.TransportConfigMapping;
67 import org.objectweb.jonas_ejb.lib.BeanNaming;
68 import org.objectweb.jonas_ejb.lib.JavaType;
69
70 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException;
71 import org.objectweb.jonas_lib.deployment.api.EjbLocalRefDesc;
72 import org.objectweb.jonas_lib.deployment.api.EjbRefDesc;
73 import org.objectweb.jonas_lib.deployment.api.EnvEntryDesc;
74 import org.objectweb.jonas_lib.deployment.api.JndiEnvRefsGroupDesc;
75 import org.objectweb.jonas_lib.deployment.api.MessageDestinationRefDesc;
76 import org.objectweb.jonas_lib.deployment.api.ResourceEnvRefDesc;
77 import org.objectweb.jonas_lib.deployment.api.ResourceRefDesc;
78 import org.objectweb.jonas_lib.deployment.api.SecurityRoleRefDesc;
79 import org.objectweb.jonas_lib.deployment.xml.JLinkedList;
80 import org.objectweb.jonas_lib.deployment.xml.RunAs;
81 import org.objectweb.jonas_lib.deployment.xml.SecurityRole;
82 import org.objectweb.jonas_lib.deployment.xml.SecurityRoleRef;
83
84 import org.objectweb.jonas_ws.deployment.api.ServiceRefDesc;
85
86 import org.objectweb.util.monolog.api.BasicLevel;
87 import org.objectweb.util.monolog.api.Logger;
88
89 /**
90  * Class to hold meta-information related to any enterprise-beans
91  *
92  * @author Christophe Ney [cney@batisseurs.com] : Initial developer
93  * @author Helene Joanin
94  * @author Jeff Mesnil
95  * @author Philippe Coq
96  * @author Florent Benoit & Ludovic Bert : ejb_link
97  */

98 public abstract class BeanDesc extends JndiEnvRefsGroupDesc {
99
100     /**
101      * Bean transaction type
102      */

103     protected static final int BEAN_TRANSACTION_TYPE = 1;
104
105     /**
106      * Container transaction type
107      */

108     protected static final int CONTAINER_TRANSACTION_TYPE = 2;
109
110     protected static final String JavaDoc[] TRANS = {null, "BEAN_TRANSACTION_TYPE", "CONTAINER_TRANSACTION_TYPE"};
111
112     private static final String JavaDoc ejb10PropertiesPrefix = "ejb10-properties/";
113
114     /**
115      * When no jndi-name specified, jndi name is set to Ejb-Name + "Home"
116      */

117     private static final String JavaDoc REMOTEDEFAULTSUFFIX = "Home";
118
119     /**
120      * When no local-jndi-name specified, local jndi name is set to jndi-name +
121      * "_L"
122      */

123     private static final String JavaDoc LOCALDEFAULTSUFFIX = "_L";
124
125     /**
126      * Package prefix for generated files
127      */

128     public static final String JavaDoc GENERATED_PREFIX = "org.objectweb.jonas_gen.";
129
130     /**
131      * name of the Bean
132      */

133     protected String JavaDoc ejbName = null;
134
135     /**
136      * JNDI name of the Bean
137      */

138     protected String JavaDoc jndiName = null;
139
140     /**
141      * JNDI local name of the Bean
142      */

143     protected String JavaDoc jndiLocalName = null;
144
145     /**
146      * Home Class
147      */

148     protected Class JavaDoc home = null;
149
150     /**
151      * Remote Class
152      */

153     protected Class JavaDoc remote = null;
154
155     /**
156      * LocalHome Class
157      */

158     protected Class JavaDoc localhome = null;
159
160     /**
161      * Local Class
162      */

163     protected Class JavaDoc local = null;
164
165     /**
166      * Bean Class
167      */

168     protected Class JavaDoc ejbClass = null;
169
170     /**
171      * bean identification string
172      */

173     protected String JavaDoc beanIdentification = null;
174     
175     /**
176      * EJB 1.0 Environment as Properties
177      */

178     protected Properties JavaDoc ejb10EnvProps = new Properties JavaDoc();
179
180     /**
181      * logger
182      */

183     protected Logger logger = null;
184
185     /**
186      * array of methods meta-info
187      */

188     private ArrayList JavaDoc methodDesc = new ArrayList JavaDoc();
189
190     /**
191      * hash map of the methods
192      */

193     private HashMap JavaDoc methodDescMap = new HashMap JavaDoc();
194
195     /**
196      * List of SecurityRoleRefDesc for JACC
197      */

198     protected List JavaDoc securityRoleRefDescList = null;
199
200     /**
201      * DeploymentDesc parent of this BeanDesc
202      */

203     protected DeploymentDesc deploymentDesc = null;
204
205     /**
206      * JOnAS Remote Wrapper fully qualified classname
207      */

208     private String JavaDoc fullWrpRemoteName = null;
209
210     /**
211      * JOnAS Remote Wrapper Classname
212      */

213     private String JavaDoc wrpRemoteName = null;
214
215     /**
216      * JOnAS Home Wrapper fully qualified classname
217      */

218     private String JavaDoc fullWrpHomeName = null;
219
220     /**
221      * JOnAS Home Wrapper Classname
222      */

223     private String JavaDoc wrpHomeName = null;
224
225     /**
226      * JOnAS Local Wrapper fully qualified classname
227      */

228     private String JavaDoc fullWrpLocalName = null;
229
230     /**
231      * JOnAS Local Wrapper Classname
232      */

233     private String JavaDoc wrpLocalName = null;
234
235     /**
236      * JOnAS LocalHome Wrapper fully qualified classname
237      */

238     private String JavaDoc fullWrpLocalHomeName = null;
239
240     /**
241      * JOnAS LocalHome Wrapper Classname
242      */

243     private String JavaDoc wrpLocalHomeName = null;
244
245     /**
246      * JOnAS Handle Wrapper fully qualified classname
247      */

248     private String JavaDoc fullWrpHandleName = null;
249
250     /**
251      * JOnAS Handle Wrapper Classname
252      */

253     private String JavaDoc wrpHandleName = null;
254
255     /**
256      * Bean fully qualified classname
257      */

258     protected String JavaDoc fullDerivedBeanName = null;
259
260     /**
261      * Bean classname
262      */

263     protected String JavaDoc derivedBeanName = null;
264
265     /**
266      * Run-as role
267      */

268     private String JavaDoc runAsRole = null;
269
270     /**
271      * Run-as principal name
272      */

273     private String JavaDoc runAsPrincipalName = null;
274
275     /**
276      * Minimum Bean Pool size
277      */

278     protected int poolMin = 0;
279
280     /**
281      * Maximum Bean Cache size
282      */

283     protected int cacheMax = 0;
284
285     /**
286      * SasComponent (for CSIv2 over IIOP)
287      */

288     private SasComponent sasComponent = null;
289
290     protected int timerTxAttribute = MethodDesc.TX_REQUIRES_NEW; // default
291

292     protected String JavaDoc ejbTimeoutSignature;
293
294     /**
295      * BeanFactory when the bean has been loaded.
296      */

297     protected BeanFactory bf = null;
298
299     /**
300      * Constructor to be used by parent node
301      *
302      * @param classLoader ClassLoader used to load Bean's classes
303      * @param ejb XML Element from standard Deployment Descriptor
304      * @param jonasEjb XML Element from jonas specific Deployment Descriptor
305      * @param asd XML Element for the AssemblyDescriptor
306      * @param fileName jar filename
307      *
308      * @throws DeploymentDescException when BeanDesc cannot be instanciated
309      * (class loading problem, ...)
310      */

311     public BeanDesc(ClassLoader JavaDoc classLoader, CommonEjb ejb, JonasCommonEjb jonasEjb, AssemblyDescriptor asd,
312             JLinkedList jMDRList, String JavaDoc fileName) throws DeploymentDescException {
313
314         super(classLoader, ejb, jonasEjb, fileName);
315         securityRoleRefDescList = new LinkedList JavaDoc();
316         if (ejb.getEjbName() != null) {
317             ejbName = ejb.getEjbName();
318         } else {
319             ejbName = null;
320         }
321
322         // If no value given specifically, we use ejbName+Home as JNDI name.
323
if (jonasEjb.getJndiName() != null) {
324             jndiName = jonasEjb.getJndiName();
325         } else {
326             jndiName = ejbName + REMOTEDEFAULTSUFFIX;
327         }
328         // If no value given specifically, we use jndiName+_L as JNDI local
329
// name.
330
if (jonasEjb.getJndiLocalName() != null) {
331             jndiLocalName = jonasEjb.getJndiLocalName();
332         } else {
333             jndiLocalName = jndiName + LOCALDEFAULTSUFFIX;
334         }
335
336         // classes
337
// --------------------------------------------------
338
if (ejb.getHome() != null) {
339             try {
340                 this.home = classLoader.loadClass(ejb.getHome());
341                 // check home extends javax.ejb.EJBHome
342
if (!javax.ejb.EJBHome JavaDoc.class.isAssignableFrom(this.home)) {
343                     throw new DeploymentDescException("Home class '" + ejb.getHome()
344                             + "' doesn't not extends javax.ejb.EJBHome");
345                 }
346             } catch (ClassNotFoundException JavaDoc e) {
347                 throw new DeploymentDescException("Home class not found for bean " + ejbName, e);
348             }
349         }
350
351         if (ejb.getRemote() != null) {
352             try {
353                 this.remote = classLoader.loadClass(ejb.getRemote());
354                 // check remote extends javax.ejb.EJBObject
355
if (!javax.ejb.EJBObject JavaDoc.class.isAssignableFrom(this.remote)) {
356                     throw new DeploymentDescException("Remote class '" + ejb.getRemote()
357                             + "' doesn't not extends javax.ejb.EJBObject");
358                 }
359             } catch (ClassNotFoundException JavaDoc e) {
360                 throw new DeploymentDescException("Remote class not found for bean " + ejbName, e);
361             }
362         }
363
364         String JavaDoc localhomename = ejb.getLocalHome();
365         // Note: Should do this only if bean is implied in a relation.
366
if (localhomename == null && this instanceof EntityCmp2Desc) {
367             localhomename = "javax.ejb.EJBLocalHome";
368         }
369         if (localhomename != null) {
370             try {
371                 this.localhome = classLoader.loadClass(localhomename);
372                 // check localhome extends javax.ejb.EJBLocalHome
373
if (!javax.ejb.EJBLocalHome JavaDoc.class.isAssignableFrom(this.localhome)) {
374                     throw new DeploymentDescException("LocalHome class '" + localhomename
375                             + "' doesn't not extends javax.ejb.EJBLocalHome");
376                 }
377             } catch (ClassNotFoundException JavaDoc e) {
378                 throw new DeploymentDescException("LocalHome class not found for bean " + ejbName, e);
379             }
380         }
381
382         String JavaDoc localname = ejb.getLocal();
383         // Note: Should do this only if bean is implied in a relation.
384
if (localname == null && this instanceof EntityCmp2Desc) {
385             localname = "javax.ejb.EJBLocalObject";
386         }
387         if (localname != null) {
388             try {
389                 this.local = classLoader.loadClass(localname);
390                 // check local extends javax.ejb.EJBLocalObject
391
if (!javax.ejb.EJBLocalObject JavaDoc.class.isAssignableFrom(this.local)) {
392                     throw new DeploymentDescException("Local class '" + localname
393                             + "' doesn't not extends javax.ejb.EJBLocalObject");
394                 }
395             } catch (ClassNotFoundException JavaDoc e) {
396                 throw new DeploymentDescException("Local class not found for bean " + ejbName, e);
397             }
398         }
399
400         // permit to load service-endpoint class
401
loadExtraClasses(ejb, classLoader);
402
403         try {
404             this.ejbClass = classLoader.loadClass(ejb.getEjbClass());
405             // check ejb-class extends javax.ejb.EnterpriseBean
406
if (!javax.ejb.EnterpriseBean JavaDoc.class.isAssignableFrom(this.ejbClass)) {
407                 throw new DeploymentDescException("Ejb class '" + ejb.getEjbClass()
408                         + "' doesn't not extends javax.ejb.EnterpriseBean");
409             }
410         } catch (ClassNotFoundException JavaDoc e) {
411             throw new DeploymentDescException("Ejb class not found for bean " + ejbName, e);
412         }
413
414         // Set EJB 1.0 Environment properties from env entries
415
EnvEntryDesc[] envt = getEnvEntryDesc();
416         for (int i = 0; i < envt.length; i++) {
417             if (envt[i].getName().startsWith(ejb10PropertiesPrefix)) {
418                 String JavaDoc newName = envt[i].getName().substring(ejb10PropertiesPrefix.length());
419                 String JavaDoc value = new String JavaDoc();
420                 if (envt[i].hasValue()) {
421                     value = envt[i].getValue().toString();
422                 }
423                 ejb10EnvProps.put(newName, value);
424             }
425         }
426
427         // run-as
428
if (ejb.getSecurityIdentity() != null) {
429             RunAs runAsElem = ejb.getSecurityIdentity().getRunAs();
430             if (runAsElem != null) {
431                 String JavaDoc roleName = runAsElem.getRoleName();
432                 if (roleName != null) {
433                     runAsRole = roleName;
434                     boolean runAsRoleFound = false;
435                     for (Iterator JavaDoc j = asd.getSecurityRoleList().iterator(); j.hasNext();) {
436                         SecurityRole securityRole = (SecurityRole) j.next();
437                         // role name of a security-role element defined in the
438
// assembly descriptor
439
String JavaDoc r = securityRole.getRoleName();
440                         if (r.equals(runAsRole)) {
441                             runAsRoleFound = true;
442                         }
443                     }
444                     //if there are no matching run-as and security-role
445
if (!runAsRoleFound) {
446                         throw new DeploymentDescException("There is no security-role defined for the run-as role: "
447                                 + runAsRole);
448                     }
449                 }
450                 // Run-as principal name
451
runAsPrincipalName = jonasEjb.getRunAsPrincipalName();
452                 // if no principal name set in JOnAS DD, set it to run-as role
453
if (runAsPrincipalName == null) {
454                     runAsPrincipalName = runAsRole;
455                 }
456             }
457         }
458
459         // populate array with all methods
460
try {
461             java.lang.reflect.Method JavaDoc[] m;
462             int beginIdx = methodDesc.size();
463             int len = 0;
464             if ((this.home != null) && (this.remote != null)) {
465                 // session bean or entity bean with remote interface
466
m = this.home.getMethods();
467                 for (int i = 0; i < m.length; i++) {
468                     if (!m[i].getDeclaringClass().equals(javax.ejb.EJBHome JavaDoc.class)
469                         || m[i].getName().equals("remove")) {
470                         addMethodDesc(m[i], this.home);
471                         len++;
472                         // check RemoteException is thrown
473
checkRemoteException(m[i], true);
474                         /*
475                          * // arguments and return types must be valid types for
476                          * RMI if
477                          * (!m[i].getDeclaringClass().equals(javax.ejb.EJBHome.class) &&
478                          * !m[i].getName().equals("findByPrimaryKey")) {
479                          * checkValidTypesForRmi(m[i]); }
480                          */

481                     }
482                 }
483
484                 m = this.remote.getMethods();
485                 for (int i = 0; i < m.length; i++) {
486                     if (!m[i].getDeclaringClass().equals(javax.ejb.EJBObject JavaDoc.class)
487                         || m[i].getName().equals("remove")) {
488                         addMethodDesc(m[i], this.remote);
489                         len++;
490                         // check RemoteException is thrown
491
checkRemoteException(m[i], true);
492                         /*
493                          * // arguments and return types must be valid for RMI
494                          * if
495                          * (!m[i].getDeclaringClass().equals(javax.ejb.EJBObject.class)) {
496                          * checkValidTypesForRmi(m[i]); }
497                          */

498                     }
499                 }
500             }
501             if ((this.localhome != null) && (this.local != null)) {
502                 // session bean or entity bean with local interface
503
m = this.localhome.getMethods();
504                 for (int i = 0; i < m.length; i++) {
505                     if (!m[i].getDeclaringClass().equals(javax.ejb.EJBLocalHome JavaDoc.class)
506                             || m[i].getName().equals("remove")) {
507                         addMethodDesc(m[i], this.localhome);
508                         len++;
509                         // check RemoteException is NOT thrown
510
checkRemoteException(m[i], false);
511                     }
512                 }
513                 m = this.local.getMethods();
514                 for (int i = 0; i < m.length; i++) {
515                     if (!m[i].getDeclaringClass().equals(javax.ejb.EJBLocalObject JavaDoc.class)
516                         || m[i].getName().equals("remove")) {
517                         addMethodDesc(m[i], this.local);
518                         len++;
519                         // check RemoteException is NOT thrown
520
checkRemoteException(m[i], false);
521                     }
522                 }
523             }
524             if (this.home == null && this.localhome == null) {
525
526                 if (ejb.getMessagingType() != null) {
527                     // message driven bean & endpoints
528
String JavaDoc msgType = ejb.getMessagingType();
529                     try {
530                         m = classLoader.loadClass(msgType).getMethods();
531                         for (int i = 0; i < m.length; i++) {
532                             addMethodDesc(m[i], m[i].getDeclaringClass());
533                             len++;
534                         }
535                     } catch (Exception JavaDoc ex) {
536                         throw new DeploymentDescException("Cannot load messaging type class (" + msgType + ") for "
537                                 + ejbName, ex);
538                     }
539                 }
540                 // (web)service-endpoints may have no home or local-home too !!
541
}
542
543             if (javax.ejb.EntityBean JavaDoc.class.isAssignableFrom(this.ejbClass)) {
544                 // ejbSelect methods
545
m = this.ejbClass.getMethods();
546                 for (int i = 0; i < m.length; i++) {
547                     if (m[i].getName().startsWith("ejbSelect") && Modifier.isAbstract(m[i].getModifiers())) {
548                         addMethodDesc(m[i], this.ejbClass);
549                         len++;
550                     }
551                 }
552             }
553
554             if (javax.ejb.TimedObject JavaDoc.class.isAssignableFrom(this.ejbClass)) {
555                 try {
556                     java.lang.reflect.Method JavaDoc timeout = this.ejbClass.getMethod("ejbTimeout",
557                             new Class JavaDoc[]{javax.ejb.Timer JavaDoc.class});
558                     addMethodDesc(timeout, this.ejbClass);
559                     len++;
560                 } catch (NoSuchMethodException JavaDoc e) {
561                     throw new DeploymentDescException("ejbTimeout not implemented in " + ejbName);
562                 }
563             }
564
565             len = addEJBMethodDesc(len);
566             orderMethodDesc(methodDesc, beginIdx, len);
567         } catch (SecurityException JavaDoc e) {
568             throw new DeploymentDescException("Cannot use java reflection on " + ejbName, e);
569         }
570
571         // populate HashMap with all security role references
572
// for each security-role-ref of the bean
573
if (ejb.getSecurityRoleRefList() != null) {
574             for (Iterator JavaDoc i = ejb.getSecurityRoleRefList().iterator(); i.hasNext();) {
575                 SecurityRoleRef sRoleRef = (SecurityRoleRef) i.next();
576                 // test if the assembly-descriptor element exists
577
if (asd == null) {
578                     throw new DeploymentDescException(
579                             "No assembly-descriptor element (and security-role elements) whereas security-role-ref element(s) are defined");
580                 } else {
581                     // test if the assembly-descriptor element contains
582
// security-role elements
583
if (asd.getSecurityRoleList().isEmpty()) {
584                         throw new DeploymentDescException(
585                                 "No security-role elements defined in the assembly-descriptor element whereas security-role-ref element(s) are defined");
586                     }
587                 }
588                 // test if the role-link element of the security-role-ref
589
// element exists
590
if (sRoleRef.getRoleLink() == null) {
591                     throw new DeploymentDescException(
592                             "No role-link element in a security-role-ref element with role-name element : "
593                                     + sRoleRef.getRoleName());
594                 }
595                 String JavaDoc roleLink = sRoleRef.getRoleLink();
596                 // correspond to role-name element in security-role-ref element
597
String JavaDoc roleRefName = sRoleRef.getRoleName();
598                 // to know if there are corresponding roleLink and roleRefName
599
boolean correspondingRoles = false;
600                 for (Iterator JavaDoc j = asd.getSecurityRoleList().iterator(); j.hasNext();) {
601                     SecurityRole securityRole = (SecurityRole) j.next();
602                     // role name of a security-role element defined in the
603
// assembly descriptor
604
String JavaDoc roleName = securityRole.getRoleName();
605                     if (roleName.equals(roleLink)) {
606                         securityRoleRefDescList.add(new SecurityRoleRefDesc(ejbName, sRoleRef, true));
607                         correspondingRoles = true;
608                     }
609                 }
610                 //if there are no matching roleLink and roleName
611
if (!correspondingRoles) {
612                     throw new DeploymentDescException(
613                             "No corresponding role-name in a security-role element for role-link : " + roleLink);
614                 }
615             }
616         }
617
618         // check if there are corresponding role-name element in security-role
619
// and method-permission element of the Assembly Descriptor
620
if (asd != null) {
621             verifyRoleName(asd);
622             // set method descriptor values for method permissions
623
for (Iterator JavaDoc i = asd.getMethodPermissionList().iterator(); i.hasNext();) {
624                 MethodPermission methodPermission = (MethodPermission) i.next();
625                 for (Iterator JavaDoc j = methodPermission.getMethodList().iterator(); j.hasNext();) {
626                     Method m = ((Method) j.next());
627                     // check method applies to current bean
628
if (!m.getEjbName().equals(ejbName)) {
629                         continue;
630                     }
631                     // selection of interface home/remote
632
Class JavaDoc pClass = null;
633                     if (m.getMethodIntf() != null) {
634                         pClass = getParentClass(m.getMethodIntf());
635                     }
636                     for (int k = 0; k < methodDesc.size(); k++) {
637                         MethodDesc md = (MethodDesc) methodDesc.get(k);
638                         int matchStatus = md.matchPattern(pClass, m.getMethodName(), m.getMethodParams());
639                         for (Iterator JavaDoc l = methodPermission.getRoleNameList().iterator(); l.hasNext();) {
640                             String JavaDoc roleName = (String JavaDoc) l.next();
641                             // Add only if it greater than APPLY_TO_NOTHING
642
if (matchStatus > MethodDesc.APPLY_TO_NOTHING) {
643                                 md.addRoleName(roleName);
644                             }
645                         }
646                     }
647                 }
648             }
649         }
650
651         // Set excluded method
652
if (asd != null && asd.getExcludeList() != null) {
653             // For each excluded method, find a methodDesc corresponding to this excluded method
654
for (Iterator JavaDoc i = asd.getExcludeList().getMethodList().iterator(); i.hasNext();) {
655                 Method m = (Method) i.next();
656                 // check method applies to current bean
657
if (!m.getEjbName().equals(ejbName)) {
658                     continue;
659                 }
660                 // selection of interface home/remote
661
Class JavaDoc pClass = null;
662                 if (m.getMethodIntf() != null) {
663                     pClass = getParentClass(m.getMethodIntf());
664                 }
665                 // Find methodDesc with matching pattern of excluded method
666
for (int k = 0; k < methodDesc.size(); k++) {
667                     MethodDesc md = (MethodDesc) methodDesc.get(k);
668                     int matchStatus = md.matchPattern(pClass, m.getMethodName(), m.getMethodParams());
669                     // Add only if it greater than APPLY_TO_NOTHING
670
if (matchStatus > MethodDesc.APPLY_TO_NOTHING) {
671                         md.setExcluded(true);
672                     }
673                 }
674             }
675         }
676
677         // set method descriptor values for container transactions
678
if (asd != null) {
679             // Loop on ContainerTransaction list
680
Iterator JavaDoc i = asd.getContainerTransactionList().iterator();
681             while (i.hasNext()) {
682                 ContainerTransaction cotr = (ContainerTransaction) i.next();
683                 // Loop on Method list
684
Iterator JavaDoc j = cotr.getMethodList().iterator();
685                 while (j.hasNext()) {
686                     Method m = (Method) j.next();
687                     // check method applies to current bean
688
if (!m.getEjbName().equals(ejbName)) {
689                         continue;
690                     }
691
692                     // selection of interface home/remote
693
Class JavaDoc pClass = null;
694                     if (m.getMethodIntf() != null) {
695                         pClass = getParentClass(m.getMethodIntf());
696                     }
697
698                     // loop on methods in the array
699
boolean found = false;
700                     for (int k = 0; k < methodDesc.size(); k++) {
701                         MethodDesc md = (MethodDesc) methodDesc.get(k);
702                         int matchStatus = md.matchPattern(pClass, m.getMethodName(), m.getMethodParams());
703                         if (matchStatus != MethodDesc.APPLY_TO_NOTHING) {
704                             found = true;
705                         }
706                         // set if proper level of assignation
707
String JavaDoc transAttribute = null;
708                         if (cotr.getTransAttribute() != null) {
709                             transAttribute = cotr.getTransAttribute();
710                         }
711                         md.overwriteTxAttribute(transAttribute, matchStatus);
712                     }
713                     if (!found) {
714                         // The method defined via the <method> element is not a
715
// declared method
716
TraceEjb.dd.log(BasicLevel.WARN, "Invalid container-transaction: method '"
717                                 + MethodDesc.methodElementToString(m) + "' not declared in bean " + ejbName);
718                     }
719                 }
720             }
721         }
722
723         String JavaDoc packageName = "";
724         String JavaDoc ejbIdentifier = getIdentifier();
725
726         if (getRemoteClass() != null) {
727             packageName = GENERATED_PREFIX + BeanNaming.getPackageName(getRemoteClass().getName());
728             wrpRemoteName = new String JavaDoc("JOnAS" + ejbIdentifier + "Remote");
729             wrpHandleName = new String JavaDoc("JOnAS" + ejbIdentifier + "Handle");
730             fullWrpRemoteName = BeanNaming.getClassName(packageName, wrpRemoteName);
731             fullWrpHandleName = BeanNaming.getClassName(packageName, wrpHandleName);
732         }
733
734         if (getLocalClass() != null) {
735             packageName = GENERATED_PREFIX + BeanNaming.getPackageName(getLocalClass().getName());
736             wrpLocalName = new String JavaDoc("JOnAS" + ejbIdentifier + "Local");
737             fullWrpLocalName = BeanNaming.getClassName(packageName, wrpLocalName);
738         }
739
740         if (getHomeClass() != null) {
741             packageName = GENERATED_PREFIX + BeanNaming.getPackageName(getHomeClass().getName());
742             wrpHomeName = new String JavaDoc("JOnAS" + ejbIdentifier + "Home");
743             fullWrpHomeName = BeanNaming.getClassName(packageName, wrpHomeName);
744         }
745
746         if (getLocalHomeClass() != null) {
747             packageName = GENERATED_PREFIX + BeanNaming.getPackageName(getLocalHomeClass().getName());
748             wrpLocalHomeName = new String JavaDoc("JOnAS" + ejbIdentifier + "LocalHome");
749             fullWrpLocalHomeName = BeanNaming.getClassName(packageName, wrpLocalHomeName);
750         }
751
752         fullDerivedBeanName = getEjbClass().getName();
753         derivedBeanName = BeanNaming.getBaseName(getEjbClass().getName());
754
755         IorSecurityConfigMapping iorSecurityConfigMapping = jonasEjb.getIorSecurityConfig();
756         if (iorSecurityConfigMapping != null) {
757             processIorSecurityConfig(iorSecurityConfigMapping);
758         }
759
760     }
761
762     /**
763      * Permit classes loading from subtypes. (needed for Stateless Session Beans
764      * with service-endpoints). Needs to be overridden in subtypes.
765      *
766      * @param ce XML Element representing EJB Descriptor
767      * @param loader ClassLoader used to load classes
768      *
769      * @throws DeploymentDescException when a class cannot be loaded
770      */

771     protected void loadExtraClasses(CommonEjb ce, ClassLoader JavaDoc loader) throws DeploymentDescException {
772         // do nothing by default
773
}
774
775     /**
776      * Permit Methods addition from subtypes Protected method that need to be
777      * overridden in subclasses
778      *
779      * @param len method array length
780      * @return new len value
781      *
782      * @throws DeploymentDescException when java reflection cannot be used on
783      * classes
784      */

785     protected int addEJBMethodDesc(int len) throws DeploymentDescException {
786         return len;
787     }
788
789     /**
790      * Returns the parent Class for a method given an interface type.
791      *
792      * @param intfType type of the interface (Home/Remote/LocalHome/Local or
793      * ServiceEndpoint)
794      *
795      * @return the parent class for a method given an interface type
796      *
797      * @throws DeploymentDescException when intfType is unknown
798      */

799     protected Class JavaDoc getParentClass(String JavaDoc intfType) throws DeploymentDescException {
800         Class JavaDoc pClass = null;
801         if (intfType.equals("Home")) {
802             pClass = javax.ejb.EJBHome JavaDoc.class;
803         } else if (intfType.equals("Remote")) {
804             pClass = javax.ejb.EJBObject JavaDoc.class;
805         } else if (intfType.equals("LocalHome")) {
806             pClass = javax.ejb.EJBLocalHome JavaDoc.class;
807         } else if (intfType.equals("Local")) {
808             pClass = javax.ejb.EJBLocalObject JavaDoc.class;
809         } else {
810             throw new DeploymentDescException(intfType + " is invalid value for method-intf on bean " + ejbName);
811         }
812         return pClass;
813     }
814
815     /**
816      * Gets an hashcode for this bean
817      * Return hashcode for jndiname + jndi localname
818      * @return a string for hashcode for jndiname + jndi localname
819      */

820     protected String JavaDoc getHashCodeForIdentifier() {
821         String JavaDoc hash = "";
822         if (getJndiName() != null) {
823             hash += getJndiName();
824         }
825         if (getJndiLocalName() != null) {
826             hash += getJndiLocalName();
827         }
828         return Integer.toString(hash.hashCode());
829     }
830
831     /**
832      * Build a valid java identifier for the bean.
833      * @return Returns a valid java identifier from the bean.
834      */

835     public String JavaDoc getIdentifier() {
836         
837         if (beanIdentification == null) {
838             String JavaDoc identifier = getEjbName();
839             identifier += getHashCodeForIdentifier();
840             
841             char[] tabChar = new char[identifier.length()];
842             for (int i = 0; i < identifier.length(); i++) {
843                 if (!Character.isJavaIdentifierPart(identifier.charAt(i))) {
844                     tabChar[i] = '_';
845                 } else {
846                     tabChar[i] = identifier.charAt(i);
847                 }
848             }
849             beanIdentification = new String JavaDoc(tabChar);
850         }
851         return beanIdentification;
852     }
853
854     /**
855      * Check if method throws RemoteException (or not).
856      *
857      * @param m the method to examine
858      * @param shouldThrow boolean value indicating if the method should or
859      * shouldn't throw RemoteException
860      *
861      * @throws DeploymentDescException thrown for non-valid method
862      */

863     public void checkRemoteException(java.lang.reflect.Method JavaDoc m, boolean shouldThrow) throws DeploymentDescException {
864         Class JavaDoc[] excepts = m.getExceptionTypes();
865         for (int j = 0; j < excepts.length; j++) {
866             if (RemoteException JavaDoc.class.isAssignableFrom(excepts[j])) {
867                 if (shouldThrow) {
868                     return;
869                 } else {
870                     throw new DeploymentDescException("Method " + m.getName() + " of " + m.getDeclaringClass()
871                             + " should NOT throw RemoteException");
872                 }
873             }
874         }
875         if (shouldThrow) {
876             throw new DeploymentDescException("Method " + m.getName() + " of " + m.getDeclaringClass()
877                     + " must throw RemoteException");
878         } else {
879             return;
880         }
881
882     }
883
884     /**
885      * Check if argument and return types are valid types for RMI-IIOP.
886      * (Primitive types, remote objects, or non-remote objects that implement
887      * the java.io.Serializable interface) Only a warning is logging if it's not
888      * the case.
889      *
890      * @param m the methode to examine
891      */

892     public void checkValidTypesForRmi(java.lang.reflect.Method JavaDoc m) {
893         boolean isValid = true;
894         Class JavaDoc[] paramTypes = m.getParameterTypes();
895         for (int i = 0; i < paramTypes.length; i++) {
896             if (!JavaType.isValidForRmi(paramTypes[i])) {
897                 isValid = false;
898             }
899         }
900         if (!JavaType.isValidForRmi(m.getReturnType()) && !JavaType.isVoid(m.getReturnType())
901                 && !JavaType.isCollecOrEnum(m.getReturnType())) {
902             // Allow Collection or Enumeration type (finder methods)
903
isValid = false;
904         }
905         if (!isValid) {
906             // TODO the trace of this warning uses a static variable into
907
// TraceEjb class
908
// because this.logger is not yet initialized
909
TraceEjb.dd.log(BasicLevel.WARN, "Method " + m.getName() + " of " + m.getDeclaringClass()
910                     + " may be have an invalid argument or return type for RMI");
911         }
912     }
913
914     /**
915      * Check that the bean descriptor is valid
916      *
917      * @throws DeploymentDescException thrown for non-valid bean
918      */

919     public void check() throws DeploymentDescException {
920         // check business methods transaction attribute
921
for (int i = 0; i < methodDesc.size(); i++) {
922             checkTxAttribute(((MethodDesc) methodDesc.get(i)));
923         }
924         checkRunAsMapping();
925     }
926
927     /**
928      * Check that the runAs role mapping is correct
929      * @throws DeploymentDescException if role mapping is incorrect
930      */

931     public void checkRunAsMapping() throws DeploymentDescException {
932         if (runAsPrincipalName != null) {
933             // verify roles of run-as principal name
934
String JavaDoc[] runAsPrincipalRoles = deploymentDesc.getRolesForRunAsPrincipal(runAsPrincipalName);
935             // Check that the run-as role is included in principal roles
936
if (runAsPrincipalRoles != null) {
937                 boolean isIncluded = false;
938                 for (int r = 0; r < runAsPrincipalRoles.length; r++) {
939                     if (runAsPrincipalRoles[r].equals(runAsRole)) {
940                         isIncluded = true;
941                     }
942                 }
943                 if (!isIncluded) {
944                     throw new DeploymentDescException("The run-as roles defined for the runas principal name '"
945                             + runAsPrincipalName + "' does not contains the run-as role '"
946                             + runAsRole + "' in bean '" + getEjbName() + ".");
947                 }
948             }
949         }
950     }
951
952     /**
953      * Check that trans-attribute is valid for a bean's method.
954      *
955      * @param md MethodDesc to check
956      *
957      * @throws DeploymentDescException When MethodDesc is not valid
958      */

959     protected abstract void checkTxAttribute(MethodDesc md) throws DeploymentDescException;
960
961     /**
962      * Check that there are always corresponding role-name element in
963      * security-role and method-permission elements.
964      *
965      * @param asd the AssemblyDescriptor used to check bean's role names
966      *
967      * @throws DeploymentDescException When verification fails
968      */

969     protected void verifyRoleName(AssemblyDescriptor asd) throws DeploymentDescException {
970         boolean verify;
971         List JavaDoc methodPermission = asd.getMethodPermissionList();
972         if (methodPermission != null) {
973             for (Iterator JavaDoc i = methodPermission.iterator(); i.hasNext();) {
974                 MethodPermission mPermission = (MethodPermission) i.next();
975                 for (Iterator JavaDoc j = mPermission.getRoleNameList().iterator(); j.hasNext();) {
976                     verify = false;
977                     String JavaDoc mpRoleName = (String JavaDoc) j.next();
978                     for (Iterator JavaDoc k = asd.getSecurityRoleList().iterator(); k.hasNext();) {
979                         String JavaDoc srRoleName = ((SecurityRole) k.next()).getRoleName();
980                         if (mpRoleName.equals(srRoleName)) {
981                             verify = true;
982                         }
983                     }
984                     if (!verify) {
985                         throw new DeploymentDescException(
986                                 "a method-permission element defined a role-name element \""
987                                         + mpRoleName
988                                         + "\" which doesn't correspond to any security-role element of the Deployment Descriptor");
989                     }
990                 }
991             }
992         }
993     }
994
995     /**
996      * Get the enterprise bean's name.
997      *
998      * @return Name of the bean
999      */

1000    public String JavaDoc getEjbName() {
1001        return ejbName;
1002    }
1003
1004    /**
1005     * Get the name to associate with the enterprise Bean in the JNDI name
1006     * space. Invoking this method is disallowed for message driven bean. (This
1007     * information is JOnAS specific). Used by Server
1008     *
1009     * @return Jndi name of the bean
1010     */

1011    public String JavaDoc getJndiName() {
1012        return jndiName;
1013    }
1014
1015    /**
1016     * Get the name to associate with the enterprise Bean in the JNDI name space
1017     * for local access (inside the same JOnAS Server)
1018     *
1019     * @return Jndi local name of the bean
1020     */

1021    public String JavaDoc getJndiLocalName() {
1022        return jndiLocalName;
1023    }
1024
1025    /**
1026     * Get bean's home interface. Invoking this method is disallowed for message
1027     * driven bean. Used by GenIC and Server
1028     *
1029     * @return Class for the home interface or null
1030     */

1031    public Class JavaDoc getHomeClass() {
1032        return home;
1033    }
1034
1035    /**
1036     * Get bean's remote interface. Invoking this method is disallowed for
1037     * message driven bean. Used by GenIC and Server
1038     *
1039     * @return Class for the remote interface or null
1040     */

1041    public Class JavaDoc getRemoteClass() {
1042        return remote;
1043    }
1044
1045    /**
1046     * Get bean's local home interface. Invoking this method is disallowed for
1047     * message driven bean. Used by GenIC and Server
1048     *
1049     * @return Class for the home interface or null
1050     */

1051    public Class JavaDoc getLocalHomeClass() {
1052        return localhome;
1053    }
1054
1055    /**
1056     * Get bean's local interface. Invoking this method is disallowed for
1057     * message driven bean. Used by GenIC and Server
1058     *
1059     * @return Class for the Local interface or null
1060     */

1061    public Class JavaDoc getLocalClass() {
1062        return local;
1063    }
1064
1065    /**
1066     * Get bean's class. Used by GenIC and Server
1067     *
1068     * @return Class for the bean
1069     */

1070    public Class JavaDoc getEjbClass() {
1071        return ejbClass;
1072    }
1073
1074    /**
1075     * Get bean's EJB 1.0 environment properties.
1076     *
1077     * @return Returns the bean's EJB 1.0 environment properties
1078     */

1079    public Properties JavaDoc getEjb10Environment() {
1080        Properties JavaDoc ret = new Properties JavaDoc(ejb10EnvProps);
1081        return ret;
1082    }
1083
1084    /**
1085     * Get descriptor attached to a given method. Used by GenIC and JMdbEndpointFactory
1086     *
1087     * @param method Method from the Home/Remote/MessageListener interface
1088     * @return The method descriptor (never returns null)
1089     */

1090    public MethodDesc getMethodDesc(java.lang.reflect.Method JavaDoc method) {
1091
1092        if (!methodDescMap.containsKey(method)) {
1093            throw new Error JavaDoc(method.getName() + " is not a method of home/remote interfaces for bean " + getEjbName());
1094        }
1095        return (MethodDesc) methodDescMap.get(method);
1096    }
1097
1098    /**
1099     * get an iterator for all MethodDesc of the bean.
1100     *
1101     * @return Returns an iterator for all MethodDesc of the bean
1102     */

1103    public Iterator JavaDoc getMethodDescIterator() {
1104        return methodDesc.iterator();
1105    }
1106
1107    /**
1108     * get a MethodDesc from its index.
1109     *
1110     * @param index MethodDesc index
1111     *
1112     * @return Returns a MethodDesc from its index
1113     */

1114    public MethodDesc getMethodDesc(int index) {
1115        return (MethodDesc) methodDesc.get(index);
1116    }
1117
1118    /**
1119     * Gets the security-role-ref of the beans can access to the
1120     * EJBRoleRefPermission and role-link.
1121     *
1122     * @return the security-role-ref of the beans
1123     */

1124    public List JavaDoc getSecurityRoleRefDescList() {
1125        return securityRoleRefDescList;
1126    }
1127
1128    /**
1129     * @return min size of the pool
1130     */

1131    public int getPoolMin() {
1132        return poolMin;
1133    }
1134
1135    /**
1136     * @return max size of the cache
1137     */

1138    public int getCacheMax() {
1139        return cacheMax;
1140    }
1141
1142    /**
1143     * @return the run-as role name
1144     */

1145    public String JavaDoc getRunAsRole() {
1146        return runAsRole;
1147    }
1148
1149    /**
1150     * @return the transaction attribute for the ejbTimeout method
1151     */

1152    public int getTimerTxAttribute() {
1153        return timerTxAttribute;
1154    }
1155
1156    /**
1157     * @return the security signature for the ejbTimeout method
1158     */

1159    public String JavaDoc getEjbTimeoutSignature() {
1160        return ejbTimeoutSignature;
1161    }
1162
1163    /**
1164     * @return the BeanFactory, if the bean has been loaded.
1165     */

1166    public BeanFactory getBeanFactory() {
1167        return bf;
1168    }
1169
1170    /**
1171     * Set the BeanFactory, when the bean is loaded in container.
1172     * @param factory The bean factory
1173     */

1174    public void setBeanFactory(BeanFactory factory) {
1175        bf = factory;
1176    }
1177
1178    /**
1179     * String representation of the object for test purpose
1180     *
1181     * @return String representation of this object
1182     */

1183    public String JavaDoc toString() {
1184        StringBuffer JavaDoc ret = new StringBuffer JavaDoc();
1185        ret.append("\ngetDisplayName()=" + getDisplayName());
1186        ret.append("\ngetEjbName()=" + getEjbName());
1187        if (jndiName != null) {
1188            ret.append("\ngetJndiName()=" + getJndiName());
1189        }
1190        if (home != null) {
1191            ret.append("\ngetHomeClass()=" + getHomeClass().toString());
1192        }
1193        if (remote != null) {
1194            ret.append("\ngetRemoteClass()=" + getRemoteClass().toString());
1195        }
1196        if (localhome != null) {
1197            ret.append("\ngetLocalHomeClass()=" + getLocalHomeClass().toString());
1198        }
1199        if (local != null) {
1200            ret.append("\ngetLocalClass()=" + getLocalClass().toString());
1201        }
1202        ret.append("\ngetEjbClass()=" + getEjbClass().toString());
1203        EnvEntryDesc[] envE = getEnvEntryDesc();
1204        for (int i = 0; i < envE.length; i++) {
1205            ret.append("\ngetEnvEntryDesc(" + i + ")=" + envE[i].toString());
1206        }
1207        ServiceRefDesc[] sr = getServiceRefDesc();
1208        for (int i = 0; i < sr.length; i++) {
1209            ret.append("\ngetServiceRefDesc(" + i + ")=" + sr[i].toString());
1210        }
1211        ResourceEnvRefDesc[] resEnvR = getResourceEnvRefDesc();
1212        for (int i = 0; i < resEnvR.length; i++) {
1213            ret.append("\ngetResourceEnvRefDesc(" + i + ")=" + resEnvR[i].toString());
1214        }
1215        ResourceRefDesc[] resR = getResourceRefDesc();
1216        for (int i = 0; i < resR.length; i++) {
1217            ret.append("\ngetResourceRefDesc(" + i + ")=" + resR[i].toString());
1218        }
1219        EjbRefDesc[] ejbR = getEjbRefDesc();
1220        for (int i = 0; i < ejbR.length; i++) {
1221            ret.append("\ngetEjbRefDesc(" + i + ")=" + ejbR[i].toString());
1222        }
1223        EjbLocalRefDesc[] ejbLR = getEjbLocalRefDesc();
1224        for (int i = 0; i < ejbLR.length; i++) {
1225            ret.append("\ngetEjbLocalRefDesc(" + i + ")=" + ejbLR[i].toString());
1226        }
1227        MessageDestinationRefDesc[] mdR = getMessageDestinationRefDesc();
1228        for (int i = 0; i < mdR.length; i++) {
1229            ret.append("\ngetMessageDestinationRefDesc(" + i + ")=" + mdR[i].toString());
1230        }
1231        for (int i = 0; i < methodDesc.size(); i++) {
1232            MethodDesc md = (MethodDesc) methodDesc.get(i);
1233            ret.append("\ngetMethodDesc(" + i + ")=" + md.getClass().getName());
1234            ret.append(md.toString());
1235        }
1236
1237        if (securityRoleRefDescList != null) {
1238            for (Iterator JavaDoc i = securityRoleRefDescList.iterator(); i.hasNext();) {
1239                SecurityRoleRefDesc sRoleRefDesc = (SecurityRoleRefDesc) i.next();
1240                ret.append("\nsecurity-role-ref, role-name = '" + sRoleRefDesc.getRoleName() + "', role-link = '"
1241                        + sRoleRefDesc.getRoleLink() + "'");
1242            }
1243        }
1244        ret.append("\ngetFullWrpRemoteName() = " + getFullWrpRemoteName());
1245        ret.append("\ngetFullWrpHomeName() = " + getFullWrpHomeName());
1246        ret.append("\ngetFullWrpLocalName() = " + getFullWrpLocalName());
1247        ret.append("\ngetFullWrpLocalHomeName() = " + getFullWrpLocalHomeName());
1248        ret.append("\ngetFullWrpHandleName() = " + getFullWrpHandleName());
1249        ret.append("\ngetFullDerivedBeanName() = " + getFullDerivedBeanName());
1250        ret.append("\ngetRunAsRole() = " + getRunAsRole());
1251        return ret.toString();
1252    }
1253
1254    /**
1255     * MethodDesc constructor factory method to ovewrite
1256     *
1257     * @param meth the method to be wrapped into a MethodDesc instance
1258     * @param index index of the method inside the MethodDesc List
1259     *
1260     * @return Returns a new MethodDesc (or subclass)
1261     */

1262    protected MethodDesc newMethodDescInstance(java.lang.reflect.Method JavaDoc meth, Class JavaDoc classDef, int index) {
1263        return new MethodDesc(this, meth, classDef, index);
1264    }
1265
1266    /**
1267     * Add a new method descriptor to the bean
1268     *
1269     * @param meth method to add inside MethodDescs list
1270     *
1271     * @return the constructed MethodDesc
1272     */

1273    protected MethodDesc addMethodDesc(java.lang.reflect.Method JavaDoc meth, Class JavaDoc classDef) {
1274        MethodDesc md = newMethodDescInstance(meth, classDef, methodDesc.size());
1275        methodDesc.add(md);
1276        methodDescMap.put(meth, md);
1277        return md;
1278    }
1279
1280    /**
1281     * @return Returns the full name of the wrapper class for the bean
1282     */

1283    public String JavaDoc getFullWrpRemoteName() {
1284        return fullWrpRemoteName;
1285    }
1286
1287    /**
1288     * @return Returns the full name of the wrapper class for the bean
1289     */

1290    public String JavaDoc getFullWrpLocalName() {
1291        return fullWrpLocalName;
1292    }
1293
1294    /**
1295     * @return Returns the name of the wrapper class for the bean
1296     */

1297    public String JavaDoc getWrpRemoteName() {
1298        return wrpRemoteName;
1299    }
1300
1301    /**
1302     * @return Returns the name of the wrapper class for the bean
1303     */

1304    public String JavaDoc getWrpLocalName() {
1305        return wrpLocalName;
1306    }
1307
1308    /**
1309     * @return Returns the full name of the Handle class for the bean
1310     */

1311    public String JavaDoc getFullWrpHandleName() {
1312        return fullWrpHandleName;
1313    }
1314
1315    /**
1316     * @return Returns the name of the Handle class for the bean
1317     */

1318    public String JavaDoc getWrpHandleName() {
1319        return wrpHandleName;
1320    }
1321
1322    /**
1323     * @return Returns the full name of the wrapper home class for the bean
1324     */

1325    public String JavaDoc getFullWrpHomeName() {
1326        return fullWrpHomeName;
1327    }
1328
1329    /**
1330     * @return Returns the full name of the wrapper local home class for the bean
1331     */

1332    public String JavaDoc getFullWrpLocalHomeName() {
1333        return fullWrpLocalHomeName;
1334    }
1335
1336    /**
1337     * @return Returns the name of the wrapper home class for the bean
1338     */

1339    public String JavaDoc getWrpHomeName() {
1340        return wrpHomeName;
1341    }
1342
1343    /**
1344     * @return Returns the name of the wrapper local home class for the bean
1345     */

1346    public String JavaDoc getWrpLocalHomeName() {
1347        return wrpLocalHomeName;
1348    }
1349
1350    /**
1351     * @return Returns the full name of the derived class of the bean
1352     */

1353    public String JavaDoc getFullDerivedBeanName() {
1354        return fullDerivedBeanName;
1355    }
1356
1357    /**
1358     * @return Returns the name of the derived class of the bean
1359     */

1360    public String JavaDoc getDerivedBeanName() {
1361        return derivedBeanName;
1362    }
1363
1364    /**
1365     * @return Returns the parent deployment descriptor
1366     */

1367    public DeploymentDesc getDeploymentDesc() {
1368        return deploymentDesc;
1369    }
1370
1371    /**
1372     * Set the parent deployment descriptor
1373     *
1374     * @param deploymentDesc parent DeploymentDesc
1375     */

1376    public void setDeploymentDesc(DeploymentDesc deploymentDesc) {
1377        this.deploymentDesc = deploymentDesc;
1378        logger = deploymentDesc.getLogger();
1379    }
1380
1381    /**
1382     * Sort the MethodDesc list.
1383     *
1384     * @param al ArrayList to be sorted
1385     * @param begin begin index
1386     * @param length size of the list
1387     */

1388    private void orderMethodDesc(ArrayList JavaDoc al, int begin, int length) {
1389        MethodDesc[] mds = new MethodDesc[length];
1390        for (int i = 0; i < length; i++) {
1391            mds[i] = (MethodDesc) al.get(begin + i);
1392        }
1393        Arrays.sort(mds, 0, length, new MethodDescComparator());
1394        for (int i = 0; i < length; i++) {
1395            al.set(begin + i, mds[i]);
1396            mds[i].setIndex(begin + i);
1397        }
1398    }
1399
1400    /**
1401     * Compare 2 MethodDesc.
1402     */

1403    private class MethodDescComparator implements Comparator JavaDoc {
1404
1405        /**
1406         * Compare 2 Object.
1407         *
1408         * @param o1 instance 1
1409         * @param o2 instance 2 to be compared to instance 1
1410         *
1411         * @return integer difference between the 2 instance
1412         */

1413        public int compare(Object JavaDoc o1, Object JavaDoc o2) {
1414            MethodDesc md1 = (MethodDesc) o1;
1415            MethodDesc md2 = (MethodDesc) o2;
1416            int res = md1.getMethod().getDeclaringClass().getName().compareTo(
1417                    md2.getMethod().getDeclaringClass().getName());
1418            if (res == 0) {
1419                res = md1.getMethod().getName().compareTo(md2.getMethod().getName());
1420                if (res == 0) {
1421                    // Same method name => compare the parameter types
1422
Class JavaDoc[] p1 = md1.getMethod().getParameterTypes();
1423                    Class JavaDoc[] p2 = md2.getMethod().getParameterTypes();
1424                    res = p1.length - p2.length;
1425                    if (res == 0) {
1426                        //Same parameter size
1427
for (int i = 0; i < p1.length && (res = p1[i].getName().compareTo(p2[i].getName())) == 0; i++) {
1428                            // compare each method
1429
}
1430                    }
1431                }
1432            }
1433            return res;
1434        }
1435    }
1436
1437    /**
1438     * @return the runAs principal name.
1439     */

1440    public String JavaDoc getRunAsPrincipalName() {
1441        return runAsPrincipalName;
1442    }
1443
1444    /**
1445     * @return true if local interface has been defined in the DD
1446     */

1447    public boolean hasDefinedLocalInterface() {
1448        if (localhome == null) {
1449            return false;
1450        } else {
1451            return (!"javax.ejb.EJBLocalHome".equals(localhome.getName()));
1452        }
1453    }
1454
1455    /**
1456     * Build sas component used for CSIv2 interop
1457     * @param iorSecurityConfigMapping CsiV2 ior configuration
1458     */

1459    private void processIorSecurityConfig(IorSecurityConfigMapping iorSecurityConfigMapping) {
1460
1461        // Transport
1462
TransportStruct transportStruct = new TransportStruct();
1463        // As
1464
AsStruct asStruct = new AsStruct();
1465        // Sas
1466
SasStruct sasStruct = new SasStruct();
1467
1468        // Now fill SasComponent with given ior values
1469
TransportConfigMapping transportConfigMapping = iorSecurityConfigMapping.getTransportConfig();
1470        AsContextMapping asContextMapping = iorSecurityConfigMapping.getAsContext();
1471        SasContextMapping sasContextMapping = iorSecurityConfigMapping.getSasContext();
1472
1473        // target requires (if required)
1474
int targetRequires = 0;
1475        if (transportConfigMapping.getIntegrity().equals("required")) {
1476            targetRequires |= Integrity.value;
1477        }
1478        if (transportConfigMapping.getConfidentiality().equals("required")) {
1479            targetRequires |= Confidentiality.value;
1480        }
1481        if (transportConfigMapping.getEstablishTrustInClient().equals("required")) {
1482            targetRequires |= EstablishTrustInClient.value;
1483        }
1484        if (transportConfigMapping.getEstablishTrustInTarget().equals("required")) {
1485            targetRequires |= EstablishTrustInTarget.value;
1486        }
1487        transportStruct.setTargetRequires(targetRequires);
1488
1489
1490        // target supports (supported or required)
1491
int targetSupports = 0;
1492        if (transportConfigMapping.getIntegrity().equals("supported") || transportConfigMapping.getIntegrity().equals("required")) {
1493            targetSupports |= Integrity.value;
1494        }
1495        if (transportConfigMapping.getConfidentiality().equals("supported") || transportConfigMapping.getConfidentiality().equals("required")) {
1496            targetSupports |= Confidentiality.value;
1497        }
1498        if (transportConfigMapping.getEstablishTrustInClient().equals("supported") || transportConfigMapping.getEstablishTrustInClient().equals("required")) {
1499            targetSupports |= EstablishTrustInClient.value;
1500        }
1501        if (transportConfigMapping.getEstablishTrustInTarget().equals("supported") || transportConfigMapping.getEstablishTrustInTarget().equals("required")) {
1502            targetSupports |= EstablishTrustInTarget.value;
1503        }
1504        transportStruct.setTargetSupports(targetSupports);
1505
1506
1507        // As struct (if it is needed)
1508
if (!asContextMapping.getAuthMethod().equals("none")) {
1509            asStruct.setTargetName(asContextMapping.getRealm());
1510            asStruct.setTargetSupports(EstablishTrustInClient.value);
1511            if (asContextMapping.getRequired().equals("true")) {
1512                asStruct.setTargetRequires(EstablishTrustInClient.value);
1513
1514            }
1515        }
1516
1517        // Sas struct (if supported)
1518
if (sasContextMapping.getCallerPropagation().equals("supported")) {
1519            sasStruct.enableGSSUPSupportedNamingMechanisms();
1520            sasStruct.setSupportedIdentityTypes(ITTAbsent.value | ITTAnonymous.value | ITTPrincipalName.value | ITTX509CertChain.value | ITTDistinguishedName.value);
1521            sasStruct.setTargetSupports(IdentityAssertion.value);
1522        }
1523
1524        // and then, set our SAS component
1525
sasComponent = new SasComponent(transportStruct, asStruct, sasStruct);
1526
1527
1528    }
1529
1530    /**
1531     * @return the sasComponent.
1532     */

1533    public SasComponent getSasComponent() {
1534        return sasComponent;
1535    }
1536    /**
1537     * @param sasComponent The sasComponent to set.
1538     */

1539    public void setSasComponent(SasComponent sasComponent) {
1540        this.sasComponent = sasComponent;
1541    }
1542}
1543
1544
Popular Tags