KickJava   Java API By Example, From Geeks To Geeks.

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


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: MethodCmp2Desc.java,v 1.10 2005/03/11 12:34:28 joaninh Exp $
23  * --------------------------------------------------------------------------
24  */

25
26
27 package org.objectweb.jonas_ejb.deployment.api;
28
29 import java.io.CharArrayReader JavaDoc;
30 import java.lang.reflect.Method JavaDoc;
31
32 import org.objectweb.jonas_ejb.deployment.ejbql.ASTEJBQL;
33 import org.objectweb.jonas_ejb.deployment.ejbql.EJBQL;
34 import org.objectweb.jonas_ejb.deployment.ejbql.ParseException;
35 import org.objectweb.jonas_ejb.lib.EjbqlQueryTreeHolder;
36 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException;
37 import org.objectweb.jorm.api.PMapper;
38
39
40 /**
41  * Class to hold meta-information related to CMP2 find/select methods
42  * @author Christophe Ney [cney@batisseurs.com] : Initial developer
43  * @author Helene Joanin
44  */

45 public class MethodCmp2Desc extends MethodDesc {
46
47     protected String JavaDoc query = null;
48     protected ASTEJBQL queryNode = null;
49     protected EjbqlQueryTreeHolder queryTreeHolder = null;
50     protected boolean resultTypeMappingRemote = false;
51     protected EntityDesc entityDesc;
52
53
54     /**
55      * construtor form XML data binding structures
56      */

57     MethodCmp2Desc(BeanDesc beanDesc, Method JavaDoc meth, Class JavaDoc classDef, int index) {
58         super(beanDesc, meth, classDef, index);
59         entityDesc = (EntityDesc) beanDesc;
60     }
61
62     /**
63      * get EJB-QL query when defined
64      * @return possibly null String containing the EJB-QL query for the method
65      */

66     public String JavaDoc getQuery() {
67         return query;
68     }
69
70     /**
71      * set EJB-QL query. Because of the deployment descriptor structure, the query is
72      * set after the object is created.
73      */

74     public void setQuery(String JavaDoc query) throws ParseException {
75         // we want a one line query for error reporting
76
this.query = query.replace('\r',' ').replace('\n',' ').replace('\t',' ');
77         EJBQL parser = new EJBQL(new CharArrayReader JavaDoc(query.toCharArray()));
78         queryNode = (ASTEJBQL)parser.EJBQL();
79         queryTreeHolder=null;
80     }
81
82
83     /**
84      * return a query tree holder allowing evaluation of the query
85      */

86     public EjbqlQueryTreeHolder getQueryTreeHolder(PMapper mapper) throws DeploymentDescException {
87         if (queryTreeHolder==null) {
88             try {
89                 queryTreeHolder = new EjbqlQueryTreeHolder(this, queryNode, mapper);
90             } catch (Exception JavaDoc e) {
91                 throw new DeploymentDescException("ejbql query "+query+" does not map to the persistent schema",e);
92             }
93         }
94         return queryTreeHolder;
95     }
96
97     /**
98      * get result type mapping state (remote/local)
99      * @return true when remote
100      */

101     public boolean isResultTypeMappingRemote() {
102         return resultTypeMappingRemote;
103     }
104
105     /**
106      * set the state of resultTypeMappingRemote
107      */

108     public void setResultTypeMapping(String JavaDoc resultTypeMapping)
109         throws DeploymentDescException {
110             if (resultTypeMapping.equals("Remote")) {
111                 resultTypeMappingRemote=true;
112             } else if (resultTypeMapping.equals("Local")) {
113                 resultTypeMappingRemote=false;
114             } else {
115                 throw new DeploymentDescException(resultTypeMapping+" is not a valid result-type-mapping value");
116             }
117     }
118
119     /**
120      * Get the prefetch tag value for this method.
121      * May be true only for finder methods (not for ejbSelect methods)
122      */

123     public boolean getPrefetch() {
124         if (this.isFinder()) {
125             return entityDesc.isPrefetch();
126         } else {
127             return false;
128         }
129     }
130
131
132     /**
133      * String representation of the given element <method>
134      * @param m an element <method>
135      * @return String representation of the given element method
136      */

137     public static String JavaDoc queryMethodElementToString(org.objectweb.jonas_ejb.deployment.xml.QueryMethod m) {
138         return methodElementToString(null, m.getMethodName(),m.getMethodParams());
139     }
140
141     /**
142      * String representation of the object for test purpose
143      * @return String representation of this object
144      */

145     public String JavaDoc toString() {
146         StringBuffer JavaDoc ret = new StringBuffer JavaDoc();
147         ret.append(super.toString());
148         ret.append("\nquery = " + query);
149         ret.append("\nqueryNode = " + queryNode);
150         ret.append("\nqueryTreeHolder = " + queryTreeHolder);
151         ret.append("\nresultTypeMappingRemote = " + resultTypeMappingRemote);
152         return ret.toString();
153     }
154
155 }
156
Popular Tags