KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jorm > metainfo > api > Class


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.api;
25
26 import java.util.Collection JavaDoc;
27 import java.util.List JavaDoc;
28
29 import org.objectweb.jorm.type.api.PType;
30 import org.objectweb.medor.expression.api.Expression;
31 import org.objectweb.medor.expression.api.ExpressionException;
32
33 /**
34  * A Class interface defines methods to describe a Class meta object.
35  * A Class is composed by a set of fields (primitive, reference class or
36  * reference generic class), a set of inherited classes, a mapping class,
37  * can be abstract or not and has a name.
38  * @author X. Spengler
39  */

40 public interface Class extends MetaObject {
41     /**
42      * Allows to retrieve the file name of this class MO.
43      * @return The file name.
44      */

45     String JavaDoc getFileName();
46
47     /**
48      * Allows to assign the file name of this class MO.
49      * @param filename The file name.
50      */

51     void setFileName(String JavaDoc filename);
52
53     /**
54      * Allows to know if the current class is an abstract class or not.
55      *
56      * @return true, if the current class is an abstract class, and false,
57      * if the current class is not abstract
58      */

59     boolean isAbstract();
60
61     void setAbstract(boolean isAbstract);
62
63     /**
64      * Allows to know the name of the current class object.
65      * @return the string representation of the class name
66      */

67     String JavaDoc getName();
68
69     /**
70      * Gets the fully qualified name (including the package name) associated
71      * with this class.
72      * @return the string representation of the fully qualified class name
73      */

74     String JavaDoc getFQName();
75
76     /**
77      * Allows to obtain an existing Field.
78      * A TypedElement is a class field, and this method finds a field with its
79      * name (fieldName). This method is a generic method to return a
80      * TypedElement object.
81      *
82      * @param fieldName the name of the class field
83      * @return a field object. If the field does not exist, null is returned.
84      */

85     TypedElement getTypedElement(String JavaDoc fieldName);
86
87     /**
88      * Removes a typed element.
89      * @param fieldName is the name of the field to be removed
90      * @return the removed element or null if the field has not been found.
91      */

92     TypedElement removeTypedElement(String JavaDoc fieldName);
93
94     /**
95      * Creates a new NameDef object for the current Class object.
96      * Here we can define if the namedef is defined outside jorm or not.
97      * In the case where the namedef is already defined for the current class,
98      * the old one is used and returned.
99      * associated.
100      * @return a new object used to describe the PName projection for
101      * the current Class
102      */

103     NameDef createNameDef();
104
105     /**
106      * Creates an hiddenfield for the current Class object.
107      * An hidden field is used to map the pname of the class or the pname of a ref field.
108      * An hidden field is a scalarfield.
109      *
110      * @param fieldname the name of the hiddenfield
111      * @param type the ptype of the hiddenfield
112      * @param size is the
113      * @return a new scalarfield object used to describe the hiddenfield
114      */

115
116     ScalarField createHiddenField(String JavaDoc fieldname, PType type, int size, int scale);
117
118     /**
119      * @return a collection of hidden field of the class WITHOUT inherited
120      * fields.
121      */

122     Collection JavaDoc getHiddenFields() ;
123
124     /**
125      * @return a collection of hidden field of the class including inherited
126      * fields.
127      */

128     Collection JavaDoc getAllHiddenFields() ;
129
130     /**
131      * Retrieve the hiddenfield identified by its name in the current class.
132      * @param fieldname the name of the hiddenfield.
133      * @return the scalarfield object describing the hiddenfield or null if the field does not exist in the class.
134      */

135     ScalarField getHiddenField(String JavaDoc fieldname);
136
137
138     /**
139      * Returns a NameDef object from a given mapperName and mappingName.
140      * If the namedef does not exist, null is returned.
141      *
142      * @param projectName the name of the class project
143      * @return an existing namedef object if exists, either null
144      */

145     NameDef getNameDef(String JavaDoc projectName);
146
147     /**
148      * @return a collection of NameDef object
149      */

150     Collection JavaDoc getNameDefs();
151
152     /**
153      * @return the filter expression (Medor expression) permitting to known if
154      * instance of the parent class is in fact an instance of the current
155      * persistent class. The filter uses the field name (composite field in case
156      * of a composite or the field class name). If the current class has no
157      * parent, then this method return null;
158      */

159     Expression getInheritanceFilter(NameDef nd) throws ExpressionException;
160
161     /**
162      * @return the key matching to the current class. This value is the result
163      * of the inheritance filter evaluation.
164      */

165     Object JavaDoc getInheritanceNamingKey(NameDef nd);
166
167     void setInheritanceNamingKey(NameDef nd, Object JavaDoc key);
168
169     /**
170      * @param filter is the filter expression (Medor expression) permitting to
171      * known if instance of the parent class is in fact an instance of the
172      * current persistent class. The filter uses the field name (composite field
173      * in case of a composite or the field class name).
174      */

175     void setInheritanceFilter(NameDef nd, Expression filter);
176
177     /**
178      * @param filter is the filter expression (Medor expression as string)
179      * permitting to known if instance of the parent class is in fact an
180      * instance of the current persistent class. The filter uses the field name
181      * (composite field in case of a composite or the field class name).
182      */

183     void setInheritanceFilter(NameDef nd, String JavaDoc filter);
184
185
186     /**
187      * Allows to obtain a new PrimitiveElement from a class field name an its
188      * type.
189      * A PrimitiveElement is a Class field. If the class field already exists,
190      * it is returned.
191      *
192      * @param fieldName the name of the primitive field
193      * @param type the PType of the primitive field
194      * @return a new PrimitiveElement object, or the existing one if already
195      * defined
196      */

197     PrimitiveElement createPrimitiveElement(String JavaDoc fieldName, PType type, int size, int scale);
198
199     /**
200      * Defines the value of a constant PrimitiveElement, defined either in the
201      * current class or in one of its ancestors.
202      * <p>The constant value is represented by a String.
203      *
204      * @param fieldName the existing PrimitiveElement
205      * @param cv the constant value
206      */

207     void setConstantValue(String JavaDoc fieldName, String JavaDoc cv);
208
209     /**
210      * Obtains the value of a constant PrimitiveElement, defined either in the
211      * current class or in one of its ancestors.
212      * <p>The constant value is represented by a String.
213      *
214      * @param fieldName the existing PrimitiveElement
215      * @return the constant value as a String
216      */

217     String JavaDoc getConstantValue(String JavaDoc fieldName);
218
219     /**
220      * Allows to obtain a new ClassRef from a field name an its class.
221      * A ClassRef object is a field which is represented by a reference to a
222      * Class. If the field already exists, it is returned.
223      *
224      * @param fieldName the name of the field
225      * @param class_ the class meta-object which represents the reference of
226      * the field
227      * @return a new ClassRef object, or the existing one if already defined
228      */

229     ClassRef createClassRef(String JavaDoc fieldName, Class JavaDoc class_);
230
231     /**
232      * Allows to obtain a new GenClassRef from a field name an its generic
233      * class.
234      * A GenClassRef object is a field which is represented by a
235      * reference to a generic class. If the field already exists,
236      * it is returned.
237      *
238      * @param fieldName the name of the field
239      * @param genName the GenClass object which represents the reference of
240      * the field
241      * @return a new GenClassRef object, or the existing one if already
242      * defined
243      */

244     GenClassRef createGenClassRef(String JavaDoc fieldName, String JavaDoc genName);
245
246     /**
247      * Returns an iterator on existing class fields.
248      * If no field is defined, an empty iterator is returned.
249      * This iterator contains PrimitiveElements, ClassRef and GenClassRef
250      * objects. The top level object is TypedElement.
251      *
252      * @return an iterator on fields, or null if there is no defined field
253      */

254     Collection JavaDoc getFields();
255
256     /**
257      * Returns an iterator on existing class fields + fields from super classes.
258      * This iterator contains PrimitiveElement, ClassRef and GenClassRef
259      * objects.
260      *
261      * @return an iterator on all defined fields, plus fields from super
262      */

263     Collection JavaDoc getAllFields() ;
264
265     /**
266      * Allows us to obtain all classes derived from the current class object.
267      * This collection contains Class objects. In the case where there is no
268      * derived class, an empty collection is returned.
269      *
270      * @return a collection on derived classes (Class objets). If no object
271      * exists, an empty collection is returned.
272      */

273     Collection JavaDoc getSubClasses();
274
275     /**
276      * Retrieves the collection of super classes
277      * @return a collection of Class meta objects.
278      */

279     Collection JavaDoc getSuperClasses();
280
281     /**
282      * Retrieves a super class whith its name.
283      * @param fqcn is the fully qualified class name of the super class
284      * @return a Class meta object instance if the specified class name is a
285      * super class of the current class. A null value if the specified class name is
286      * not a super class of the current class.
287      */

288     Class JavaDoc getSuperClass(String JavaDoc fqcn);
289
290     /**
291      * Adds a new inherited class to the list of the inherited classes for the
292      * current class object.
293      * If the class already exists, nothing is done.
294      *
295      * @param class_ the inherited class to add to inherited classes list
296      */

297     void addSuperClass(Class JavaDoc class_);
298
299     /**
300      * Adds a new class to the list of the derived classes for the
301      * current class object.
302      * If the class already exists, nothing is done.
303      *
304      * @param class_ the inherited class to add to inherited classes list
305      */

306     void addSubClass(Class JavaDoc class_);
307
308     /**
309      * Returns the number of inherited classes for the current Class object.
310      *
311      * @return the number of inherited classes
312      */

313     int getInheritedClassNumber();
314
315     /**
316      * @return the PType of the persistent class
317      */

318     PType getPType();
319
320     /**
321      * Returns the number of fields which are references to classes.
322      *
323      * @return the number of fieldRef
324      */

325     int getFieldRefNumber();
326
327     /**
328      * Returns a ClassProject object.
329      *
330      * @param projectName a project name.
331      * @return a ClassProject object.
332      */

333     ClassProject getClassProject(String JavaDoc projectName);
334
335     /**
336      * Returns a ClassMapping object.
337      *
338      * @param projectName a project name,
339      * mappername a mapper name.
340      * @return a ClassMapping object.
341      */

342     public ClassMapping getClassMapping(String JavaDoc projectName, String JavaDoc mapperName);
343
344     /**
345      * Returns a collection of ClassProject objects.
346      * @return a collection.
347      */

348     Collection JavaDoc getClassProjects();
349
350     /**
351      * Adds a ClassProject object.
352      *
353      * @param projectName a project name,
354      * classProject a ClassProject object.
355      */

356     void addClassProject(String JavaDoc projectName, ClassProject classProject);
357
358     /**
359      * Creates a new ClassProject object.
360      *
361      * @param projectName the name of the project.
362      * @return a new ClassProject object, or an existing one.
363      */

364     ClassProject createClassProject(String JavaDoc projectName);
365
366     /**
367      * Removes a ClassProject instance.
368      * @param projectname is the name of removed ClassProject
369      * @return The removed ClassProject
370      */

371     ClassProject removeClassProject(String JavaDoc projectname);
372
373     /**
374      * Returns only the top ancestors.
375      */

376     List JavaDoc getAncestors();
377
378     /**
379      * Return all the ancestors in the inheritance graph.
380      */

381     List JavaDoc getAllAncestors();
382     
383     /**
384      * Returns true if the class is polymorphic, i.e. it has subclasses or
385      * superclasses
386      * @return true if the class is polymorphic
387      */

388     boolean isPolymorphic();
389
390     /**
391      * Return true if the KFPNC has to be generated.
392      * Else, return false.
393      */

394     boolean generateKFPNC() throws ExpressionException;
395     
396     /**
397      * Return true if one element of the expression exp is not part of the namedef.
398      * Else, return false.
399      */

400     public boolean detectFilterElementNotInPK(Expression exp, NameDef nd)
401                     throws ExpressionException;
402 }
403
Popular Tags