KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > generation > lib > NamingRules


1 /**
2  * Speedo: an implementation of JDO compliant personality on top of JORM generic
3  * I/O sub-system.
4  * Copyright (C) 2001-2004 France Telecom R&D
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 of the License, or (at your option) 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 USA
19  *
20  *
21  *
22  * Contact: speedo@objectweb.org
23  *
24  * Authors: S.Chassande-Barrioz.
25  *
26  */

27
28 package org.objectweb.speedo.generation.lib;
29
30 import org.objectweb.speedo.metadata.SpeedoClass;
31 import org.objectweb.speedo.metadata.SpeedoField;
32 import org.objectweb.jorm.api.PMapper;
33
34 import java.util.StringTokenizer JavaDoc;
35
36 /**
37  * Normalises names given to Proxy infrastructure's files created during
38  * generation.
39  * @author S.Chassande-Barrioz
40  */

41 public abstract class NamingRules {
42
43     /**
44      * Suffix added to the class name to create the proxy class name.
45      */

46     public final static String JavaDoc proxy = "Proxy";
47
48     /**
49      * Suffix added to the class name to create the field manager class name.
50      */

51     public final static String JavaDoc fields = "Fields";
52
53     /**
54      * Suffix added to the class name to create the field manager class name.
55      */

56     public final static String JavaDoc home = "Home";
57
58     /**
59      * Suffix added to the object idclass name
60      */

61     public final static String JavaDoc objectId = "_Id";
62
63     /**
64      * Gives the proxy name.
65      *
66      * @param className class name.
67      * @return proxy name.
68      */

69     public final static String JavaDoc proxyName(String JavaDoc className) {
70         return className + proxy;
71     }
72
73     /**
74      * Gives the home name.
75      *
76      * @param className class name.
77      * @return home name.
78      */

79     public final static String JavaDoc homeName(String JavaDoc className) {
80         return className + home;
81     }
82
83     public final static String JavaDoc generatedObjectIdName(String JavaDoc className) {
84         return className + objectId;
85     }
86
87     /**
88      * Gives the name of the persistent fields holder.
89      *
90      * @param className className.
91      * @return name for persistent fields holder.
92      */

93     public final static String JavaDoc fieldsName(String JavaDoc className) {
94         return className + fields;
95     }
96
97     /**
98      * Gives the name for the JORM class which manages binding between memory
99      * instances and database instances.
100      *
101      * @param className class name.
102      * @return binder name.
103      */

104     public final static String JavaDoc bindingName(String JavaDoc className) {
105         return className + "Binding";
106     }
107
108     /**
109      * Gives the name for the JORM class which manages binding between memory
110      * instances and database instances.
111      *
112      * @param className class name.
113      * @return binder name.
114      */

115     public final static String JavaDoc fqBindingName(String JavaDoc className, String JavaDoc mapperName) {
116         String JavaDoc p = packageName(className);
117         if (p == null || p.length() == 0) {
118             return mapperName + "." + className + "Binding";
119         } else {
120             return p + "." + mapperName + "." + className(className) + "Binding";
121         }
122     }
123
124     /**
125      * Gives the name for the JORM class which manages mapping.
126      *
127      * @param className class name.
128      * @return mapping name.
129      */

130     public final static String JavaDoc mappingName(String JavaDoc className) {
131         return className + "Mapping";
132     }
133
134     /**
135      * Gives the name for the JORM class which manages mapping.
136      *
137      * @param compositeNameName composite name.
138      * @return mapping name.
139      */

140     public final static String JavaDoc binderName(String JavaDoc compositeNameName) {
141         return compositeNameName + "Binder";
142     }
143
144     public final static String JavaDoc fpncName(String JavaDoc className) {
145         return className + "FPNC";
146     }
147
148     public final static String JavaDoc kfpncName(String JavaDoc className) {
149         return className + "KFPNC";
150     }
151
152     /**
153      * Gives the name for the JORM class which manages mapping.
154      *
155      * @param compositeNameName composite name.
156      * @return mapping name.
157      */

158     public final static String JavaDoc pnameName(String JavaDoc compositeNameName) {
159         return compositeNameName + "PName";
160     }
161
162     /**
163      * Gives the name for the JORM class which manages mapping.
164      *
165      * @param compositeNameName composite name.
166      * @return mapping name.
167      */

168     public final static String JavaDoc pngName(String JavaDoc compositeNameName) {
169         return compositeNameName + "PNG";
170     }
171
172     /**
173      * Gives the name for the JORM class which manages mapping.
174      *
175      * @param className class name.
176      * @return mapping name.
177      */

178     public final static String JavaDoc fqMappingName(String JavaDoc className) {
179         return className + PMapper.PCLASSMAPPINGAPPENDER;
180     }
181
182     /**
183      * Gives the name for the object which implements the interface PAccessor.
184      *
185      * @param className class name.
186      * @return manager name.
187      */

188     public final static String JavaDoc accessorName(String JavaDoc className) {
189         return className + "Accessor";
190     }
191
192     /**
193      * Gives the name for key objects.
194      *
195      * @param className class name.
196      * @return key class name.
197      */

198     public final static String JavaDoc keyName(String JavaDoc className) {
199         return className + "Key";
200     }
201
202     /**
203      * Gives the name of an accessor for a field (a get method).
204      *
205      * @param fieldName field name
206      * @return the name of the accessor method.
207      */

208     public final static String JavaDoc getterName(SpeedoClass sc, String JavaDoc fieldName) {
209         return "jdoGet" + fieldName;
210     }
211     public final static String JavaDoc getterName(SpeedoField sf) {
212         return "jdoGet" + sf.name;
213     }
214
215     /**
216      * Gives the name of a mutator for a field (a set method).
217      *
218      * @param fieldName field name
219      * @return the name of the mutator method.
220      */

221     public final static String JavaDoc setterName(SpeedoClass sc, String JavaDoc fieldName) {
222         return "jdoSet" + fieldName;
223     }
224
225     /**
226      * Gives the name of a coherent mutator for a reference field in a relation.
227      *
228      * @param fieldName field name
229      * @return the name of the mutator method.
230      */

231     public final static String JavaDoc coherentSetterName(SpeedoClass sc, String JavaDoc fieldName) {
232         return "jdoCoherentSet" + fieldName;
233     }
234
235     /**
236      * Gives the name of a mutator for a field (a set method).
237      *
238      * @param field field
239      * @return the name of the mutator method.
240      */

241     public final static String JavaDoc setterName(SpeedoField field) {
242         if (field.relationType == SpeedoField.NO_RELATION) {
243             return setterName(field.jdoClass, field.name);
244         } else {
245             return coherentSetterName(field.jdoClass, field.name);
246         }
247     }
248
249     /**
250      * Gets the name of a class
251      *
252      * @param completeClassName the complete name of the class including its package name
253      * @return the name of the class without its package
254      */

255     public static String JavaDoc className(String JavaDoc completeClassName) {
256         StringTokenizer JavaDoc tok = new StringTokenizer JavaDoc(completeClassName, ".");
257         String JavaDoc res = "";
258         while (tok.hasMoreTokens()) res = tok.nextToken();
259         return res;
260     }
261
262     /**
263      * Gets the package of a class
264      *
265      * @param completeClassName the complete name of the class including its package name
266      * @return the package of the class without its class name
267      */

268     public static String JavaDoc packageName(String JavaDoc completeClassName) {
269         StringTokenizer JavaDoc tok = new StringTokenizer JavaDoc(completeClassName, ".");
270         String JavaDoc res = "";
271         String JavaDoc resold = "";
272         while (tok.hasMoreTokens()) {
273             resold = (res == "") ? "" : ((resold == "") ? res : resold + "." + res);
274             res = tok.nextToken();
275         }
276         return resold;
277     }
278 }
279
Popular Tags