001: /**
002: * Speedo: an implementation of JDO compliant personality on top of JORM generic
003: * I/O sub-system.
004: * Copyright (C) 2001-2004 France Telecom R&D
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: *
021: *
022: * Contact: speedo@objectweb.org
023: *
024: * Authors: S.Chassande-Barrioz.
025: *
026: */package org.objectweb.speedo.generation.lib;
027:
028: import org.objectweb.speedo.metadata.SpeedoClass;
029: import org.objectweb.speedo.metadata.SpeedoField;
030: import org.objectweb.jorm.api.PMapper;
031:
032: import java.util.StringTokenizer;
033:
034: /**
035: * Normalises names given to PO infrastructure's files created during
036: * generation.
037: * @author S.Chassande-Barrioz
038: */
039: public abstract class NamingRules {
040:
041: /**
042: * Suffix added to the class name to create the field manager class name.
043: */
044: public final static String FIELDS = "Fields";
045:
046: /**
047: * Suffix added to the class name to create the field manager class name.
048: */
049: public final static String HOME = "Home";
050:
051: /**
052: * Suffix added to the object idclass name
053: */
054: public final static String OBJECT_ID = "_Id";
055:
056: /**
057: * Gives the home name.
058: *
059: * @param className class name.
060: * @return home name.
061: */
062: public final static String homeName(String className) {
063: return className + HOME;
064: }
065:
066: public final static String generatedObjectIdName(String className) {
067: return className + OBJECT_ID;
068: }
069:
070: /**
071: * Gives the name of the persistent fields holder.
072: *
073: * @param className className.
074: * @return name for persistent fields holder.
075: */
076: public final static String fieldsName(String className) {
077: return className + FIELDS;
078: }
079:
080: /**
081: * Gives the name for the JORM class which manages binding between memory
082: * instances and database instances.
083: *
084: * @param className class name.
085: * @return binder name.
086: */
087: public final static String fqBindingName(String className,
088: String mapperName) {
089: String p = packageName(className);
090: if (p == null || p.length() == 0) {
091: return mapperName + "." + className + "Binding";
092: } else {
093: return p + "." + mapperName + "." + className(className)
094: + "Binding";
095: }
096: }
097:
098: /**
099: * Gives the name for the JORM class which manages mapping.
100: *
101: * @param className class name.
102: * @return mapping name.
103: */
104: public final static String mappingName(String className) {
105: return className + "Mapping";
106: }
107:
108: /**
109: * Gives the name for the JORM class which manages mapping.
110: *
111: * @param compositeNameName composite name.
112: * @return mapping name.
113: */
114: public final static String binderName(String compositeNameName) {
115: return compositeNameName + "Binder";
116: }
117:
118: public final static String fpncName(String className) {
119: return className + "FPNC";
120: }
121:
122: public final static String kfpncName(String className) {
123: return className + "KFPNC";
124: }
125:
126: /**
127: * Gives the name for the JORM class which manages mapping.
128: *
129: * @param compositeNameName composite name.
130: * @return mapping name.
131: */
132: public final static String pnameName(String compositeNameName) {
133: return compositeNameName + "PName";
134: }
135:
136: /**
137: * Gives the name for the JORM class which manages mapping.
138: *
139: * @param compositeNameName composite name.
140: * @return mapping name.
141: */
142: public final static String pngName(String compositeNameName) {
143: return compositeNameName + "PNG";
144: }
145:
146: /**
147: * Gives the name for the JORM class which manages mapping.
148: *
149: * @param className class name.
150: * @return mapping name.
151: */
152: public final static String fqMappingName(String className) {
153: return className + PMapper.PCLASSMAPPINGAPPENDER;
154: }
155:
156: /**
157: * Gives the name for the object which implements the interface PAccessor.
158: *
159: * @param className class name.
160: * @return manager name.
161: */
162: public final static String accessorName(String className) {
163: return className + "Accessor";
164: }
165:
166: /**
167: * Gives the name for key objects.
168: *
169: * @param className class name.
170: * @return key class name.
171: */
172: public final static String keyName(String className) {
173: return className + "Key";
174: }
175:
176: /**
177: * Gives the name of an accessor for a field (a get method).
178: *
179: * @param fieldName field name
180: * @return the name of the accessor method.
181: */
182: public final static String getterName(SpeedoClass sc,
183: String fieldName) {
184: return "jdoGet" + fieldName;
185: }
186:
187: public final static String getterName(SpeedoField sf) {
188: return "jdoGet" + sf.name;
189: }
190:
191: /**
192: * Gives the name of a mutator for a field (a set method).
193: *
194: * @param fieldName field name
195: * @return the name of the mutator method.
196: */
197: public final static String setterName(SpeedoClass sc,
198: String fieldName) {
199: return "jdoSet" + fieldName;
200: }
201:
202: /**
203: * Gives the name of a coherent mutator for a reference field in a relation.
204: *
205: * @param fieldName field name
206: * @return the name of the mutator method.
207: */
208: public final static String coherentSetterName(SpeedoClass sc,
209: String fieldName) {
210: return "jdoCoherentSet" + fieldName;
211: }
212:
213: /**
214: * Gives the name of a mutator for a field (a set method).
215: *
216: * @param field field
217: * @return the name of the mutator method.
218: */
219: public final static String setterName(SpeedoField field) {
220: if (field.relationType == SpeedoField.NO_BI_RELATION) {
221: return setterName(field.moClass, field.name);
222: } else {
223: return coherentSetterName(field.moClass, field.name);
224: }
225: }
226:
227: /**
228: * Gets the name of a class
229: *
230: * @param completeClassName the complete name of the class including its package name
231: * @return the name of the class without its package
232: */
233: public static String className(String completeClassName) {
234: StringTokenizer tok = new StringTokenizer(completeClassName,
235: ".");
236: String res = "";
237: while (tok.hasMoreTokens())
238: res = tok.nextToken();
239: return res;
240: }
241:
242: /**
243: * Gets the package of a class
244: *
245: * @param completeClassName the complete name of the class including its package name
246: * @return the package of the class without its class name
247: */
248: public static String packageName(String completeClassName) {
249: StringTokenizer tok = new StringTokenizer(completeClassName,
250: ".");
251: String res = "";
252: String resold = "";
253: while (tok.hasMoreTokens()) {
254: resold = (res == "") ? "" : ((resold == "") ? res : resold
255: + "." + res);
256: res = tok.nextToken();
257: }
258: return resold;
259: }
260: }
|