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.metadata.ejb;
018:
019: import java.util.ArrayList;
020: import java.util.HashMap;
021:
022: import org.objectweb.speedo.api.SpeedoException;
023: import org.objectweb.speedo.api.SpeedoRuntimeException;
024: import org.objectweb.speedo.lib.Personality;
025: import org.objectweb.speedo.metadata.SpeedoCallback;
026: import org.objectweb.speedo.metadata.SpeedoClass;
027: import org.objectweb.speedo.metadata.SpeedoCollection;
028: import org.objectweb.speedo.metadata.SpeedoColumn;
029: import org.objectweb.speedo.metadata.SpeedoDefaults;
030: import org.objectweb.speedo.metadata.SpeedoDiscriminator;
031: import org.objectweb.speedo.metadata.SpeedoElement;
032: import org.objectweb.speedo.metadata.SpeedoField;
033: import org.objectweb.speedo.metadata.SpeedoIdentity;
034: import org.objectweb.speedo.metadata.SpeedoInheritance;
035: import org.objectweb.speedo.metadata.SpeedoInheritedField;
036: import org.objectweb.speedo.metadata.SpeedoJoin;
037: import org.objectweb.speedo.metadata.SpeedoJoinColumn;
038: import org.objectweb.speedo.metadata.SpeedoMap;
039: import org.objectweb.speedo.metadata.SpeedoNoFieldColumn;
040: import org.objectweb.speedo.metadata.SpeedoNullValue;
041: import org.objectweb.speedo.metadata.SpeedoPackage;
042: import org.objectweb.speedo.metadata.SpeedoTable;
043:
044: /**
045: * This class is in charge of the initialization of Speedo Meta Objects with
046: * the default value corresponding to the EJB personality.
047: *
048: * @author S.Chassande-Barrioz, P. Dechamboux
049: */
050: public class EJBDefaults extends SpeedoDefaults {
051: final static String UNKNOWN = "unknown";
052:
053: public void assignDefaults(Object se) throws SpeedoRuntimeException {
054: ((SpeedoElement) se).personality = Personality.EJB;
055: if (se instanceof SpeedoPackage) {
056: SpeedoPackage sp = (SpeedoPackage) se;
057: //sp.classes = ?;
058: //sp.jdoExtension = ?;
059: sp.name = UNKNOWN;
060: //sp.sequences = ?;
061: sp.xmlDescriptor = null;
062: } else if (se instanceof SpeedoClass) {
063: SpeedoClass sc = (SpeedoClass) se;
064: //sc.enhancementStatus = ?;
065: sc.fetchGroups = new HashMap();
066: sc.fields = new HashMap();
067: sc.identity = null;
068: sc.versionField = null;
069: sc.inheritance = null;
070: sc.isAbstract = false;
071: sc.isDetachable = false;
072: sc.isInstanceCallbacks = false;
073: sc.isSerializable = false;
074: //sc.jdoExtension = ?;
075: //sc.joinToExtTables = ?;
076: //sc.jormclass = ?;
077: sc.callBacks = new HashMap();
078: //sc.mainTable = ?;
079: //sc.moPackage = ?;
080: sc.name = UNKNOWN;
081: sc.name2query = new HashMap();
082: //sc.noArgConstructorStatus = ?;
083: //sc.version = ?;
084: } else if (se instanceof SpeedoField) {
085: SpeedoField sf = (SpeedoField) se;
086: sf.name = null;
087: //sf.visibility = ?;
088: sf.propagate = SpeedoField.PROPAG_NONE;
089: sf.type = null;
090: sf.number = -1;
091: sf.persistenceStatus = SpeedoField.UNKNOWN;
092: sf.primaryKey = false;
093: sf.nullValue = SpeedoNullValue.NONE;
094: sf.defaultFetchGroup = true;
095: sf.depth = 0;
096: //sf.fetchGroup = ?;
097: sf.embedded = true;
098: //sf.valueStrategy = ?;
099: //sf.sequence = ?;
100: sf.relationType = SpeedoField.NO_BI_RELATION;
101: sf.reverseField = null;
102: sf.isCoherentReverseField = false;
103: sf.jdoTuple = null;
104: sf.moClass = null;
105: sf.columns = null;
106: sf.join = null;
107: sf.mappedByReversefield = false;
108: } else if (se instanceof SpeedoTable) {
109: SpeedoTable st = (SpeedoTable) se;
110: st.catalog = null;
111: st.name = null;
112: st.schema = null;
113: st.join = null;
114: } else if (se instanceof SpeedoJoin) {
115: SpeedoJoin sj = (SpeedoJoin) se;
116: sj.extTable = null;
117: sj.mainTable = null;
118: sj.columns = new ArrayList();
119: sj.deleteAction = SpeedoJoin.ACTION_NONE;
120: } else if (se instanceof SpeedoColumn) {
121: SpeedoColumn sc = (SpeedoColumn) se;
122: sc.allowNull = true;
123: //sc.defaultValue = ?;
124: //sc.jdbcType = ?;
125: sc.length = 255;
126: sc.name = null;
127: sc.targetColumn = null;
128: sc.targetField = null;
129: sc.scale = 0;
130: //sc.sqlType = ?;
131: sc.table = null;
132: sc.insertable = true;
133: sc.updatable = true;
134: } else if (se instanceof SpeedoIdentity) {
135: SpeedoIdentity si = (SpeedoIdentity) se;
136: si.objectidClass = null;
137: si.objectidJClass = null;
138: si.sequenceName = null;
139: si.strategy = SpeedoIdentity.NO_ID;
140: si.columns = null;
141: } else if (se instanceof SpeedoJoinColumn) {
142: SpeedoJoinColumn sjc = (SpeedoJoinColumn) se;
143: sjc.column = null;
144: sjc.targetColumn = null;
145: sjc.targetField = null;
146: } else if (se instanceof SpeedoInheritance) {
147: SpeedoInheritance si = (SpeedoInheritance) se;
148: si.clazz = null;
149: //si.discriminator = ;
150: si.discriminatorValues = null;
151: si.join = null;
152: si.remappedInheritedFields = null;
153: si.strategy = SpeedoInheritance.STRATEGY_UNKOWN;
154: si.super ClassName = "";//TODO: null should be better
155: } else if (se instanceof SpeedoDiscriminator) {
156: SpeedoDiscriminator sd = (SpeedoDiscriminator) se;
157: sd.elements = new ArrayList();
158: sd.strategy = SpeedoDiscriminator.STRATEGY_NONE;
159: } else if (se instanceof SpeedoNoFieldColumn) {
160: SpeedoNoFieldColumn sc = (SpeedoNoFieldColumn) se;
161: // In EJB3, type may be one of {"Ljava.lang.String;", "", ""}.
162: //sc.type = ;
163: //sc.column = ;
164: } else if (se instanceof SpeedoInheritedField) {
165: SpeedoInheritedField shf = (SpeedoInheritedField) se;
166: shf.name = null;
167: shf.columns = null;
168: shf.inheritedField = null;
169: shf.join = null;
170: shf.moClass = null;
171: } else if (se instanceof SpeedoCollection) {
172: SpeedoCollection sc = (SpeedoCollection) se;
173: sc.elementType = null;
174: sc.embeddedElement = false;
175: sc.indexColumns = null;
176: sc.moField = null;
177: } else if (se instanceof SpeedoMap) {
178: SpeedoMap sm = (SpeedoMap) se;
179: sm.embeddedKey = false;
180: sm.embeddedValue = false;
181: sm.keyColumns = null;
182: sm.keyType = null;
183: sm.moField = null;
184: } else if (se instanceof SpeedoCallback) {
185: SpeedoCallback sc = (SpeedoCallback) se;
186: sc.listenerClassName = null;
187: sc.callbackName = null;
188: sc.methodByteCodeSignature = null;
189: sc.callbackType = -1;
190: } else {
191: throw new SpeedoRuntimeException(
192: "Unknown meta-info element to initialize: "
193: + se.getClass().getName());
194: }
195: }
196: }
|