KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_ejb > genic > VcMethod


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: VcMethod.java,v 1.31 2005/03/11 13:25:18 joaninh Exp $
23  * --------------------------------------------------------------------------
24  */

25
26
27 package org.objectweb.jonas_ejb.genic;
28
29
30 import java.lang.reflect.Method JavaDoc;
31 import java.util.ArrayList JavaDoc;
32 import java.util.Iterator JavaDoc;
33 import java.util.List JavaDoc;
34 import java.util.StringTokenizer JavaDoc;
35 import java.util.Vector JavaDoc;
36
37 import org.objectweb.jonas_ejb.deployment.api.BeanDesc;
38 import org.objectweb.jonas_ejb.deployment.api.EntityJdbcCmp1Desc;
39 import org.objectweb.jonas_ejb.deployment.api.EntityJdbcCmp2Desc;
40 import org.objectweb.jonas_ejb.deployment.api.FieldJdbcDesc;
41 import org.objectweb.jonas_ejb.deployment.api.MethodCmp2Desc;
42 import org.objectweb.jonas_ejb.deployment.api.MethodDesc;
43 import org.objectweb.jonas_ejb.deployment.api.MethodJdbcCmp1Desc;
44 import org.objectweb.jonas_ejb.lib.BeanNaming;
45 import org.objectweb.jonas_ejb.lib.JavaType;
46 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException;
47 import org.objectweb.jorm.type.api.PType;
48
49
50 /**
51  * This class is the "Velocity context" for a interface method or a bean method used in the Velocity Templates.
52  * @author Helene Joanin (Bull) : Initial developer
53  * @author Santiago Gala (sgala@hisitech.com) - 00/09/14 - Parameters can be followed by a number in the WHERE clause
54  * @author Joe Gittings has proposed to code method signature for security
55  * in order to avoid same signature for inherited methods.
56  */

