KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jorm > metainfo > lib > BasicMapping


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.metainfo.lib;
25
26 import org.objectweb.jorm.metainfo.api.ClassMapping;
27 import org.objectweb.jorm.metainfo.api.GenClassMapping;
28 import org.objectweb.jorm.metainfo.api.Mapping;
29 import org.objectweb.jorm.metainfo.api.MetaObject;
30
31 import java.util.ArrayList JavaDoc;
32 import java.util.Collection JavaDoc;
33 import java.util.HashMap JavaDoc;
34 import java.util.Map JavaDoc;
35
36 /**
37  * Implementation of the mapping interface.
38  */

39 public abstract class BasicMapping
40     extends BasicMetaObject
41         implements Mapping {
42     /**
43      * The mapper name.
44      */

45     private String JavaDoc mapperName;
46
47     /**
48      * The persistent structure resulting from the mapping of a class and its primitive
49      * values is described in a ClassMapping object.
50      */

51     private ClassMapping classMapping;
52
53     /**
54      * This HashMap associates a generic class identifier with a GenClassMapping
55      * object.
56      *
57      * Generic class identifiers uniquely identify one or several nested generic
58      * classes accessible from a given class field.
59      *
60      * Example:
61      * class Person {
62      * private set(set(Equipment) equipments;
63      * ...}
64      * The external set is identified by "equipments.set".
65      * The internal set is identified by "equipments.set.set".
66      */

67     private Map JavaDoc genClassMappings;
68
69     /**
70      * Builds a new BasicMapping object.
71      * This object contains the mapping structures of a class.
72      * The parent object is a Project object.
73      * @param mapperName the mapper name,
74      * parent the parent of the current object.
75      */

76     public BasicMapping(String JavaDoc mapperName, MetaObject parent) {
77         super(parent);
78         this.mapperName = mapperName;
79         classMapping = null;
80         genClassMappings = new HashMap JavaDoc();
81     }
82
83     ///////////////////////////////////////////////////////////////////
84
// from Mapping interface
85
///////////////////////////////////////////////////////////////////
86

87     /**
88      * Returns the name of the mapper.
89      * @return the mapper name.
90      */

91     public String JavaDoc getMapperName() {
92         return mapperName;
93     }
94
95     /**
96      * Sets the mapper name.
97      * @param mapperName the mapper name.
98      */

99     public void setMapperName(String JavaDoc mapperName) {
100         this.mapperName = mapperName;
101     }
102
103     /**
104      * Returns the mapping structure of the class.
105      * @return a ClassMapping object.
106      */

107     public ClassMapping getClassMapping() {
108         return classMapping;
109     }
110
111     /**
112      * Sets the mapping structure of the class.
113      * @param classMapping a ClassMapping object.
114      */

115     public void setClassMapping(ClassMapping classMapping) {
116         this.classMapping = classMapping;
117     }
118
119     /**
120      * Returns the GenClassMapping object of a GenClass.
121      * @param genClassId a GenClass identifier.
122      * @return a GenClassMapping object.
123      */

124     public GenClassMapping getGenClassMapping(String JavaDoc genClassId) {
125         return (GenClassMapping) genClassMappings.get(genClassId);
126     }
127
128     /**
129      * Returns a collection of GenClassMapping objects.
130      * @return a collection.
131      */

132     public Collection JavaDoc getGenClassMappings() {
133         return genClassMappings.values();
134     }
135
136     /**
137      * Adds a GenClassMapping object.
138      * @param genClassId a GenClass identifier,
139      * genClassMapping a GenClassMapping object.
140      */

141     public void addGenClassMapping(String JavaDoc genClassId,
142                                    GenClassMapping genClassMapping) {
143         genClassMappings.put(genClassId, genClassMapping);
144     }
145
146     protected Collection JavaDoc getChildren() {
147         ArrayList JavaDoc al = new ArrayList JavaDoc();
148         al.add(classMapping);
149         al.addAll(genClassMappings.values());
150         return al;
151     }
152 }
153
Popular Tags