KickJava   Java API By Example, From Geeks To Geeks.

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


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
26 /*
27  * CMP20TemplateFormatter.java
28  *
29  * Created on February 25, 2004
30  */

31
32 package com.sun.jdo.spi.persistence.support.ejb.ejbc;
33
34 import java.io.*;
35
36 import java.text.MessageFormat JavaDoc;
37 import java.util.HashMap JavaDoc;
38 import java.util.Properties JavaDoc;
39 import java.util.StringTokenizer JavaDoc;
40
41 import com.sun.jdo.spi.persistence.utility.generator.JavaClassWriterHelper;
42
43 /*
44  * This is the helper class for JDO specific generation of
45  * a concrete bean implementation for CMP 2.0 beans.
46  * Because both CMP11TemplateFormatter and this class extend
47  * CMPTemplateFormatter, and all references are static, properties
48  * in this class must differ in names if there is a similar property
49  * in the super class. Such properties have 2_0 or 20 in them.
50  *
51  * @author Marina Vatkina
52  */

53 class CMP20TemplateFormatter extends CMPTemplateFormatter {
54
55     private final static String JavaDoc templateFile =
56         "com/sun/jdo/spi/persistence/support/ejb/ejbc/CMP20Templates.properties"; // NOI18N
57

58     // Strings for CMP 2.0 code generation:
59
public final static String JavaDoc local_ = "Local"; // NOI18N
60
public final static String JavaDoc ejbLocalObject_ = "EJBLocalObject"; // NOI18N
61
public final static String JavaDoc ejbLocalHome_ = "EJBLocalHome"; // NOI18N
62
public final static String JavaDoc getter_ = "getter"; // NOI18N
63
public final static String JavaDoc setter_ = "setter"; // NOI18N
64
public final static String JavaDoc assertPKsetter_ = "assertPKsetter"; // NOI18N
65
public final static String JavaDoc pksetter_ = "pksetter"; // NOI18N
66
public final static String JavaDoc pkstringsetter_ = "pkstringsetter"; // NOI18N
67
public final static String JavaDoc pkcopysetter_ = "pkcopysetter"; // NOI18N
68
public final static String JavaDoc copygetter_ = "copygetter"; // NOI18N
69
public final static String JavaDoc copysetter_ = "copysetter"; // NOI18N
70
public final static String JavaDoc arraygetter_ = "arraygetter"; // NOI18N
71
public final static String JavaDoc arraysetter_ = "arraysetter"; // NOI18N
72
public final static String JavaDoc sfldgetter_ = "sfldGetter"; // NOI18N
73
public final static String JavaDoc sfldsetter_ = "sfldSetter"; // NOI18N
74
public final static String JavaDoc cmrGetter_ = "cmrGetter"; // NOI18N
75
public final static String JavaDoc cmrSetter_ = "cmrSetter"; // NOI18N
76
public final static String JavaDoc cmrGetterCollection_ = "cmrGetterCollection"; // NOI18N
77
public final static String JavaDoc cmrSetterCollection_ = "cmrSetterCollection"; // NOI18N
78
public final static String JavaDoc startCascadeDelete_ = "startCascadeDelete"; // NOI18N
79
public final static String JavaDoc endCascadeDelete_ = "endCascadeDelete"; // NOI18N
80
public final static String JavaDoc cmrCascadeDelete_ = "cmrCascadeDelete"; // NOI18N
81
public final static String JavaDoc cmrCascadeDeleteCollection_ = "cmrCascadeDeleteCollection"; // NOI18N
82
public final static String JavaDoc localCmrVariables_ = "localCmrVariables"; // NOI18N
83
public final static String JavaDoc cleanCollectionCmr_ = "cleanCollectionCmr"; // NOI18N
84
public final static String JavaDoc ejbFinderSelectorParamCheckLocalInterface_
85                                      = "ejbFinderSelectorParamCheckLocalInterface"; // NOI18N
86
public final static String JavaDoc ejbFinderSelectorParamCheckRemoteInterface_
87                                      = "ejbFinderSelectorParamCheckRemoteInterface"; // NOI18N
88
public final static String JavaDoc ejbMultiSelectorBodyConversion_ = "ejbMultiSelectorBodyConversion"; // NOI18N
89
public final static String JavaDoc ejbMultiSelectorBody_ = "ejbMultiSelectorBody"; // NOI18N
90
public final static String JavaDoc ejbMultiSelectorBodySet_ = "ejbMultiSelectorBodySet"; // NOI18N
91
public final static String JavaDoc ejbSingleSelectorReturnBodyConversion_ = "ejbSingleSelectorReturnBodyConversion"; // NOI18N
92
public final static String JavaDoc ejbSingleSelectorReturnBody_ = "ejbSingleSelectorReturnBody"; // NOI18N
93
public final static String JavaDoc ejbAggregateSelectorPrimitiveReturnBody_ = "ejbAggregateSelectorPrimitiveReturnBody"; // NOI18N
94
public final static String JavaDoc ejbAggregateSelectorReturnBody_ = "ejbAggregateSelectorReturnBody"; // NOI18N
95
public final static String JavaDoc ejbAggregateSelectorReturnBodyConversion_ = "ejbAggregateSelectorReturnBodyConversion"; // NOI18N
96
public final static String JavaDoc ejbAggregateSelectorReturnBigDecimalConversion_ = "ejbAggregateSelectorReturnBigDecimalConversion"; // NOI18N
97
public final static String JavaDoc ejbAggregateSelectorReturnBigIntegerConversion_ = "ejbAggregateSelectorReturnBigIntegerConversion"; // NOI18N
98
public final static String JavaDoc ejbSingleSelectorBody_ = "ejbSingleSelectorBody"; // NOI18N
99
public final static String JavaDoc preSelect_ = "preSelect"; // NOI18N
100
public final static String JavaDoc convertPCToEJBLocalObject_
101                                      = "convertPCToEJBLocalObject"; // NOI18N
102
public final static String JavaDoc convertCollectionPCToEJBObject_
103                                      = "convertCollectionPCToEJBObject"; // NOI18N
104
public final static String JavaDoc convertCollectionPCToEJBObjectSet_
105                                      = "convertCollectionPCToEJBObjectSet"; // NOI18N
106
public final static String JavaDoc convertCollectionPCToEJBLocalObject_
107                                      = "convertCollectionPCToEJBLocalObject"; // NOI18N
108
public final static String JavaDoc convertCollectionPCToEJBLocalObjectSet_
109                                      = "convertCollectionPCToEJBLocalObjectSet"; // NOI18N
110
public final static String JavaDoc jdoCleanCollectionRef_ = "jdoCleanCollectionRef"; // NOI18N
111

112     // Inner helper Class strings.
113
public final static String JavaDoc helper20Interface_
114                       = "com.sun.jdo.spi.persistence.support.sqlstore.ejb.JDOEJB20Helper"; // NOI18N
115
public final static String JavaDoc helper20Impl_
116                       = "com.sun.jdo.spi.persistence.support.ejb.cmp.JDOEJB20HelperImpl"; // NOI18N
117

118     public final static String JavaDoc ejbHashSetImport_
119                       = "com.sun.jdo.spi.persistence.support.ejb.cmp.EJBHashSet"; // NOI18N
120

121     public final static String JavaDoc assertInstanceOfLocalInterfaceImpl_
122                                                           = "assertInstanceOfLocalInterfaceImpl"; // NOI18N
123
// property key for the CVS keyword substitution
124
public final static String JavaDoc signature2_0_ = "signature2_0"; //NOI18N
125

126     // getters and setters
127
public static MessageFormat JavaDoc gformatter = null; // CMP field getter
128
public static MessageFormat JavaDoc sformatter = null; // CMP field setter
129
public static MessageFormat JavaDoc copygformatter = null; // Date CMP field uses copygetter
130
public static MessageFormat JavaDoc copysformatter = null; // Date CMP field uses copysetter
131
public static MessageFormat JavaDoc arraygformatter = null; // byte[] CMP field uses arraygetter
132
public static MessageFormat JavaDoc arraysformatter = null; // byte[] CMP field uses arraysetter
133
public static MessageFormat JavaDoc assertpksformatter = null; // assert not null PK field setter
134
public static MessageFormat JavaDoc pksformatter = null; // PK field setter
135
public static MessageFormat JavaDoc pkstringsformatter = null; // String PK CMP field setter (calls trim())
136
public static MessageFormat JavaDoc pkcopysformatter = null; // Mutable PK CMP field setter (calls clone())
137
public static MessageFormat JavaDoc sfldgformatter = null; // Serializable CMP field getter
138
public static MessageFormat JavaDoc sfldsformatter = null; // Serializable CMP field setter
139

140     public static MessageFormat JavaDoc cmrgformatter = null; // 1-side CMR getter
141
public static MessageFormat JavaDoc cmrsformatter = null; // 1-side CMR setter
142
public static MessageFormat JavaDoc cmrCgformatter = null; // many-side CMR getter
143
public static MessageFormat JavaDoc cmrCsformatter = null; // many-side CMR setter
144
public static MessageFormat JavaDoc cmrcdformatter = null; // cascade-delete for one-one CMR
145
public static MessageFormat JavaDoc cmrcdCformatter = null; // cascade-delete for one-many CMR
146

147     // 2.0 variables
148
public static MessageFormat JavaDoc cmrvformatter = null; // local cmr variables
149
public static MessageFormat JavaDoc cleancmrformatter = null; // clean collection cmr references
150

151     // 2.0 methods
152
public static MessageFormat JavaDoc cformatter = null; // ejbCreate
153
public static MessageFormat JavaDoc cunpkformatter = null; // ejbCreateUnknownPK
154
public static MessageFormat JavaDoc postcformatter = null; // ejbPostCreate
155
public static MessageFormat JavaDoc rmformatter = null; // ejbRemove
156

157     // finder/selector methods
158
public static MessageFormat JavaDoc finderselectorchecklocalformatter = null; //common body for selector and finder param check for local interface impl class
159
public static MessageFormat JavaDoc finderselectorcheckremoteformatter = null; //common body for selector and finder param check for remote interface impl class
160
public static MessageFormat JavaDoc preselectformatter = null; // preSelect callback
161
public static MessageFormat JavaDoc multiselectorconvformatter = null; // selector for multi-value-objects body with resultset-conversion
162
public static MessageFormat JavaDoc multiselectorformatter = null; // selector for multi-value-objects body
163
public static MessageFormat JavaDoc multiselectorsetformatter = null; // selector for multi-value-objects body and conversion to Set
164
public static MessageFormat JavaDoc singleselectorreturnconvformatter = null; // selector for single-value-objects body with resultset-conversion
165
public static MessageFormat JavaDoc singleselectorreturnformatter = null; // selector for single-value-objects body with resultset-conversion
166
public static MessageFormat JavaDoc aggregateselectorprimitivereturnformatter = null; // selector for aggregate functions return primitive without object conversion
167
public static MessageFormat JavaDoc aggregateselectorreturnformatter = null; // selector for aggregate functions without object conversion
168
public static MessageFormat JavaDoc aggregateselectorreturnconvformatter = null; // selector for aggregate functions with object conversion
169
public static MessageFormat JavaDoc aggregateselectorreturnbigdecimalconvformatter = null; // selector for aggregate functions with BigDecimal conversion
170
public static MessageFormat JavaDoc aggregateselectorreturnbigintegerconvformatter = null; // selector for aggregate functions with BigInteger conversion
171
public static MessageFormat JavaDoc singleselectorformatter = null; // selector for single-value-objects body
172

173     // standard templates for the corresponding keys, so that a template "xxxTemplate"
174
// corresponds to a "xxx" key.
175
public static String JavaDoc startCascadeDeleteTemplate = null;
176     public static String JavaDoc endCascadeDeleteTemplate = null;
177     public static String JavaDoc assertInstanceOfLocalInterfaceImplTemplate = null;
178     public static String JavaDoc signature2_0Template = null;
179
180     private static boolean is20HelpersLoaded = false;
181
182     /**
183      * Constructs a new <code>CMP20TemplateFormatter</code> instance.
184      */

185     CMP20TemplateFormatter() {
186     }
187
188     /**
189      * Initializes templates for code generation.
190      */

191     static synchronized void initHelpers() throws IOException {
192         if (is20HelpersLoaded == false) {
193             loadProperties(helpers, templateFile);
194             init20Formatters();
195             init20Templates();
196
197             is20HelpersLoaded = true;
198
199         }
200     }
201
202     /**
203      * Initializes MessageFormats for code generation.
204      */

205     private static void init20Formatters() {
206         // getters and setters
207
gformatter = new MessageFormat JavaDoc(helpers.getProperty(getter_));
208         sformatter = new MessageFormat JavaDoc(helpers.getProperty(setter_));
209         copygformatter = new MessageFormat JavaDoc(helpers.getProperty(copygetter_));
210         copysformatter = new MessageFormat JavaDoc(helpers.getProperty(copysetter_));
211         arraygformatter = new MessageFormat JavaDoc(helpers.getProperty(arraygetter_));
212         arraysformatter = new MessageFormat JavaDoc(helpers.getProperty(arraysetter_));
213         assertpksformatter = new MessageFormat JavaDoc(helpers.getProperty(assertPKsetter_));
214         pksformatter = new MessageFormat JavaDoc(helpers.getProperty(pksetter_));
215         pkstringsformatter = new MessageFormat JavaDoc(helpers.getProperty(pkstringsetter_));
216         pkcopysformatter = new MessageFormat JavaDoc(helpers.getProperty(pkcopysetter_));
217         sfldsformatter = new MessageFormat JavaDoc(helpers.getProperty(sfldsetter_));
218         sfldgformatter = new MessageFormat JavaDoc(helpers.getProperty(sfldgetter_));
219         cmrgformatter = new MessageFormat JavaDoc(helpers.getProperty(cmrGetter_));
220         cmrsformatter = new MessageFormat JavaDoc(helpers.getProperty(cmrSetter_));
221         cmrCgformatter = new MessageFormat JavaDoc(helpers.getProperty(cmrGetterCollection_));
222         cmrCsformatter = new MessageFormat JavaDoc(helpers.getProperty(cmrSetterCollection_));
223         cmrcdformatter = new MessageFormat JavaDoc(helpers.getProperty(cmrCascadeDelete_));
224         cmrcdCformatter = new MessageFormat JavaDoc(helpers.getProperty(cmrCascadeDeleteCollection_));
225
226         // 2.0 variables
227
cmrvformatter = new MessageFormat JavaDoc(helpers.getProperty(localCmrVariables_));
228         cleancmrformatter = new MessageFormat JavaDoc(helpers.getProperty(cleanCollectionCmr_));
229
230         // 2.0 methods
231
cformatter = new MessageFormat JavaDoc(helpers.getProperty(ejbCreate_));
232         cunpkformatter = new MessageFormat JavaDoc(helpers.getProperty(ejbCreateUnknownPK_));
233         postcformatter = new MessageFormat JavaDoc(helpers.getProperty(ejbPostCreate_));
234         rmformatter = new MessageFormat JavaDoc(helpers.getProperty(ejbRemove_));
235
236         // 2.0 finder/selector methods
237
finderselectorchecklocalformatter = new MessageFormat JavaDoc(helpers.getProperty(ejbFinderSelectorParamCheckLocalInterface_));
238         finderselectorcheckremoteformatter = new MessageFormat JavaDoc(helpers.getProperty(ejbFinderSelectorParamCheckRemoteInterface_));
239         preselectformatter = new MessageFormat JavaDoc(helpers.getProperty(preSelect_));
240         multiselectorconvformatter = new MessageFormat JavaDoc(helpers.getProperty(ejbMultiSelectorBodyConversion_));
241         multiselectorformatter = new MessageFormat JavaDoc(helpers.getProperty(ejbMultiSelectorBody_));
242         multiselectorsetformatter = new MessageFormat JavaDoc(helpers.getProperty(ejbMultiSelectorBodySet_));
243         singleselectorreturnconvformatter = new MessageFormat JavaDoc(helpers.getProperty(ejbSingleSelectorReturnBodyConversion_));
244         singleselectorreturnformatter = new MessageFormat JavaDoc(helpers.getProperty(ejbSingleSelectorReturnBody_));
245         aggregateselectorprimitivereturnformatter = new MessageFormat JavaDoc(helpers.getProperty(ejbAggregateSelectorPrimitiveReturnBody_));
246         aggregateselectorreturnformatter = new MessageFormat JavaDoc(helpers.getProperty(ejbAggregateSelectorReturnBody_));
247         aggregateselectorreturnconvformatter = new MessageFormat JavaDoc(helpers.getProperty(ejbAggregateSelectorReturnBodyConversion_));
248         aggregateselectorreturnbigdecimalconvformatter = new MessageFormat JavaDoc(helpers.getProperty(ejbAggregateSelectorReturnBigDecimalConversion_));
249         aggregateselectorreturnbigintegerconvformatter = new MessageFormat JavaDoc(helpers.getProperty(ejbAggregateSelectorReturnBigIntegerConversion_));
250         singleselectorformatter = new MessageFormat JavaDoc(helpers.getProperty(ejbSingleSelectorBody_));
251     }
252
253     /**
254      * Initializes standard templates for code generation.
255      */

256     private static void init20Templates() {
257         startCascadeDeleteTemplate = helpers.getProperty(startCascadeDelete_);
258         endCascadeDeleteTemplate = helpers.getProperty(endCascadeDelete_);
259         assertInstanceOfLocalInterfaceImplTemplate = helpers.getProperty(
260             assertInstanceOfLocalInterfaceImpl_);
261         signature2_0Template = helpers.getProperty(signature2_0_);
262     }
263 }
264
Popular Tags