KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jorm > genclass > lib > GenClassMapping


1 /**
2  * JORM: an implementation of a generic mapping system for persistent Java
3  * objects. Two mapping are supported: to RDBMS and to binary files.
4  * Copyright (C) 2001-2003 France Telecom R&D - INRIA
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * Contact: jorm-team@objectweb.org
21  *
22  */

23
24 package org.objectweb.jorm.genclass.lib;
25
26 import org.objectweb.jorm.api.PAccessor;
27 import org.objectweb.jorm.api.PBinding;
28 import org.objectweb.jorm.api.PClassMapping;
29 import org.objectweb.jorm.api.PMapper;
30 import org.objectweb.jorm.api.PMappingCallback;
31 import org.objectweb.jorm.api.PException;
32 import org.objectweb.jorm.api.PClassMappingCtrl;
33 import org.objectweb.jorm.api.PNameIterator;
34 import org.objectweb.jorm.metainfo.api.GenClass;
35 import org.objectweb.jorm.metainfo.api.MetaObject;
36 import org.objectweb.jorm.naming.api.PBinder;
37 import org.objectweb.jorm.naming.api.PNameCoder;
38 import org.objectweb.jorm.genclass.api.FieldDesc;
39 import org.objectweb.jorm.genclass.api.GenClassProp;
40 import org.objectweb.jorm.type.api.PExceptionTyping;
41 import org.objectweb.jorm.type.api.PType;
42 import org.objectweb.jorm.util.api.Loggable;
43 import org.objectweb.util.monolog.api.Logger;
44 import org.objectweb.util.monolog.api.LoggerFactory;
45
46 import java.util.Iterator JavaDoc;
47 import java.util.Collections JavaDoc;
48
49 /**
50  * This abstract class provides all the generic code for the PClassMapping
51  * associated with JORM generic classes. It implements all methods except the
52  * following ones: createPBinding, and isConform.
53  * @author P. Dechamboux
54  */

