KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jdo > spi > persistence > support > ejb > ejbc > MethodHelper


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

23
24 /*
25  * MethodHelper.java
26  *
27  * Created on December 20, 2001, 5:30 PM
28  */

29
30 package com.sun.jdo.spi.persistence.support.ejb.ejbc;
31
32 import java.util.ArrayList JavaDoc;
33 import java.util.Collection JavaDoc;
34 import java.util.ResourceBundle JavaDoc;
35 import java.lang.reflect.Method JavaDoc;
36
37 import com.sun.enterprise.deployment.runtime.IASEjbCMPFinder;
38 import com.sun.enterprise.deployment.runtime.PrefetchDisabledDescriptor;
39 import com.sun.enterprise.deployment.IASEjbCMPEntityDescriptor;
40 import com.sun.enterprise.deployment.MethodDescriptor;
41 import com.sun.enterprise.deployment.QueryDescriptor;
42
43 import com.sun.jdo.spi.persistence.utility.I18NHelper;
44 import com.sun.jdo.spi.persistence.utility.generator.JavaClassWriterHelper;
45
46 /** This is a subclass of {@link AbstractMethodHelper}
47  * which provides overridden method implementations based on an SunONE
48  * implementation.
49  *
50  * @author Rochelle Raccah
51  */

52 public class MethodHelper extends AbstractMethodHelper
53 {
54     /** I18N message handler */
55     private final static ResourceBundle JavaDoc messages = I18NHelper.loadBundle(
56             MethodHelper.class);
57
58     /** Creates a new instance of MethodHelper
59      * @param ejbcmp the IASEjbCMPEntityDescriptor which defines the
60      * information for this bean.
61      */

62     public MethodHelper (IASEjbCMPEntityDescriptor descriptor)
63     {
64         super(descriptor);
65     }
66
67     /**
68      * Reads all known methods and sorts them by name into specific
69      * Collections for further processing.
70      */

71     protected void categorizeMethods ()
72     {
73         IASEjbCMPEntityDescriptor cmpDescriptor =
74             (IASEjbCMPEntityDescriptor)getDescriptor();
75
76         super.categorizeMethods();
77
78         // replace the finders and selectors with ias specific info
79
setFinders(getListForCollection(cmpDescriptor.getFinders()));
80         setSelectors(getListForCollection(cmpDescriptor.getSelectors()));
81     }
82
83     // returns a non-null list for the supplied collection
84
private static ArrayList JavaDoc getListForCollection (Collection JavaDoc aCollection)
85     {
86         return ((aCollection != null) ?
87             new ArrayList JavaDoc(aCollection) : new ArrayList JavaDoc());
88     }
89
90     /** Returns <code>true</code> if prefetch is enabled for the specified
91      * method, <code>false</code> otherwise. Prefetch is enabled by default.
92      * @param method the java.lang.reflect.Method object used to find the
93      * prefetch setting.
94      * @return a boolean representing the prefetch setting
95      */

96     public boolean isQueryPrefetchEnabled (Method JavaDoc method)
97     {
98         boolean enabled = true;
99         QueryDescriptor queryDescriptor = getQueryDescriptor(method);
100
101         if (queryDescriptor != null)
102         {
103             IASEjbCMPEntityDescriptor cmpDescriptor =
104                 (IASEjbCMPEntityDescriptor)getDescriptor();
105             PrefetchDisabledDescriptor pdDescriptor =
106                 cmpDescriptor.getPrefetchDisabledDescriptor();
107
108             if (pdDescriptor != null)
109             {
110                 MethodDescriptor methodDescriptor =
111                     queryDescriptor.getQueryMethodDescriptor();
112
113                 enabled = !pdDescriptor.isPrefetchDisabledFor(
114                     methodDescriptor);
115             }
116         }
117
118         return enabled;
119     }
120
121     /** Gets the jdo filter expression associated with the specified method
122      * if it exists. Note that this method should only be used for CMP 1.1 -
123      * use {@link #getQueryString} for CMP 2.0.
124      * @param method the java.lang.reflect.Method object used to find the
125      * query filter
126      * @return the jdo filter expression
127      */

128     public String JavaDoc getJDOFilterExpression (Method JavaDoc method)
129     {
130         IASEjbCMPFinder cmpFinder = getFinder(method);
131
132         return ((cmpFinder != null) ? cmpFinder.getQueryFilter() : null);
133     }
134
135     /** Gets the jdo parameter declaration associated with the specified
136      * method if it exists. Note that this method should only be used for
137      * CMP 1.1 - use {@link #getQueryString} for CMP 2.0.
138      * @param method the java.lang.reflect.Method object used to find the
139      * parameter declaration
140      * @return the jdo parameter declaration
141      */

142     public String JavaDoc getJDOParameterDeclaration (Method JavaDoc method)
143     {
144         IASEjbCMPFinder cmpFinder = getFinder(method);
145
146         return ((cmpFinder != null) ?
147             cmpFinder.getQueryParameterDeclaration() : null);
148     }
149
150     /** Gets the jdo variables declaration associated with the specified
151      * method if it exists. Note that this method should only be used for
152      * CMP 1.1 - use {@link #getQueryString} for CMP 2.0.
153      * @param method the java.lang.reflect.Method object used to find the
154      * parameter declaration
155      * @return the jdo variables declaration
156      */

157     public String JavaDoc getJDOVariableDeclaration (Method JavaDoc method)
158     {
159         IASEjbCMPFinder cmpFinder = getFinder(method);
160
161         return ((cmpFinder != null) ? cmpFinder.getQueryVariables() : null);
162     }
163
164     /** Gets the jdo ordering specification associated with the specified
165      * method if it exists. Note that this method should only be used for
166      * CMP 1.1 - use {@link #getQueryString} for CMP 2.0.
167      * @param method the java.lang.reflect.Method object used to find the
168      * parameter declaration
169      * @return the jdo ordering specification
170      */

171     public String JavaDoc getJDOOrderingSpecification (Method JavaDoc method)
172         {
173         IASEjbCMPFinder cmpFinder = getFinder(method);
174
175         return ((cmpFinder != null) ? cmpFinder.getQueryOrdering() : null);
176         }
177
178
179     private IASEjbCMPFinder getFinder (Method JavaDoc method)
180     {
181         IASEjbCMPEntityDescriptor cmpDescriptor =
182             (IASEjbCMPEntityDescriptor)getDescriptor();
183         IASEjbCMPFinder finder = cmpDescriptor.getIASEjbCMPFinder(method);
184
185         if (finder == null) {
186             String JavaDoc methodSignature = cmpDescriptor.getName() + '.' +
187                 method.getName() +
188                 JavaClassWriterHelper.parenleft_ +
189                 JavaClassWriterHelper.getParameterTypesList(method) +
190                 JavaClassWriterHelper.parenright_ ;
191             String JavaDoc msg = I18NHelper.getMessage(messages,
192                 "EXC_MissingCMP11Finder", methodSignature);//NOI18N
193
throw new RuntimeException JavaDoc(msg);
194         }
195
196         return finder;
197     }
198 }
199
Popular Tags