KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > medor > query > jorm > lib > GenClassExtent


1 /**
2  * MEDOR: Middleware Enabling Distributed Object Requests
3  *
4  * Copyright (C) 2001-2003 France Telecom R&D
5  * Contact: alexandre.lefebvre@rd.francetelecom.com
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  *
21  * Initial developers: M. Alia, A. Lefebvre
22  */

23
24 package org.objectweb.medor.query.jorm.lib;
25
26 import org.objectweb.jorm.metainfo.api.GenClassRef;
27 import org.objectweb.jorm.metainfo.api.TypedElement;
28 import org.objectweb.jorm.metainfo.api.MetaObject;
29 import org.objectweb.medor.api.Field;
30 import org.objectweb.medor.api.MedorException;
31
32 import java.util.Iterator JavaDoc;
33 import java.util.Map JavaDoc;
34
35 /**
36  * This class represents the extent of a JORM GenClass.
37  * It contains and implements its associated TupleStructure.
38  */

39 public class GenClassExtent extends BasicJormExtent {
40
41     private GenClassRef gcr;
42
43     private String JavaDoc elementFieldName;
44
45     public GenClassExtent() {
46     }
47
48     public GenClassExtent(String JavaDoc _name, String JavaDoc pnFieldName) {
49         super(_name, pnFieldName);
50     }
51
52     /**
53      * Constructs an extent for the JORM GenClass, in the form of a QueryLeaf.
54      * @param gcr is the JORM GenClass meta information object
55      * @param _name is the name of the node (null value => empty string)
56      * @param pnameFieldName is the name of the field representing the PName
57      * of the GenClass id.
58      */

59     public GenClassExtent(GenClassRef gcr,
60                           String JavaDoc _name,
61                           String JavaDoc pnameFieldName,
62                           String JavaDoc elemName) throws MedorException {
63         super(_name, pnameFieldName);
64         this.gcr = gcr;
65
66         //Add the Genclass PName
67
identifier = new PNameField(getFieldName(name, pnFieldName), gcr, true, this);
68         fields.add(identifier);
69         name2field.put(identifier.getName(), identifier);
70
71         // Add the element
72
Field f = null;
73         elementFieldName = getFieldName(name, elemName);
74         if (gcr.isClassRef()) {
75             f = new PNameField(elementFieldName, gcr.getClassRef(), this);
76         } else if (gcr.isGenClassRef()) {
77             f = new PNameField(elementFieldName, gcr.getGenClassRef(), false, this);
78         } else if (gcr.isPrimitive()) {
79             f = new BasicJormField(elementFieldName, this, gcr.getPrimitiveElement());
80         }
81         fields.add(f);
82         name2field.put(f.getName(), f);
83
84         // Add the indexes
85
for (Iterator JavaDoc idxIt = gcr.getIndexFields().iterator();
86              idxIt.hasNext();) {
87             TypedElement te1 = (TypedElement) idxIt.next();
88             f = new BasicJormField(
89                 getFieldName(name, te1.getName()), this, gcr);
90             fields.add(f);
91             name2field.put(f.getName(), f);
92         }
93     }
94
95     public Object JavaDoc clone(Object JavaDoc clone,
96                         Map JavaDoc obj2clone) throws CloneNotSupportedException JavaDoc {
97         clone = super.clone(clone, obj2clone);
98         ((GenClassExtent) clone).gcr = gcr;
99         ((GenClassExtent) clone).elementFieldName = elementFieldName;
100         return clone;
101     }
102
103
104     public String JavaDoc getElementFieldName() {
105         return elementFieldName;
106     }
107
108     public MetaObject getMetaObject() {
109         return gcr;
110     }
111
112     public String JavaDoc getJormName() {
113         return gcr.getGenClassId();
114     }
115
116 }
117
Popular Tags