KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > mapper > lib > DelegatePMapper


1 /**
2  * Copyright (C) 2001-2004 France Telecom R&D
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * 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  */

18 package org.objectweb.speedo.mapper.lib;
19
20 import org.objectweb.jorm.api.PMapper;
21 import org.objectweb.jorm.api.PClassMapping;
22 import org.objectweb.jorm.api.PException;
23 import org.objectweb.jorm.api.PMappingStructuresManager;
24 import org.objectweb.jorm.api.PMapperListener;
25 import org.objectweb.jorm.api.PMapCluster;
26 import org.objectweb.jorm.metainfo.api.Manager;
27 import org.objectweb.jorm.type.api.PTypeSpace;
28 import org.objectweb.speedo.mapper.api.JormFactory;
29 import org.objectweb.speedo.api.ExceptionHelper;
30 import org.objectweb.util.monolog.api.Logger;
31 import org.objectweb.medor.eval.prefetch.api.PrefetchCache;
32
33 import javax.jdo.JDOException;
34 import java.util.Collection JavaDoc;
35
36 /**
37  * This class is an implementation of the PMapper interface delegating all
38  * method to another PMapper, except for the lookup method. In this case the
39  * lookup method is done by the use of the JormFactory. The aim is to always
40  * have the PClassMapping instance. But only the JormFactory is able to build
41  * the PClassMapping instance of a Persistent class.
42  *
43  * @author S.Chassande-Barrioz
44  */

45 public class DelegatePMapper implements PMapper {
46
47     private JormFactory jf;
48     private PMapper mapper;
49     private ClassLoader JavaDoc classLoader;
50
51     public DelegatePMapper(PMapper mapper) {
52         this.mapper = mapper;
53     }
54
55     public JormFactory getJormFactory() {
56         return jf;
57     }
58
59     public void setJormFactory(JormFactory jf) {
60         this.jf = jf;
61     }
62
63     public PMapper getMapper() {
64         return mapper;
65     }
66
67     public void setMapper(PMapper mapper) {
68         this.mapper = mapper;
69     }
70
71     public ClassLoader JavaDoc getClassLoader() {
72         return classLoader;
73     }
74
75     public void setClassLoader(ClassLoader JavaDoc classLoader) {
76         this.classLoader = classLoader;
77     }
78     // IMPLEMENTATION OF THE PMapper INTERFACE //
79

80     public PClassMapping lookup(String JavaDoc s) {
81         try {
82             return jf.getPClassMapping(s, classLoader);
83         } catch (PException e) {
84             throw new JDOException(
85                     "Impossible to initialize the persistent class '" + s
86                     + "': ", ExceptionHelper.getNested(e));
87         }
88     }
89
90     public void setPMapper(PMapper pm) {
91         mapper.setPMapper(pm);
92     }
93
94     public void setLogger(Logger l) {
95         mapper.setLogger(l);
96     }
97
98     public void setPrefetchCache(PrefetchCache prefetchCache) throws PException {
99         mapper.setPrefetchCache(prefetchCache);
100     }
101     public PrefetchCache getPrefetchCache() {
102         return mapper.getPrefetchCache();
103     }
104     public void closeConnection(Object JavaDoc o) throws PException {
105         mapper.closeConnection(o);
106     }
107     public String JavaDoc cn2mn(String JavaDoc s) {
108         return mapper.cn2mn(s);
109     }
110     public Object JavaDoc getConnection() throws PException {
111         return mapper.getConnection();
112     }
113     public Object JavaDoc getConnection(Object JavaDoc o) throws PException {
114         return mapper.getConnection(o);
115     }
116     public Object JavaDoc getConnection(Object JavaDoc connectionContext, Object JavaDoc user) throws PException {
117         return mapper.getConnection(connectionContext, user);
118     }
119     public String JavaDoc getMapperName() {
120         return mapper.getMapperName();
121     }
122     public PMappingStructuresManager getPMappingStructuresManager() {
123         return mapper.getPMappingStructuresManager();
124     }
125     public void map(PClassMapping pClassMapping) throws PException {
126         mapper.map(pClassMapping);
127     }
128     public void map(Object JavaDoc o, PClassMapping pClassMapping) throws PException {
129         mapper.map(o, pClassMapping);
130     }
131     public void map(Object JavaDoc o, PClassMapping pClassMapping, boolean b) throws PException {
132         mapper.map(o, pClassMapping, b);
133     }
134     public void setConnectionFactory(Object JavaDoc o) throws PException {
135         mapper.setConnectionFactory(o);
136     }
137     public Object JavaDoc getConnectionFactory() {
138         return mapper.getConnectionFactory();
139     }
140     public void setMapperName(String JavaDoc s) {
141         mapper.setMapperName(s);
142     }
143     public Manager getMetaInfoManager() {
144         return mapper.getMetaInfoManager();
145     }
146     public PTypeSpace getPTypeSpace() {
147         return mapper.getPTypeSpace();
148     }
149     public void start() throws PException {
150         mapper.start();
151     }
152     public void stop() throws PException {
153         mapper.stop();
154     }
155     public void unmap(String JavaDoc s) throws PException {
156         mapper.unmap(s);
157     }
158     public void addMapperEventListener(PMapperListener pMapperListener) {
159         mapper.addMapperEventListener(pMapperListener);
160     }
161     public void removeMapperEventListener(PMapperListener pMapperListener) {
162         mapper.removeMapperEventListener(pMapperListener);
163     }
164     public PClassMapping createGenClassMapping() throws PException {
165         return mapper.createGenClassMapping();
166     }
167     public PMapCluster getPMapCluster(String JavaDoc s) throws PException {
168         return mapper.getPMapCluster(s);
169     }
170     public Collection JavaDoc getPMapClusters() {
171         return mapper.getPMapClusters();
172     }
173     public void addDependency(String JavaDoc s, String JavaDoc s1) throws PException {
174         mapper.addDependency(s, s1);
175     }
176     public void classDefined(String JavaDoc s) throws PException {
177         mapper.classDefined(s);
178     }
179     public void declareClass(String JavaDoc jcname) {
180         mapper.declareClass(jcname);
181     }
182     public String JavaDoc[] getMappedClasses() {
183         return mapper.getMappedClasses();
184     }
185 }
186
187
Popular Tags