55 public abstract class GenClassMapping
56         implements PClassMapping, PClassMappingCtrl, GenClassProp, Loggable {
57     /**
58      * This field references the mapper. The mapper is used to know the mapper
59      * name and the mapping name.
60      */

61     protected PMappingCallback mapper = null;
62
63     /**
64      * It references the meta-information associated with this generic class.
65      */

66     protected GenClass genClassMetaInfo = null;
67
68     /**
69      * This field is the PType of the involved generic class.
70      */

71     protected PType genClassPType = null;
72
73     /** Fully quailied name of the persitent class */
74     protected String JavaDoc jormClassName = "";
75
76     /**
77      * This array contains the ScalarField meta object elements which
78      * represent the index fields of the generic class instance.
79      */

80     protected FieldDesc[] indexFields = null;
81
82     /**
83      * This array contains the ScalarField meta object elements which
84      * represent the identifier fields of the generic class instance.
85      */

86     protected FieldDesc[] identifierFields = null;
87
88     /**
89      * This array contains the ScalarField meta object elements which
90      * represent the element fields of the generic class instance. If it is
91      * a reference, there must be at least two fields: one describing the
92      * reference field, and one describing its structural projection. This
93      * structural projection may be a composite name in which case it should
94      * describes all the fields of this composite name.
95      */

96     protected FieldDesc[] elemFields = null;
97
98     /**
99      * The actual PBinder.
100      */

101     protected PBinder binder = null;
102
103     protected PNameCoder classPNC;
104
105     /**
106      * The PClassMapping of the generic class instance representing the element
107      * stored within this generic class object. This is valid only if the
108      * elements of this generic class object are also generic class objects.
109      */

110     protected PClassMapping elemClassMapping = null;
111
112     /**
113      * The naming context associated to the reference elements of this generic
114      * class instance.
115      */

116     protected PNameCoder elemNameCoder = null;
117
118     protected String JavaDoc projectName = null;
119
120     /**
121      * The logger to log all information related to the mapping of this class.
122      */

123     protected Logger logger = null;
124
125     /**
126      * The loggerFactory.
127      */

128     protected LoggerFactory loggerFactory = null;
129
130
131     public FieldDesc[] getElemFields() {
132         return elemFields;
133     }
134
135     public FieldDesc[] getIdentifierFields() {
136         return identifierFields;
137     }
138
139     public FieldDesc[] getIndexFields() {
140         return indexFields;
141     }
142
143
144     public String JavaDoc getProjectName() {
145         return projectName;
146     }
147
148     public void setProjectName(String JavaDoc projectName) {
149         this.projectName = projectName;
150     }
151
152     /**
153      * It retrieves the name of the class mapped by this PClassMapping. It
154      * should be the same as the one get when calling
155      * "getPType().getJormName()" if the PType exists.
156      */

157     public String JavaDoc getClassName() {
158         return jormClassName;
159     }
160
161     /**
162      * It gives access to the PClassMapping associated to the element of a
163      * generic class whose type is a generic class.
164      * @return The PClassMapping of the generic class instance.
165      */

166     public PClassMapping getGenClassMapping() {
167         return elemClassMapping;
168     }
169
170     /**
171      * It gives access to the PClassMapping associated to a field whose type is
172      * a generic class. It has no meaning within this context.
173      * @param fn The name of the generic class field.
174      * @return The PClassMapping of the generic class instance: always null
175      * here.
176      */

177     public PClassMapping getGenClassMapping(String JavaDoc fn) {
178         return null;
179     }
180
181     /**
182      * It returns the Class/GenClass object representing the meta-information
183      * associated to the JORM class/generic class whose mapping is defined by
184      * this PClassMapping. It may be null if not requested at mapping time.
185      * @return The Class/GenClass meta-object or null.
186      * @see org.objectweb.jorm.api.PMapper#map
187      */

188     public MetaObject getMetaInfo() {
189         return genClassMetaInfo;
190     }
191
192     /**
193      * It yields the PBinder associated to this PClassMapping. As a PBinder
194      * itself, this PClassMapping delegates this behaviour to this PBinder.
195      * @return The PBinder associated to this PClassMapping.
196      */

197     public PBinder getPBinder() {
198         return binder;
199     }
200
201     public PNameCoder getClassPNameCoder() {
202         return classPNC;
203     }
204
205     /**
206      * It gives access to the mapper that has mapped the associated JORM class
207      * as defined by this PClassMapping.
208      * @return The associated PMapper.
209      */

210     public PMapper getPMapper() {
211         return mapper;
212     }
213
214     /**
215      * It returns the naming context that manages the references contained by
216      * the generic class instance whose mapping is defined by this
217      * PClassMapping.
218      * @return The naming context that manages references contained by a
219      * generic class instance.
220      * @exception UnsupportedOperationException It is raised when this
221      * PClassMapping does not map
222      * a generic class instance, or
223      * when the elements of this
224      * generic class instance are
225      * not references.
226      */

227     public PNameCoder getPNameCoder()
228             throws UnsupportedOperationException JavaDoc {
229         return elemNameCoder;
230     }
231
232     /**
233      * It returns the naming context that manages the reference associated to
234      * a field whose type is a JORM class.
235      * @return The naming context that manages the reference defined by a
236      * field.
237      * @exception UnsupportedOperationException It is raised when no naming
238      * context is associated to
239      * the corresponding field.
240      */

241     public PNameCoder getPNameCoder(String JavaDoc fn)
242             throws UnsupportedOperationException JavaDoc {
243         throw new UnsupportedOperationException JavaDoc();
244     }
245
246     /**
247      * It intialises the class mapping. It especially assigns a mapper as well
248      * as a meta-object describing either a class or a generic class.
249      * @param mapper The mapper to be assigned to this class mapping.
250      * @param metaclass The meta-object describing the associated class. It may
251      * be null.
252      */

253     public void init(PMappingCallback mapper, MetaObject metaclass) throws PException {
254         this.mapper = mapper;
255         genClassMetaInfo = (GenClass) metaclass;
256     }
257
258     public Iterator getPNameIterator(Object JavaDoc conn) throws PException {
259         return getPNameIterator(conn, false, false, null);
260     }
261
262     /**
263      * It assigns the PBinder associated to this PClassMapping. As a PBinder
264      * itself, this PClassMapping delegates this behaviour to this PBinder.
265      * @param pb The PBinder associated to this PClassMapping.
266      * @exception PExceptionTyping It is raised when the structure of the
267      * the name that identifies the DSI for
268      * the PClassMapping is not supported by
269      * this PBinder that should be connected
270      * to this PClassMapping.
271      */

272     public void setPBinder(PBinder pb) throws PExceptionTyping {
273         binder = pb;
274     }
275
276     public void setClassPNameCoder(PNameCoder pnc) throws PException {
277         this.classPNC = pnc;
278     }
279
280     public void configureRefFields(PClassMapping.ReferenceConfigurator rc)
281             throws PException, UnsupportedOperationException JavaDoc {
282         throw new UnsupportedOperationException JavaDoc();
283     }
284
285     /**
286      * It assigns the PNameCoder used to manage the references hold by a
287      * generic class instance whose mapping is described by this PClassMapping.
288      * It should verify that the name structure for this reference is supported
289      * by the corresponding naming context.
290      * @param pnc The PNameCoder to be associated to this generic class
291      * PClassMapping for managing its reference elements.
292      * @exception PExceptionTyping It is raised when the structure of the
293      * the names that reference the DSI stored
294      * within the generic class instance is not
295      * supported by this naming context.
296      * @exception UnsupportedOperationException It is raised when this
297      * PClassMapping does not map
298      * a generic class instance, or
299      * when the elements of this
300      * generic class instance are
301      * not references.
302      */

303     public void setPNameCoder(PNameCoder pnc)
304             throws PException, UnsupportedOperationException JavaDoc {
305         elemNameCoder = pnc;
306     }
307
308     /**
309      * It assigns the PNameCoder used to manage the reference hold by a
310      * field whose type is a JORM class.
311      * It should verify that the name structure for this reference is supported
312      * by the corresponding naming context.
313      * @param fn The name of the involved field.
314      * @param pnc The PNameCoder to be associated to this field for
315      * managing the reference it may hold.
316      * @exception PExceptionTyping It is raised when the structure of the
317      * the names that reference the DSI stored
318      * within the generic class instance is not
319      * supported by this naming context.
320      * @exception UnsupportedOperationException It is raised when no naming
321      * context is associated to
322      * the corresponding field.
323      */

324     public void setPNameCoder(String JavaDoc fn, PNameCoder pnc)
325             throws PException, UnsupportedOperationException JavaDoc {
326         throw new UnsupportedOperationException JavaDoc();
327     }
328
329     /**
330      * It assigns the GenClassMapping used to manage the reference hold by a
331      * field whose type is a JORM gen class.
332      */

333     public void setGenClassMapping(PClassMapping pcm)
334             throws UnsupportedOperationException JavaDoc {
335         // TODO: verifies with the PType that the elements are gen class
336
// themselves
337
elemClassMapping = pcm;
338     }
339
340     /**
341      * It assigns the GenClassMapping used to manage the reference hold by a
342      * field whose type is a JORM class.
343      */

344     public void setGenClassMapping(String JavaDoc fn, PClassMapping pcm)
345             throws UnsupportedOperationException JavaDoc {
346         throw new UnsupportedOperationException JavaDoc();
347     }
348
349     /**
350      * Retrieves the PType associated to the JORM class which is the type of
351      * the name managed by this naming context.
352      * @return The related PType.
353      */

354     public PType getPType() {
355         return genClassPType;
356     }
357
358     /**
359      * It assigns the PType associated to the JORM class which is the type of
360      * the reference managed by this naming context.
361      * @param pt The PType of the JORM class reference managed by this naming
362      * context.
363      */

364     public void setPType(PType pt) {
365         if (genClassPType == null) {
366             genClassPType = pt;
367             jormClassName += pt.getJormName();
368             binder.setPType(pt);
369             if (pt.getNestedPType() != null) {
370                 if (elemClassMapping != null) {
371                     // element is a genclass
372
elemClassMapping.getPBinder().setPType(pt.getNestedPType());
373                 }
374                 if (pt.getNestedPType().getTypeCode() == PType.TYPECODE_REFERENCE) {
375                     elemNameCoder.setPType(pt.getNestedPType());
376                 }
377             }
378         }
379     }
380     public void read(PBinding pb, Object JavaDoc conn, PAccessor pa, Object JavaDoc txctx) throws PException {
381         read(pb, conn, pa);
382     }
383
384     // IMPLMENTATION OF THE GenClassProp INTERFACE
385

386     /**
387      * Defines the fields property specifying the fields composing the
388      * identifier structure of a generic class instance.
389      * @param fds The array of descriptions of the associated fields.
390      */

391     public void setIdentifierDesc(FieldDesc[] fds) {
392         identifierFields = fds;
393     }
394
395     /**
396      * Defines the fields property specifying the fields composing the
397      * index structure of a generic class instance elements.
398      * @param fds The array of descriptions of the associated fields.
399      */

400     public void setIndexDesc(FieldDesc[] fds) {
401         indexFields = fds;
402     }
403
404     /**
405      * Defines the fields property specifying the fields composing the
406      * element value structure of a generic class instance elements.
407      * @param fds The array of descriptions of the associated fields.
408      */

409     public void setElemDesc(FieldDesc[] fds) {
410         elemFields = fds;
411     }
412
413     /**
414      * It assigns a logger factory that allows the creation of new loggers.
415      * @param lf The LoggerFactory object to obtain new loggers.
416      */

417     public void setLoggerFactory(LoggerFactory lf) {
418         loggerFactory = lf;
419     }
420
421     /**
422      * It assigns a logger to an component that wants to log things.
423      * @param logger The logger object.
424      */

425     public void setLogger(Logger logger) {
426         this.logger = logger;
427     }
428
429     public Logger getLogger() {
430         return logger;
431     }
432
433     public LoggerFactory getLoggerFactory() {
434         return loggerFactory;
435     }
436 }
437
Popular Tags