001: /**
002: * Copyright (C) 2001-2005 France Telecom R&D
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */package org.objectweb.speedo.lib;
018:
019: import org.objectweb.jorm.util.lib.StringReplace;
020:
021: import java.io.File;
022: import java.io.Serializable;
023:
024: /**
025: * Represents a Speedo personality. Two well instances are defined (one for
026: * each personality): #JDO and #EJB. This class provides a parser method
027: * #getPersonality(String) retrieving the personality from its name.
028: *
029: * @author S.Chassande-Barrioz
030: */
031: public abstract class Personality implements Serializable {
032:
033: public static Personality JDO;
034: public static Personality EJB;
035:
036: static {
037: try {
038: JDO = (Personality) Class.forName(
039: "org.objectweb.speedo.jdo.JDOPersonality")
040: .newInstance();
041: JDO.init("jdo");
042: } catch (Throwable e) {
043: JDO = null;
044: }
045: try {
046: EJB = (Personality) Class.forName(
047: "org.objectweb.speedo.ejb.EJBPersonality")
048: .newInstance();
049: EJB.init("ejb");
050: } catch (Throwable e) {
051: EJB = null;
052: }
053: }
054:
055: private String name;
056: private String nameUpper;
057: private String classNameDot = null;
058: private String classNameSlash = null;
059: private String classNameUserDot = null;
060: private String classNameUserSlash = null;
061: private String classNameFatalDot = null;
062: private String classNameFatalSlash = null;
063: private String classNameDetachSlash = null;
064:
065: /**
066: * Retrieve the basic runtime exception dedicated to the relevant personality.
067: *
068: * @return The class of the user exception to be thrown.
069: */
070: public abstract RuntimeException newRuntimeException();
071:
072: public abstract RuntimeException newRuntimeException(String msg);
073:
074: public abstract RuntimeException newRuntimeException(String msg,
075: Throwable[] nested);
076:
077: public abstract RuntimeException newRuntimeException(String msg,
078: Throwable nested);
079:
080: public abstract RuntimeException newRuntimeException(String msg,
081: Object failed);
082:
083: public abstract RuntimeException newRuntimeException(String msg,
084: Throwable[] nested, Object failed);
085:
086: public abstract RuntimeException newRuntimeException(String msg,
087: Throwable nested, Object failed);
088:
089: public abstract RuntimeException newRuntimeException(
090: Throwable nested);
091:
092: /**
093: * Retrieve the runtime user exception class dedicated to the relevant
094: * personality.
095: *
096: * @return The class of the user exception to be thrown.
097: */
098: public abstract Class getRuntimeExceptionClass();
099:
100: /**
101: * Retrieve the class name of the runtime user exception dedicated to the
102: * relevant personality.
103: *
104: * @return The class of the user exception to be thrown.
105: */
106: public String getRuntimeExceptionClassNameDot() {
107: if (classNameDot == null) {
108: classNameDot = getRuntimeExceptionClass().getName();
109: }
110: return classNameDot;
111: }
112:
113: /**
114: * Retrieve the class name of the runtime user exception dedicated to the
115: * relevant personality.
116: *
117: * @return The class of the user exception to be thrown.
118: */
119: public String getRuntimeExceptionClassNameSlash() {
120: if (classNameSlash == null) {
121: classNameSlash = getRuntimeExceptionClass().getName()
122: .replace('.', '/');
123: }
124: return classNameSlash;
125: }
126:
127: /**
128: * Retrieve the runtime user exception dedicated to the relevant personality.
129: *
130: * @return The class of the user exception to be thrown.
131: */
132: public abstract RuntimeException newUserRuntimeException();
133:
134: public abstract RuntimeException newUserRuntimeException(String msg);
135:
136: public abstract RuntimeException newUserRuntimeException(
137: String msg, Throwable[] nested);
138:
139: public abstract RuntimeException newUserRuntimeException(
140: String msg, Throwable nested);
141:
142: public abstract RuntimeException newUserRuntimeException(
143: String msg, Object failed);
144:
145: public abstract RuntimeException newUserRuntimeException(
146: String msg, Throwable[] nested, Object failed);
147:
148: public abstract RuntimeException newUserRuntimeException(
149: String msg, Throwable nested, Object failed);
150:
151: public abstract RuntimeException newUserRuntimeException(
152: Throwable nested);
153:
154: /**
155: * Retrieve the runtime user exception class dedicated to the relevant
156: * personality.
157: *
158: * @return The class of the user exception to be thrown.
159: */
160: public abstract Class getUserRuntimeExceptionClass();
161:
162: /**
163: * Retrieve the class name of the runtime user exception dedicated to the
164: * relevant personality.
165: *
166: * @return The class of the user exception to be thrown.
167: */
168: public String getUserRuntimeExceptionClassNameDot() {
169: if (classNameUserDot == null) {
170: classNameUserDot = getUserRuntimeExceptionClass().getName();
171: }
172: return classNameUserDot;
173: }
174:
175: /**
176: * Retrieve the class name of the runtime user exception dedicated to the
177: * relevant personality.
178: *
179: * @return The class of the user exception to be thrown.
180: */
181: public String getUserRuntimeExceptionClassNameSlash() {
182: if (classNameUserSlash == null) {
183: classNameUserSlash = getUserRuntimeExceptionClass()
184: .getName().replace('.', '/');
185: }
186: return classNameUserSlash;
187: }
188:
189: /**
190: * Retrieve the runtime fatal exception dedicated to the relevant personality.
191: *
192: * @return The class of the user exception to be thrown.
193: */
194: public abstract RuntimeException newFatalRuntimeException();
195:
196: public abstract RuntimeException newFatalRuntimeException(String msg);
197:
198: public abstract RuntimeException newFatalRuntimeException(
199: String msg, Throwable[] nested);
200:
201: public abstract RuntimeException newFatalRuntimeException(
202: String msg, Throwable nested);
203:
204: public abstract RuntimeException newFatalRuntimeException(
205: String msg, Object failed);
206:
207: public abstract RuntimeException newFatalRuntimeException(
208: String msg, Throwable[] nested, Object failed);
209:
210: public abstract RuntimeException newFatalRuntimeException(
211: String msg, Throwable nested, Object failed);
212:
213: public abstract RuntimeException newFatalRuntimeException(
214: Throwable nested);
215:
216: /**
217: * Retrieve the runtime fatal exception class dedicated to the relevant
218: * personality.
219: *
220: * @return The class of the user exception to be thrown.
221: */
222: public abstract Class getFatalRuntimeExceptionClass();
223:
224: /**
225: * Retrieve the class name of the runtime fatal exception dedicated to the
226: * relevant personality.
227: *
228: * @return The class of the user exception to be thrown.
229: */
230: public String getFatalRuntimeExceptionClassNameDot() {
231: if (classNameFatalDot == null) {
232: classNameFatalDot = getFatalRuntimeExceptionClass()
233: .getName();
234: }
235: return classNameFatalDot;
236: }
237:
238: /**
239: * Retrieve the class name of the runtime fatal exception dedicated to the
240: * relevant personality.
241: *
242: * @return The class of the user exception to be thrown.
243: */
244: public String getFatalRuntimeExceptionClassNameSlash() {
245: if (classNameFatalSlash == null) {
246: classNameFatalSlash = getFatalRuntimeExceptionClass()
247: .getName().replace('.', '/');
248: }
249: return classNameFatalSlash;
250: }
251:
252: public abstract RuntimeException newFatalDataStoreRuntimeException();
253:
254: public abstract RuntimeException newFatalDataStoreRuntimeException(
255: String msg);
256:
257: public abstract RuntimeException newFatalDataStoreRuntimeException(
258: String msg, Throwable[] nested);
259:
260: public abstract RuntimeException newFatalDataStoreRuntimeException(
261: String msg, Throwable nested);
262:
263: public abstract RuntimeException newFatalDataStoreRuntimeException(
264: String msg, Object failed);
265:
266: public abstract RuntimeException newFatalDataStoreRuntimeException(
267: String msg, Throwable[] nested, Object failed);
268:
269: public abstract RuntimeException newFatalDataStoreRuntimeException(
270: String msg, Throwable nested, Object failed);
271:
272: public abstract RuntimeException newFatalDataStoreRuntimeException(
273: Throwable nested);
274:
275: public abstract RuntimeException newDataStoreRuntimeException(
276: String msg);
277:
278: public abstract RuntimeException newDataStoreRuntimeException(
279: String msg, Throwable nested);
280:
281: public abstract Class getDetachedFieldAccessRuntimeExceptionClass();
282:
283: public String getDetachedFieldAccessExceptionClassNameSlash() {
284: if (classNameDetachSlash == null) {
285: classNameDetachSlash = getDetachedFieldAccessRuntimeExceptionClass()
286: .getName().replace('.', '/');
287: }
288: return classNameDetachSlash;
289: }
290:
291: private void init(String n) {
292: this .name = n;
293: String nu = "";
294: for (int i = 0; i < name.length(); i++) {
295: nu += Character.toUpperCase(name.charAt(i));
296: }
297: nameUpper = nu;
298: }
299:
300: public String getName() {
301: return name;
302: }
303:
304: public String getPersonalityClassName(String pac, String classuffix) {
305: return pac + "." + name + "." + nameUpper + classuffix;
306: }
307:
308: public String getGenClassName(String gcBaseName) {
309: StringBuffer sb = new StringBuffer(gcBaseName);
310: if (gcBaseName.endsWith(".class")) {
311: // ".class" string
312: final int l = sb.length();
313: sb.delete(l - 6, l);
314: }
315: char sep = File.separatorChar;
316: int idx = sb.lastIndexOf("" + sep);
317: if (idx == -1) {
318: sep = '.';
319: idx = sb.lastIndexOf("" + sep);
320: if (idx == -1) {
321: throw new IllegalArgumentException(
322: "unmanaged gcBaseName: " + gcBaseName);
323: }
324: }
325: // the sub package 'xxx' and the class prefix "XXX"
326: sb.insert(idx + 1, name + sep + name.toUpperCase());
327: if (sep != File.separatorChar) {
328: return StringReplace.replaceChar(File.separatorChar, sep,
329: sb.toString());
330: } else {
331: return sb.toString();
332: }
333: }
334:
335: /**
336: * Retrieve the PersistentObjectManager class for the associated
337: * personality.
338: * @return The Java class.
339: */
340: public abstract Class getPOMClass();
341:
342: /**
343: * Retrieve the PersistentObjectManagerFactory class for the associated
344: * personality.
345: * @return The Java class.
346: */
347: public abstract Class getPOMFClass();
348: }
|