01: /**
02: * Copyright (C) 2001-2005 France Telecom R&D
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */package org.objectweb.speedo.metadata;
18:
19: import org.objectweb.speedo.api.SpeedoException;
20: import org.objectweb.speedo.api.SpeedoRuntimeException;
21: import org.objectweb.speedo.lib.Personality;
22: import org.objectweb.speedo.metadata.ejb.EJBDefaults;
23: import org.objectweb.speedo.metadata.jdo.JDODefaults;
24:
25: /**
26: * Is an helper class for loading default value of speedo meta objects.
27: *
28: * @author S.Chassande-Barrioz
29: */
30: public abstract class SpeedoDefaults {
31:
32: /**
33: * is the unique instance helping the initialization of speedo meta objects
34: */
35: private static SpeedoDefaults defaults;
36:
37: /**
38: * This abstract method should initiaze a speedo meta Object.
39: * @param se the speedo meta object to initialize.
40: */
41: public abstract void assignDefaults(Object se)
42: throws SpeedoRuntimeException;
43:
44: /**
45: * Initializes the defaults field with regards to the current personality
46: * @param p the current personality
47: */
48: public static void init(Personality p) throws SpeedoException {
49: String className = p.getPersonalityClassName(
50: "org.objectweb.speedo.metadata", "Defaults");
51: try {
52: defaults = (SpeedoDefaults) Class.forName(className)
53: .newInstance();
54: } catch (InstantiationException e) {
55: throw new SpeedoException(
56: "Cannot create object for Speedo defaults with class: "
57: + className, e);
58: } catch (IllegalAccessException e) {
59: throw new SpeedoException(
60: "Cannot create object for Speedo defaults with class: "
61: + className, e);
62: } catch (ClassNotFoundException e) {
63: throw new SpeedoException(
64: "Cannot create object for Speedo defaults with class: "
65: + className, e);
66: }
67: }
68:
69: /**
70: * Set the default value for a Speedo Meta Object.
71: * @param se the meta object to initiaze with default value of the current
72: * personality.
73: */
74: public static void setDefaults(Object se)
75: throws SpeedoRuntimeException {
76: defaults.assignDefaults(se);
77: }
78: }
|