57
58 public class VcMethod {
59
60     /**
61      * home.create method
62      */

63     static final byte METHOD_CREATE = 0;
64     /**
65      * bean.ebjCreate method
66      */

67     static final byte METHOD_EJB_CREATE = 1;
68     /**
69      * bean.ejbPostCreate method
70      */

71     static final byte METHOD_EJB_POST_CREATE = 2;
72     /**
73      * EJBObject.remove() method
74      */

75     static final byte METHOD_REMOVE_THIS = 10;
76     /**
77      * home.remove(primarykey) method
78      */

79     static final byte METHOD_REMOVE_PK = 11;
80     /**
81      * home.remove(handle) method
82      */

83     static final byte METHOD_REMOVE_HANDLE = 12;
84     /**
85      * bean.ejbRemove() method
86      */

87     static final byte METHOD_EJB_REMOVE = 13;
88     /**
89      * home.findByPrimaryKey(pk) method
90      */

91     static final byte METHOD_FINDER_BY_PK = 20;
92     /**
93      * home.findXxx() method
94      */

95     static final byte METHOD_FINDER_ALL = 21;
96     /**
97      * home.findXxx() method that returns a simple object
98      */

99     static final byte METHOD_FINDER_SIMPLE = 22;
100     /**
101      * home.findXxx() method that returns an Enumeration
102      */

103     static final byte METHOD_FINDER_ENUM = 23;
104     /**
105      * home.findXxx() method that returns a Collection
106      */

107     static final byte METHOD_FINDER_COL = 24;
108     /**
109      * bean.ejbSelectXxx() method that returns a simple object
110      */

111     static final byte METHOD_EJB_SELECT_SIMPLE = 30;
112     /**
113      * bean.ejbSelectXxx() method that returns a Collection
114      */

115     static final byte METHOD_EJB_SELECT_COL = 31;
116     /**
117      * bean.ejbSelectXxx() method that returns a Set
118      */

119     static final byte METHOD_EJB_SELECT_SET = 32;
120     /**
121      * bean.ejbLoad() method
122      */

123     static final byte METHOD_EJB_LOAD = 40;
124     /**
125      * bean.ejbStore() method
126      */

127     static final byte METHOD_EJB_STORE = 41;
128     /**
129      * bean.setEntityContext() method
130      */

131     static final byte METHOD_EJB_SET_ENTITY_CONTEXT = 42;
132     /**
133      * bean.ejbActivate() method
134      */

135     static final byte METHOD_EJB_ACTIVATE = 43;
136
137     /**
138      * kind of the method ie home.create() or bean.ejbCreate, or ...
139      */

140     private byte mKind = -1;
141
142     /**
143      * name of the method
144      */

145     private String JavaDoc mName = null;
146
147     /**
148      * name of the method with the firt letter capitalized
149      */

150     private String JavaDoc mCapName = null;
151
152     /**
153      * string representation of the formal parameters of the method (for ex: "int p1, String p2");
154      */

155     private StringBuffer JavaDoc mFormalParameters = null;
156
157     /**
158      * string representation of the actual parameters of the method (for ex: "p1, p2")
159      */

160     private StringBuffer JavaDoc mActualParameters = null;
161
162     /**
163      * Array of objects of the parameters
164      */

165     private StringBuffer JavaDoc mArrayObjectParameters = null;
166
167     /**
168      * string representation of the exception list
169      */

170     private StringBuffer JavaDoc mExceptionList = null;
171
172     /**
173      * string representation of the security signature method
174      */

175     private String JavaDoc mSecuritySignature;
176
177     /**
178      * transactional attribute of the method
179      */

180     private int mTxAttribute = MethodDesc.TX_NULL;
181
182     /**
183      * name of the return type of the method
184      */

185     private String JavaDoc mReturnType;
186
187     /**
188      * java.lang.reflect.Method, just for explicit error message
189      */

190     private Method JavaDoc mMethod = null;
191
192     /**
193      * index of the method. Each method is identify with an unuique index.
194      */

195     private int methodIndex = -1;
196
197     /**
198      * BeanDesc of the associated bean to the method
199      */

200     private BeanDesc beanDesc = null;
201
202     /*
203     * For CMP1 only
204     */

205
206     /**
207      * string representation of the SQL statement associated to the method
208      */

209     private String JavaDoc mSqlStmt = null;
210
211     /**
212      * VcParamWhere list of the finder method
213      */

214     private ArrayList JavaDoc mParamWhereList = null;
215
216     /*
217      * For CMP2 only
218      */

219
220     /**
221      * true is this is a finder/ejbSelect method that return a remote bean
222      * (Only used in CMP2 for finder and ejbSelect methods)
223      */

224
225     private boolean isEjbqlReturnRemoteBean = false;
226     /**
227      * true is this is a finder/ejbSelect method that return a local bean
228      * (Only used in CMP2 for finder and ejbSelect methods)
229      */

230
231     private boolean isEjbqlReturnLocalBean = false;
232     /**
233      * Medor Field representation of the result of the finder/ejbSelect method
234      * (Only used in CMP2 for finder and ejbSelect methods)
235      */

236
237     private org.objectweb.medor.api.Field resFieldOfEjbql = null;
238     /**
239      * VcParam list of the finder/ejbSelect method
240      * (Only used in CMP2 for finder and ejbSelect methods)
241      */

242     private ArrayList JavaDoc mParamList = null;
243
244     /**
245      * Class list of the parameters of the method
246      */

247     private Class JavaDoc[] parameterTypes = null;
248     /**
249      * true if the method throws javax.ejb.CreateException
250      */

251     private boolean canThrowCreate = false;
252
253     /**
254      * VcMethod constructor
255      * @param method java.lang.reflect.Method method description
256      * @param methodDesc method description
257      * @param dd bean description of the associated bean
258      */

259     VcMethod(Method JavaDoc method, MethodDesc methodDesc, BeanDesc dd) {
260
261         if (methodDesc != null) {
262             methodIndex = methodDesc.getIndex();
263         }
264         beanDesc = dd;
265         /*
266          * The 'method' may be
267          * - a home interface's method
268          * - a local home interface's method
269          * - a remote interface's method
270          * - a local interface's method
271          * - a bean's method as
272          * - a beans's ejbSelect() method,
273          * setEntityContext(), ejbActivate(), ejbCreate(), ejbLoad(), ejbStore(), ejbRemove().
274          * - a beans's ejbSelect() method,
275          * In the last case, the 'methodDesc' is null in case of
276          * setEntityContext(), ejbActivate(), ejbLoad() and ejbStore().
277          */

278
279         Class JavaDoc declClass = method.getDeclaringClass();
280         Class JavaDoc [] params = method.getParameterTypes();
281         parameterTypes = params;
282         Class JavaDoc [] exceptions = method.getExceptionTypes();
283         mMethod = method;
284
285         // Name and CapName
286
mName = method.getName();
287         mCapName = BeanNaming.firstToUpperCase(mName);
288
289         // FormalParameters and ActualParameters
290
mFormalParameters = new StringBuffer JavaDoc();
291         mActualParameters = new StringBuffer JavaDoc();
292         mArrayObjectParameters = new StringBuffer JavaDoc();
293         String JavaDoc var = null;
294         for (int p = 1; p <= params.length; p++) {
295             var = "p" + p;
296             mFormalParameters.append(JavaType.getName(params[p - 1]) + " " + var);
297             mActualParameters.append(var);
298             mArrayObjectParameters.append(JavaType.toStringObject(var, params[p - 1]));
299             if (p < params.length) {
300                 mFormalParameters.append(", ");
301                 mActualParameters.append(", ");
302                 mArrayObjectParameters.append(", ");
303             }
304         }
305
306         // ExceptionList
307
mExceptionList = new StringBuffer JavaDoc();
308         for (int e = 0; e < exceptions.length; e++) {
309             Class JavaDoc ecl = exceptions[e];
310             if (javax.ejb.CreateException JavaDoc.class.isAssignableFrom(ecl)) {
311                 canThrowCreate = true;
312             }
313             mExceptionList.append(JavaType.getName(ecl));
314             if (e < exceptions.length - 1) {
315                 mExceptionList.append(", ");
316             }
317         }
318
319         // SecuritySignature
320
// No methodDesc for bean's methods as ejbLoad(), ejbStore(), ...
321
if (methodDesc != null) {
322             mSecuritySignature = "";
323             if (methodDesc.getRoleName().length > 0 || methodDesc.isExcluded()) {
324                 mSecuritySignature = BeanNaming.getSignature(dd.getEjbName(), method);
325             }
326         }
327
328         // TxAttribute
329
// No methodDesc for bean's methods as ejbLoad(), ejbStore(), ...
330
if (methodDesc != null) {
331             mTxAttribute = methodDesc.getTxAttribute();
332         }
333
334         // ReturnType
335
mReturnType = JavaType.getName(method.getReturnType());
336
337         // isFinderXXX
338
boolean isFinder = false;
339
340         if (mName.startsWith("find")
341             && (javax.ejb.EJBHome JavaDoc.class.isAssignableFrom(declClass)
342                 || javax.ejb.EJBLocalHome JavaDoc.class.isAssignableFrom(declClass))
343             ) {
344             isFinder = true;
345         }
346         if (isFinder) {
347             if ("findByPrimaryKey".equals(mName)) {
348                 mKind = METHOD_FINDER_BY_PK;
349             } else {
350                 if (java.util.Enumeration JavaDoc.class.equals(method.getReturnType())) {
351                     mKind = METHOD_FINDER_ENUM;
352                 } else if (java.util.Collection JavaDoc.class.equals(method.getReturnType())) {
353                     mKind = METHOD_FINDER_COL;
354                 } else {
355                     mKind = METHOD_FINDER_SIMPLE;
356                 }
357             }
358         }
359
360         // isCreate
361
if (mName.startsWith("create")
362             && (javax.ejb.EJBHome JavaDoc.class.isAssignableFrom(declClass)
363                 || javax.ejb.EJBLocalHome JavaDoc.class.isAssignableFrom(declClass))
364             ) {
365             mKind = METHOD_CREATE;
366         }
367
368         // isEjbCreate
369
if (mName.startsWith("ejbCreate")
370             && javax.ejb.EnterpriseBean JavaDoc.class.isAssignableFrom(declClass)) {
371             mKind = METHOD_EJB_CREATE;
372         }
373
374         // isEjbPostCreate
375
if (mName.startsWith("ejbPostCreate")
376             && javax.ejb.EnterpriseBean JavaDoc.class.isAssignableFrom(declClass)) {
377             mKind = METHOD_EJB_POST_CREATE;
378         }
379
380         // isRemoveXXX
381
boolean isRemove = "remove".equals(mName);
382         if (isRemove) {
383             if (declClass.equals(javax.ejb.EJBObject JavaDoc.class)
384                 || declClass.equals(javax.ejb.EJBLocalObject JavaDoc.class)) {
385                 mKind = METHOD_REMOVE_THIS;
386             } else if (declClass.equals(javax.ejb.EJBHome JavaDoc.class)
387                        || declClass.equals(javax.ejb.EJBLocalHome JavaDoc.class)) {
388                 if (params[0].equals(javax.ejb.Handle JavaDoc.class)) {
389                     mKind = METHOD_REMOVE_HANDLE;
390                 } else {
391                     mKind = METHOD_REMOVE_PK;
392                 }
393             }
394         }
395
396         // isEjbRemove, isEjbLoad, isEjbStore
397
if (javax.ejb.EnterpriseBean JavaDoc.class.isAssignableFrom(declClass)
398             && (params.length == 0)) {
399             if ("ejbRemove".equals(mName)) {
400                 mKind = METHOD_EJB_REMOVE;
401             } else if ("ejbLoad".equals(mName)) {
402                 mKind = METHOD_EJB_LOAD;
403             } else if ("ejbStore".equals(mName)) {
404                 mKind = METHOD_EJB_STORE;
405             }
406         }
407
408         // isEjbSetEntityContext
409
if (javax.ejb.EnterpriseBean JavaDoc.class.isAssignableFrom(declClass)) {
410             if ("setEntityContext".equals(mName)
411                 && (params.length == 1)
412                 && javax.ejb.EntityContext JavaDoc.class.equals(params[0])) {
413                 mKind = METHOD_EJB_SET_ENTITY_CONTEXT;
414             }
415         }
416
417         // isEjbActivate
418
if (javax.ejb.EnterpriseBean JavaDoc.class.isAssignableFrom(declClass)) {
419             if ("ejbActivate".equals(mName)
420                 && (params.length == 0)) {
421                 mKind = METHOD_EJB_ACTIVATE;
422             }
423         }
424
425         if (dd instanceof EntityJdbcCmp1Desc) {
426             // For Entity CMP 1
427
// SqlStmt, and ParamsWhere in case of FinderSimple, FinderEnum or FinderCol.
428
EntityJdbcCmp1Desc edd = (EntityJdbcCmp1Desc) dd;
429             StringBuffer JavaDoc lf = new StringBuffer JavaDoc();
430             StringBuffer JavaDoc lv = new StringBuffer JavaDoc();
431             boolean firstLf = true;
432             boolean firstLv = true;
433             if (mKind == METHOD_EJB_CREATE) {
434                 for (Iterator JavaDoc i = edd.getCmpFieldDescIterator(); i.hasNext();) {
435                     FieldJdbcDesc fd = (FieldJdbcDesc) i.next();
436                     if (firstLv) {
437                         firstLv = false;
438                     } else {
439                         lf.append(", ");
440                         lv.append(", ");
441                     }
442                     lf.append(fd.getJdbcFieldName());
443                     lv.append("?");
444                 }
445                 mSqlStmt =
446                     "insert into " + edd.getJdbcTableName()
447                     + " (" + lf + ") values (" + lv + ")";
448             } else if (mKind == METHOD_FINDER_BY_PK) {
449                 for (Iterator JavaDoc i = edd.getCmpFieldDescIterator(); i.hasNext();) {
450                     FieldJdbcDesc fd = (FieldJdbcDesc) i.next();
451                     if (fd.isPrimaryKey()) {
452                         if (firstLv) {
453                             firstLv = false;
454                         } else {
455                             lf.append(", ");
456                             lv.append(" and ");
457                         }
458                         lf.append(fd.getJdbcFieldName());
459                         lv.append(fd.getJdbcFieldName() + "=?");
460                     }
461                 }
462
463                 mSqlStmt =
464                     "select " + lf + " from " + edd.getJdbcTableName()
465                     + " where " + lv;
466             } else if ((mKind == METHOD_FINDER_SIMPLE)
467                        || (mKind == METHOD_FINDER_ENUM)
468                        || (mKind == METHOD_FINDER_COL)) {
469                 if (!((MethodJdbcCmp1Desc) methodDesc).hasWhereClause()) {
470                     throw new Error JavaDoc("No WHERE clause defined for the finder method '"
471                                     + method.toString() + "'");
472                 }
473                 ArrayList JavaDoc posParams = new ArrayList JavaDoc();
474                 String JavaDoc clauseWhere = parseWhere (((MethodJdbcCmp1Desc) methodDesc).getWhereClause(), posParams);
475                 for (Iterator JavaDoc i = edd.getCmpFieldDescIterator(); i.hasNext();) {
476                     FieldJdbcDesc fd = (FieldJdbcDesc) i.next();
477                     if (fd.isPrimaryKey()) {
478                         if (firstLf) {
479                             firstLf = false;
480                         } else {
481                             lf.append(", ");
482                         }
483                         lf.append(fd.getJdbcFieldName());
484                     }
485                 }
486
487                 mSqlStmt =
488                     "select " + lf + " from " + edd.getJdbcTableName()
489                     + " " + clauseWhere;
490                 mParamWhereList = new ArrayList JavaDoc();
491                 for (int i = 0; i < posParams.size(); i++) {
492                     int pos = ((Integer JavaDoc) posParams.get(i)).intValue();
493                     if (pos >= params.length) {
494                         throw new Error JavaDoc("Wrong parameters number between the method definition and the WHERE clause of the method '" + method + "'");
495                     }
496                     VcParamWhere vpw = new VcParamWhere(params[pos], pos + 1);
497                     mParamWhereList.add(vpw);
498                 }
499             } else if (mKind == METHOD_EJB_REMOVE) {
500                 for (Iterator JavaDoc i = edd.getCmpFieldDescIterator(); i.hasNext();) {
501                     FieldJdbcDesc fd = (FieldJdbcDesc) i.next();
502                     if (fd.isPrimaryKey()) {
503                         if (firstLv) {
504                            firstLv = false;
505                         } else {
506                            lv.append(" and ");
507                         }
508                         lv.append(fd.getJdbcFieldName() + "=?");
509                     }
510                 }
511
512                 mSqlStmt =
513                     "delete from " + edd.getJdbcTableName()
514                     + " where " + lv;
515             } else if (mKind == METHOD_EJB_LOAD) {
516                 for (Iterator JavaDoc i = edd.getCmpFieldDescIterator(); i.hasNext();) {
517                     FieldJdbcDesc fd = (FieldJdbcDesc) i.next();
518                     if (firstLf) {
519                         firstLf = false;
520                     } else {
521                         lf.append(", ");
522                     }
523                     lf.append(fd.getJdbcFieldName());
524                     if (fd.isPrimaryKey()) {
525                         if (firstLv) {
526                             firstLv = false;
527                         } else {
528                             lv.append(" and ");
529                         }
530                         lv.append(fd.getJdbcFieldName() + "=?");
531                     }
532                 }
533
534                 mSqlStmt =
535                     "select " + lf + " from " + edd.getJdbcTableName()
536                     + " where " + lv;
537             } else if (mKind == METHOD_EJB_STORE) {
538                 for (Iterator JavaDoc i = edd.getCmpFieldDescIterator(); i.hasNext();) {
539                     FieldJdbcDesc fd = (FieldJdbcDesc) i.next();
540                     if (fd.isPrimaryKey()) {
541                         if (firstLv) {
542                             firstLv = false;
543                         } else {
544                             lv.append(" and ");
545                         }
546                         lv.append(fd.getJdbcFieldName() + "=?");
547                     } else {
548                         if (firstLf) {
549                            firstLf = false;
550                         } else {
551                             lf.append(", ");
552                         }
553                         lf.append(fd.getJdbcFieldName() + "=?");
554                     }
555                 }
556                 mSqlStmt =
557                     "update " + edd.getJdbcTableName()
558                     + " set " + lf + " where " + lv;
559             }
560         } else if (dd instanceof EntityJdbcCmp2Desc) {
561             // ejbSelect() methods
562
boolean isEjbSelect = false;
563             if (mName.startsWith("ejbSelect")
564                 && javax.ejb.EntityBean JavaDoc.class.isAssignableFrom(declClass)) {
565                 isEjbSelect = true;
566             }
567             if (isEjbSelect) {
568                 if (java.util.Collection JavaDoc.class.equals(method.getReturnType())) {
569                     mKind = METHOD_EJB_SELECT_COL;
570                 } else if (java.util.Set JavaDoc.class.equals(method.getReturnType())) {
571                     mKind = METHOD_EJB_SELECT_SET;
572                 } else {
573                     mKind = METHOD_EJB_SELECT_SIMPLE;
574                 }
575             }
576             if (isFinder || isEjbSelect) {
577                 mParamList = new ArrayList JavaDoc();
578                 for (int p = 0; p < params.length; p++) {
579                     mParamList.add(new VcParam(params[p], dd));
580                 }
581                 if (isEjbSelect) {
582                     try {
583                         resFieldOfEjbql = ((MethodCmp2Desc) methodDesc).getQueryTreeHolder(null).getResField();
584                         if (resFieldOfEjbql.getType().getTypeCode() == PType.TYPECODE_REFERENCE) {
585                             if (((MethodCmp2Desc) methodDesc).isResultTypeMappingRemote()) {
586                                 isEjbqlReturnRemoteBean = true;
587                             } else {
588                                 isEjbqlReturnLocalBean = true;
589                             }
590                         }
591                     } catch (DeploymentDescException e) {
592                         throw new Error JavaDoc("Error while the EJB-QL parsing of '" + method.toString()
593                                         + "': " + e.getMessage());
594                     }
595                 } else if (!isFinderByPk()) {
596                     // finder method other than findByPrimaryKey: parse the EJBQL query to check the query
597
try {
598                         ((MethodCmp2Desc) methodDesc).getQueryTreeHolder(null).getResField();
599                     } catch (DeploymentDescException ignore) {
600                         GenIC.warning("Warning: Error while the EJB-QL parsing of '" + method.toString()
601                                         + "': " + ignore.getMessage());
602                     }
603                 }
604             }
605
606         }
607
608         // System.out.print("VcMethod: "+method.toString());
609
// System.out.println(toString());
610
}
611
612     /**
613      * Parses Strings with syntax "WHERE summary like ?<nnn>"
614      * where <nnn> is a decimal integer that indexes (starting by 0)
615      * the parameters in the findByXXX method for CMP1.
616      * @param fragment
617      * @param pos
618      * @return
619      * @author: Santiago Gala (sgala@hisitech.com)
620      */

621     private String JavaDoc parseWhere(String JavaDoc fragment, List JavaDoc pos) {
622         StringTokenizer JavaDoc parseWhere = new StringTokenizer JavaDoc(fragment, "?\n", true);
623         int numpos = pos.size();
624         String JavaDoc newWhere = "";
625         String JavaDoc tok;
626         while (parseWhere.hasMoreTokens()) {
627             tok = parseWhere.nextToken();
628             String JavaDoc numVar = "";
629             if (Character.isDigit(tok.charAt(0))) {
630                 for (int i = 0; tok.length() > i && Character.isDigit(tok.charAt(i)); i++) {
631                     numVar += tok.charAt(i);
632                 }
633                 if (numVar.length() > 0) {
634                     newWhere += tok.substring(numVar.length(), tok.length());
635                     pos.set(numpos - 1, (Object JavaDoc) new Integer JavaDoc(Integer.parseInt(numVar) - 1));
636                 }
637             } else {
638                 newWhere += tok;
639                 if (tok.charAt(0) == '?') {
640                     pos.add(new Integer JavaDoc(numpos++));
641                 }
642             }
643         }
644         return newWhere;
645     }
646
647     /**
648      * @return Return the name of the method
649      */

650     public String JavaDoc getName() {
651         return mName;
652     }
653
654     /**
655      * @return Return the name of the method with the first letter capitalized
656      */

657     public String JavaDoc getCapName() {
658         return mCapName;
659     }
660
661     /**
662      * @return Return the string representation of the formal parameters list (ie "int p1, String p2")
663      */

664     public String JavaDoc getFormalParameters() {
665         return mFormalParameters.toString();
666     }
667
668     /**
669      * @return Return the string representation of the actual parameters list (ie "p1, p2")
670      */

671     public String JavaDoc getActualParameters() {
672         return mActualParameters.toString();
673     }
674
675     /**
676      * @return Return the string representation of the exception list of the method
677      */

678     public String JavaDoc getExceptionList() {
679         return mExceptionList.toString();
680     }
681
682     /**
683      * @return Return true if the method throws the javax.ejb.createException exception
684      */

685     public boolean canThrowCreate() {
686         return canThrowCreate;
687     }
688
689     /**
690      * @return Return the string representation of the security signature of the method
691      */

692     public String JavaDoc getSecuritySignature() {
693         if (mSecuritySignature == null) {
694             throw new Error JavaDoc("VcMethod.getSecuritySignature() not available for the method '"
695                             + mMethod.toString() + "'");
696         }
697         return mSecuritySignature;
698     }
699
700     /**
701      * @return Return the transactional attribute associated to the method
702      */

703     public int getTxAttribute() {
704         if (mTxAttribute == MethodDesc.TX_NULL) {
705             throw new Error JavaDoc("VcMethod.getTxAttribute() not available for the method '"
706                             + mMethod.toString() + "'");
707         }
708         return mTxAttribute;
709     }
710
711     /**
712      * @return Return the name of the return type of the method
713      */

714     public String JavaDoc getReturnType() {
715         return mReturnType;
716     }
717
718     /**
719      * @return Return false because we are not able to know if a finder method is a FinderAll method !!
720      */

721     public boolean isFinderAll() {
722         // How to known a finder is a finderAll !?
723
return false;
724     }
725
726     /**
727      * @return Return true if the method is the findByPrimaryKey() method
728      */

729     public boolean isFinderByPk() {
730         return (mKind == METHOD_FINDER_BY_PK);
731     }
732
733     /**
734      * @return Return true if the method is a finder method that returns a unique object
735      */

736     public boolean isFinderSimple() {
737         return (mKind == METHOD_FINDER_SIMPLE);
738     }
739
740     /**
741      * @return Return true if the method is a finder method that returns a Enumeration
742      */

743     public boolean isFinderEnum() {
744         return (mKind == METHOD_FINDER_ENUM);
745     }
746
747     /**
748      * @return Return true if the method is a finder method that returns a Collection
749      */

750     public boolean isFinderCol() {
751         return (mKind == METHOD_FINDER_COL);
752     }
753
754     /**
755      * @return Return true if the method is an ejbSelect method that returns a unique object
756      */

757     public boolean isEjbSelectSimple() {
758         return (mKind == METHOD_EJB_SELECT_SIMPLE);
759     }
760
761     /**
762      * @return Return true if the method is an ejbSelect method that returns a Set
763      */

764     public boolean isEjbSelectSet() {
765         return (mKind == METHOD_EJB_SELECT_SET);
766     }
767
768     /**
769      * @return Return true if the method is an ejbSelect method that returns a Collection
770      */

771     public boolean isEjbSelectCol() {
772         return (mKind == METHOD_EJB_SELECT_COL);
773     }
774
775     /**
776      * @return Return true if the method is a finder/select method that return a remote bean
777      */

778     public boolean isEjbqlReturnRemoteBean() {
779         return isEjbqlReturnRemoteBean;
780     }
781
782     /**
783      * @return Return true if the method is a finder/select method that return a local bean
784      */

785     public boolean isEjbqlReturnLocalBean() {
786         return isEjbqlReturnLocalBean;
787     }
788
789     /**
790      * @return Return true if the method is home.create()
791      */

792     public boolean isCreate() {
793         return (mKind == METHOD_CREATE);
794     }
795
796     /**
797      * @return Return true if the method is bean.ejbCreate()
798      */

799     public boolean isEjbCreate() {
800         return (mKind == METHOD_EJB_CREATE);
801     }
802
803     /**
804      * @return Return true if the method is bean.ejbPostCreate()
805      */

806     public boolean isEjbPostCreate() {
807         return (mKind == METHOD_EJB_POST_CREATE);
808     }
809
810     /**
811      * @return Return true if the method is EJBObject.remove() method
812      */

813     public boolean isRemoveThis() {
814         return (mKind == METHOD_REMOVE_THIS);
815     }
816
817     /**
818      * @return Return true if the method is home.remove(primarykey)
819      */

820     public boolean isRemovePk() {
821         return (mKind == METHOD_REMOVE_PK);
822     }
823
824     /**
825      * @return Return true if the method is home.remove(handle);
826      */

827     public boolean isRemoveHandle() {
828         return (mKind == METHOD_REMOVE_HANDLE);
829     }
830
831     /**
832      * @return Return true if the method is bean.ejbRemove()
833      */

834     public boolean isEjbRemove() {
835         return (mKind == METHOD_EJB_REMOVE);
836     }
837
838     /**
839      * @return Return true if the method is bean.ejbLoad()
840      */

841     public boolean isEjbLoad() {
842         return (mKind == METHOD_EJB_LOAD);
843     }
844
845     /**
846      * @return Return true if the method is bean.ejbStore()
847      */

848     public boolean isEjbStore() {
849         return (mKind == METHOD_EJB_STORE);
850     }
851
852     /**
853      * @return Return true if the method is bean.setEntityContext()
854      */

855     public boolean isEjbSetEntityContext() {
856         return (mKind == METHOD_EJB_SET_ENTITY_CONTEXT);
857     }
858
859     /**
860      * @return Return true if the method is bean.ejbActivate()
861      */

862     public boolean isEjbActivate() {
863         return (mKind == METHOD_EJB_ACTIVATE);
864     }
865
866     /**
867      * Only for CMP1 finder methods
868      * @return Return the string representation of the SQL statement associated to the method
869      */

870     public String JavaDoc getSqlStmt() {
871         if (mSqlStmt == null) {
872             throw new Error JavaDoc("VcMethod.getSqlStmt() not available for the method '"
873                             + mMethod.toString() + "'");
874         }
875         return mSqlStmt;
876     }
877
878
879     /**
880      * @return Return the Class array of the parameters of the method
881      */

882     public Class JavaDoc[] getParameterTypes() {
883         return parameterTypes;
884     }
885
886     /**
887      * @return Return the number of the parameters of the method
888      */

889     public int getParametersNumber() {
890         return parameterTypes.length;
891     }
892
893
894     /**
895      * Only for CMP1 finder methods
896      * @return Return the VcParamWhere list of the method
897      */

898     public Vector JavaDoc getParamWhereList() {
899         if (mParamWhereList == null) {
900             throw new Error JavaDoc("VcMethod.getParamWhereList() not available for the method '"
901                             + mMethod.toString() + "'");
902         }
903         return (new Vector JavaDoc(mParamWhereList));
904     }
905
906
907     /**
908      * @return Return the VcParam list of the method
909      */

910     public Vector JavaDoc getParamList() {
911         if (mParamList == null) {
912             throw new Error JavaDoc("VcMethod.getParamList() not available for the method '"
913                             + mMethod.toString() + "'");
914         }
915         return (new Vector JavaDoc(mParamList));
916     }
917
918
919     /**
920      * @return Return the index of the method. This is a unique index for each method of a bean.
921      */

922     public int getMethodIndex() {
923         return methodIndex;
924     }
925
926     /**
927      * Only for CMP2 finder/select methods
928      * @return Return the Medor field of tuple result of an Finder/Select method
929      */

930     public org.objectweb.medor.api.Field getResFieldOfEjbql() {
931         return resFieldOfEjbql;
932     }
933
934     /**
935      * Only for CMP2 finder/select methods
936      * @return Return the Medor get method name of the tuple result of an ejbSelect method
937      */

938     public String JavaDoc getTupleGetter() {
939         PType type = resFieldOfEjbql.getType();
940         switch(type.getTypeCode()) {
941         case PType.TYPECODE_BOOLEAN:
942             return "getBoolean";
943         case PType.TYPECODE_BYTE:
944             return "getByte";
945         case PType.TYPECODE_CHAR:
946             return "getChar";
947         case PType.TYPECODE_DATE:
948             return "getDate";
949         case PType.TYPECODE_DOUBLE:
950             return "getDouble";
951         case PType.TYPECODE_FLOAT:
952             return "getFloat";
953         case PType.TYPECODE_INT:
954             return "getInt";
955         case PType.TYPECODE_LONG:
956             return "getLong";
957         case PType.TYPECODE_SERIALIZED:
958             return "getObject";
959         case PType.TYPECODE_SHORT:
960             return "getShort";
961         case PType.TYPECODE_STRING:
962             return "getString";
963         case PType.TYPECODE_BIGDECIMAL:
964         case PType.TYPECODE_REFERENCE:
965         case PType.TYPECODE_BYTEARRAY:
966         case PType.TYPECODE_CHARARRAY:
967         case PType.TYPECODE_OBJBOOLEAN:
968         case PType.TYPECODE_OBJBYTE:
969         case PType.TYPECODE_OBJCHAR:
970         case PType.TYPECODE_OBJDOUBLE:
971         case PType.TYPECODE_OBJFLOAT:
972         case PType.TYPECODE_OBJINT:
973         case PType.TYPECODE_OBJLONG:
974         case PType.TYPECODE_OBJSHORT:
975         default:
976             return "getObject";
977         }
978     }
979
980     /**
981      * Only for CMP2 finder/select methods
982      * @return Return true is the return type of the Medor getter method of the tuple result of an ejbSelect method is a primitive type
983      */

984     public boolean isTupleGetterPrimitive() {
985         PType type = resFieldOfEjbql.getType();
986         switch(type.getTypeCode()) {
987         case PType.TYPECODE_BOOLEAN:
988         case PType.TYPECODE_BYTE:
989         case PType.TYPECODE_CHAR:
990         case PType.TYPECODE_DOUBLE:
991         case PType.TYPECODE_FLOAT:
992         case PType.TYPECODE_INT:
993         case PType.TYPECODE_LONG:
994         case PType.TYPECODE_SHORT:
995             return true;
996         default:
997             return false;
998         }
999     }
1000
1001    /**
1002     * Only for CMP2 finder/select methos
1003     * @return Return the associated class of the Medor getter method of the tuple result of an ejbSelect method when it's a primtive type
1004     */

1005    public String JavaDoc getTupleGetterObjectClass() {
1006        PType type = resFieldOfEjbql.getType();
1007        switch(type.getTypeCode()) {
1008        case PType.TYPECODE_BOOLEAN:
1009            return "Boolean";
1010        case PType.TYPECODE_BYTE:
1011            return "Byte";
1012        case PType.TYPECODE_CHAR:
1013            return "Char";
1014        case PType.TYPECODE_DOUBLE:
1015            return "Double";
1016        case PType.TYPECODE_FLOAT:
1017            return "Float";
1018        case PType.TYPECODE_INT:
1019            return "Integer";
1020        case PType.TYPECODE_LONG:
1021            return "Long";
1022        case PType.TYPECODE_SHORT:
1023            return "Short";
1024        default:
1025            return "Object";
1026        }
1027    }
1028
1029    /**
1030     * Split a dot separated path into tokens
1031     * @param path input path to split
1032     * @return Return the string array of the splited token
1033     */

1034    String JavaDoc[] splitPath(String JavaDoc path) {
1035        StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(path, ".");
1036        String JavaDoc[] ret = new String JavaDoc[st.countTokens()];
1037        for (int i = 0; i < ret.length; i++) {
1038            ret[i] = st.nextToken();
1039        }
1040        return ret;
1041    }
1042
1043    /**
1044     * Gets an empty array if no parameters and return an array of objects of the parameters if any
1045     * @return array of objects
1046     */

1047    public String JavaDoc getArrayObjectParameters() {
1048        if (mArrayObjectParameters.length() == 0) {
1049            return "new Object[0]";
1050        } else {
1051            return "new Object[] {" + mArrayObjectParameters.toString() + "}";
1052        }
1053    }
1054
1055
1056    /**
1057     * @return Return a string representation of the VcMethod object for debug use
1058     */

1059    public String JavaDoc toString() {
1060        StringBuffer JavaDoc ret = new StringBuffer JavaDoc();
1061        ret.append("\n Name = " + getName());
1062        ret.append("\n CapName = " + getCapName());
1063        ret.append("\n FormalParameters = " + getFormalParameters());
1064        ret.append("\n ActualParameters = " + getActualParameters());
1065        ret.append("\n ExceptionList = " + getExceptionList());
1066        if (mSecuritySignature != null) {
1067            ret.append("\n SecuritySignature = " + getSecuritySignature());
1068        }
1069        if (mTxAttribute != MethodDesc.TX_NULL) {
1070            ret.append("\n TxAttribute = " + getTxAttribute());
1071        }
1072        ret.append("\n ReturnType = " + getReturnType());
1073        ret.append("\n isFinderByPk = " + isFinderByPk());
1074        ret.append("\n isFinderSimple = " + isFinderSimple());
1075        ret.append("\n isFinderEnum = " + isFinderEnum());
1076        ret.append("\n isFinderCol = " + isFinderCol());
1077        ret.append("\n isCreate = " + isCreate());
1078        ret.append("\n isEjbCreate = " + isEjbCreate());
1079        ret.append("\n isRemoveThis = " + isRemoveThis());
1080        ret.append("\n isRemovePk = " + isRemovePk());
1081        ret.append("\n isRemoveHandle = " + isRemoveHandle());
1082        ret.append("\n isEjbRemove = " + isEjbRemove());
1083        ret.append("\n isEjbLoad = " + isEjbLoad());
1084        ret.append("\n isEjbStore = " + isEjbStore());
1085        ret.append("\n isEjbSetEntityContext = " + isEjbSetEntityContext());
1086        ret.append("\n isEjbActivate = " + isEjbActivate());
1087        ret.append("\n isEjbSelectSimple = " + isEjbSelectSimple());
1088        ret.append("\n isEjbSelectSet = " + isEjbSelectSet());
1089        ret.append("\n isEjbSelectCol = " + isEjbSelectCol());
1090        if (mSqlStmt != null) {
1091            ret.append("\n SqlStmt = " + getSqlStmt());
1092        }
1093        if (mParamWhereList != null) {
1094            ret.append("\n ParamWhereList = " + getParamWhereList());
1095        }
1096        return (ret.toString());
1097    }
1098
1099}
1100
Popular Tags