001: /**
002: * Copyright (C) 2001-2004 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.mapper.lib;
018:
019: import org.objectweb.jorm.api.PMapper;
020: import org.objectweb.jorm.api.PClassMapping;
021: import org.objectweb.jorm.api.PException;
022: import org.objectweb.jorm.api.PMappingStructuresManager;
023: import org.objectweb.jorm.api.PMapperListener;
024: import org.objectweb.jorm.api.PMapCluster;
025: import org.objectweb.jorm.metainfo.api.Manager;
026: import org.objectweb.jorm.type.api.PTypeSpace;
027: import org.objectweb.jorm.util.io.api.PathExplorer;
028: import org.objectweb.speedo.lib.Personality;
029: import org.objectweb.speedo.mapper.api.JormFactory;
030: import org.objectweb.speedo.api.ExceptionHelper;
031: import org.objectweb.util.monolog.api.Logger;
032: import org.objectweb.medor.eval.prefetch.api.PrefetchCache;
033:
034: import java.util.ArrayList;
035: import java.util.Collection;
036:
037: /**
038: * This class is an implementation of the PMapper interface delegating all
039: * method to another PMapper, except for the lookup method. In this case the
040: * lookup method is done by the use of the JormFactory. The aim is to always
041: * have the PClassMapping instance. But only the JormFactory is able to build
042: * the PClassMapping instance of a Persistent class.
043: *
044: * @author S.Chassande-Barrioz
045: */
046: public class DelegatePMapper implements PMapper {
047:
048: private JormFactory jf;
049: private PMapper mapper;
050: private Personality personality;
051: private ClassLoader classLoader;
052:
053: public DelegatePMapper(PMapper mapper, Personality p) {
054: this .mapper = mapper;
055: personality = p;
056: }
057:
058: public JormFactory getJormFactory() {
059: return jf;
060: }
061:
062: public void setJormFactory(JormFactory jf) {
063: this .jf = jf;
064: }
065:
066: public PMapper getMapper() {
067: return mapper;
068: }
069:
070: public void setMapper(PMapper mapper) {
071: this .mapper = mapper;
072: }
073:
074: public ClassLoader getClassLoader() {
075: return classLoader;
076: }
077:
078: public void setClassLoader(ClassLoader classLoader) {
079: this .classLoader = classLoader;
080: }
081:
082: // IMPLEMENTATION OF THE PMapper INTERFACE //
083:
084: public PClassMapping lookup(String s) {
085: try {
086: return jf.getPClassMapping(s, classLoader);
087: } catch (PException e) {
088: throw personality.newRuntimeException(
089: "Impossible to initialize the persistent class '"
090: + s + "': ", ExceptionHelper.getNested(e));
091: }
092: }
093:
094: public void setPMapper(PMapper pm) {
095: mapper.setPMapper(pm);
096: }
097:
098: public void setLogger(Logger l) {
099: mapper.setLogger(l);
100: }
101:
102: public void setDTDLocations(ArrayList dtdlocs) {
103: mapper.setDTDLocations(dtdlocs);
104: }
105:
106: public void setPathsToPdFiles(PathExplorer paths) {
107: mapper.setPathsToPdFiles(paths);
108: }
109:
110: public void setPrefetchCache(PrefetchCache prefetchCache)
111: throws PException {
112: mapper.setPrefetchCache(prefetchCache);
113: }
114:
115: public PrefetchCache getPrefetchCache() {
116: return mapper.getPrefetchCache();
117: }
118:
119: public void closeConnection(Object o) throws PException {
120: mapper.closeConnection(o);
121: }
122:
123: public String cn2mn(String s) {
124: return mapper.cn2mn(s);
125: }
126:
127: public Object getConnection() throws PException {
128: return mapper.getConnection();
129: }
130:
131: public Object getConnection(Object o) throws PException {
132: return mapper.getConnection(o);
133: }
134:
135: public Object getConnection(Object connectionContext, Object user)
136: throws PException {
137: return mapper.getConnection(connectionContext, user);
138: }
139:
140: public String getMapperName() {
141: return mapper.getMapperName();
142: }
143:
144: public PMappingStructuresManager getPMappingStructuresManager() {
145: return mapper.getPMappingStructuresManager();
146: }
147:
148: public void map(PClassMapping pClassMapping) throws PException {
149: mapper.map(pClassMapping);
150: }
151:
152: public void map(Object o, PClassMapping pClassMapping)
153: throws PException {
154: mapper.map(o, pClassMapping);
155: }
156:
157: public void map(Object o, PClassMapping pClassMapping, boolean b)
158: throws PException {
159: mapper.map(o, pClassMapping, b);
160: }
161:
162: public void setConnectionFactory(Object o) throws PException {
163: mapper.setConnectionFactory(o);
164: }
165:
166: public Object getConnectionFactory() {
167: return mapper.getConnectionFactory();
168: }
169:
170: public void setMapperName(String s) {
171: mapper.setMapperName(s);
172: }
173:
174: public Manager getMetaInfoManager() {
175: return mapper.getMetaInfoManager();
176: }
177:
178: public PTypeSpace getPTypeSpace() {
179: return mapper.getPTypeSpace();
180: }
181:
182: public void start() throws PException {
183: mapper.start();
184: }
185:
186: public void stop() throws PException {
187: mapper.stop();
188: }
189:
190: public void unmap(String s) throws PException {
191: mapper.unmap(s);
192: }
193:
194: public void clean() throws PException {
195: mapper.clean();
196: }
197:
198: public void addMapperEventListener(PMapperListener pMapperListener) {
199: mapper.addMapperEventListener(pMapperListener);
200: }
201:
202: public void removeMapperEventListener(
203: PMapperListener pMapperListener) {
204: mapper.removeMapperEventListener(pMapperListener);
205: }
206:
207: public PClassMapping createGenClassMapping() throws PException {
208: return mapper.createGenClassMapping();
209: }
210:
211: public PMapCluster getPMapCluster(String s) throws PException {
212: return mapper.getPMapCluster(s);
213: }
214:
215: public Collection getPMapClusters() {
216: return mapper.getPMapClusters();
217: }
218:
219: public void addDependency(String s, String s1) throws PException {
220: mapper.addDependency(s, s1);
221: }
222:
223: public void classDefined(String s) throws PException {
224: mapper.classDefined(s);
225: }
226:
227: public void declareClass(String jcname) {
228: mapper.declareClass(jcname);
229: }
230:
231: public String[] getMappedClasses() {
232: return mapper.getMappedClasses();
233: }
234:
235: public void clear() throws PException {
236: mapper.clear();
237: }
238: }
|