KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jdo > api > persistence > model > EnhancerModel


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.jdo.api.persistence.model;
25
26 import java.util.List JavaDoc;
27 import java.net.URL JavaDoc;
28 import java.io.IOException JavaDoc;
29 import java.io.BufferedInputStream JavaDoc;
30 import java.io.BufferedOutputStream JavaDoc;
31 import java.io.InputStream JavaDoc;
32 import java.lang.reflect.Modifier JavaDoc;
33
34 import com.sun.jdo.api.persistence.model.jdo.PersistenceClassElement;
35 import com.sun.jdo.api.persistence.model.jdo.PersistenceFieldElement;
36
37 /**
38  *
39  * @author nico
40  * @version %I%
41  */

42 class EnhancerModel extends Model {
43     private static final boolean DEBUG = false;
44
45     /**
46      * Creates a new <code>EnhancerModel</code>. This constructor should not be
47      * called directly; instead, the static instance accessible from the
48      * <code>Model</code> class should be used.
49      *
50      * @see Model#ENHANCER
51      */

52     EnhancerModel () {
53         super();
54     }
55
56     /**
57      * Determines if the specified className represents an interface type.
58      * @param className the fully qualified name of the class to be checked
59      * @return <code>true</code> if this class name represents an interface;
60      * <code>false</code> otherwise.
61      */

62     public boolean isInterface (String JavaDoc className) {
63         throw new UnsupportedOperationException JavaDoc();
64     }
65
66     /**
67      * Returns the input stream with the supplied resource name found with
68      * the supplied class name.
69      *
70      * @param className the fully qualified name of the class which will
71      * be used as a base to find the resource
72      * @param classLoader the class loader used to find the resource
73      * @param resourceName the name of the resource to be found
74      *
75      * @return the input stream for the specified resource, <code>null</code>
76      * if an error occurs or none exists
77      */

78     protected BufferedInputStream JavaDoc getInputStreamForResource (String JavaDoc className,
79         ClassLoader JavaDoc classLoader, String JavaDoc resourceName)
80     {
81         debug("getInputStreamForResource(" + className + // NOI18N
82
"," + resourceName + ")"); // NOI18N
83

84         InputStream JavaDoc is = (classLoader != null)
85             ? classLoader.getResourceAsStream(resourceName)
86             : ClassLoader.getSystemResourceAsStream(resourceName);
87
88         BufferedInputStream JavaDoc rc = null;
89         if (is != null && !(is instanceof BufferedInputStream JavaDoc)) {
90             rc = new BufferedInputStream JavaDoc(is);
91         } else {
92             rc = (BufferedInputStream JavaDoc)is;
93         }
94         return rc;
95     }
96
97     /**
98      * Returns the name of the second to top (top excluding java.lang.Object)
99      * superclass for the given class name.
100      * @param className the fully qualified name of the class to be checked
101      * @return the top non-Object superclass for className,
102      * <code>className</code> if an error occurs or none exists
103      */

104     protected String JavaDoc findPenultimateSuperclass (String JavaDoc className) {
105         debug("findPenultimateSuperclass(" + className + ")"); // NOI18N
106
throw new UnsupportedOperationException JavaDoc();
107     }
108
109     /**
110      * Returns the name of the superclass for the given class name.
111      * @param className the fully qualified name of the class to be checked
112      * @return the superclass for className, <code>null</code> if an error
113      * occurs or none exists
114      */

115     protected String JavaDoc getSuperclass (String JavaDoc className) {
116         debug("getSuperclass (" + className + ")"); // NOI18N
117
return null; // "java.lang.Object"; // NOI18N
118
}
119
120     /**
121      * Creates a file with the given base file name and extension
122      * parallel to the supplied class (if it does not yet exist).
123      *
124      * @param className the fully qualified name of the class
125      * @param baseFileName the name of the base file
126      * @param extension the file extension
127      *
128      * @return the output stream for the specified resource, <code>null</code>
129      * if an error occurs or none exists
130      *
131      * @exception IOException if there is some error creating the file
132      */

133     protected BufferedOutputStream JavaDoc createFile (String JavaDoc className, String JavaDoc baseFileName,
134         String JavaDoc extension) throws IOException JavaDoc
135     {
136         throw new UnsupportedOperationException JavaDoc();
137     }
138
139     /**
140      * Deletes the file with the given file name which is parallel
141      * to the supplied class.
142      * @param className the fully qualified name of the class
143      * @param fileName the name of the file
144      * @exception IOException if there is some error deleting the file
145      */

146     protected void deleteFile (String JavaDoc className, String JavaDoc fileName)
147         throws IOException JavaDoc
148     {
149         throw new UnsupportedOperationException JavaDoc();
150     }
151
152     /** Returns the class element with the specified className.
153      * @param className the fully qualified name of the class to be checked
154      * @param classLoader the class loader used to check the class
155      * @return the class element for the specified className
156      */

157     public Object JavaDoc getClass (String JavaDoc className, ClassLoader JavaDoc classLoader)
158     {
159         throw new UnsupportedOperationException JavaDoc();
160     }
161
162     /** Determines if the specified class implements the specified interface.
163      * Note, class element is a model specific class representation as returned
164      * by a getClass call executed on the same model instance.
165      * @param classElement the class element to be checked
166      * @param interfaceName the fully qualified name of the interface to
167      * be checked
168      * @return <code>true</code> if the class implements the interface;
169      * <code>false</code> otherwise.
170      * @see #getClass
171      */

172     public boolean implementsInterface (Object JavaDoc classElement,
173         String JavaDoc interfaceName)
174     {
175         throw new UnsupportedOperationException JavaDoc();
176     }
177
178     /** Determines if the class with the specified name declares a constructor.
179      * @param className the name of the class to be checked
180      * @return <code>true</code> if the class declares a constructor;
181      * <code>false</code> otherwise.
182      * @see #getClass
183      */

184     public boolean hasConstructor (String JavaDoc className)
185     {
186         throw new UnsupportedOperationException JavaDoc();
187     }
188
189     /** Returns the constructor element for the specified argument types
190      * in the class with the specified name. Types are specified as type
191      * names for primitive type such as int, float or as fully qualified
192      * class names.
193      * @param className the name of the class which contains the constructor
194      * to be checked
195      * @param argTypeNames the fully qualified names of the argument types
196      * @return the constructor element
197      * @see #getClass
198      */

199     public Object JavaDoc getConstructor (String JavaDoc className, String JavaDoc[] argTypeNames)
200     {
201         throw new UnsupportedOperationException JavaDoc();
202     }
203
204     /** Returns the method element for the specified method name and argument
205      * types in the class with the specified name. Types are specified as
206      * type names for primitive type such as int, float or as fully qualified
207      * class names.
208      * @param className the name of the class which contains the method
209      * to be checked
210      * @param methodName the name of the method to be checked
211      * @param argTypeNames the fully qualified names of the argument types
212      * @return the method element
213      * @see #getClass
214      */

215     public Object JavaDoc getMethod (String JavaDoc className, String JavaDoc methodName,
216        String JavaDoc[] argTypeNames)
217     {
218         throw new UnsupportedOperationException JavaDoc();
219     }
220
221     /** Returns the string representation of type of the specified element.
222      * If element denotes a field, it returns the type of the field.
223      * If element denotes a method, it returns the return type of the method.
224      * Note, element is either a field element as returned by getField, or a
225      * method element as returned by getMethod executed on the same model
226      * instance.
227      * @param element the element to be checked
228      * @return the string representation of the type of the element
229      * @see #getField
230      * @see #getMethod
231      */

232     public String JavaDoc getType (Object JavaDoc element)
233     {
234         throw new UnsupportedOperationException JavaDoc();
235     }
236
237     /**
238      * Returns a list of names of all the declared field elements in the
239      * class with the specified name.
240      * @param className the fully qualified name of the class to be checked
241      * @return the names of the field elements for the specified class
242      */

243     public List JavaDoc getFields (String JavaDoc className) {
244         throw new UnsupportedOperationException JavaDoc();
245     }
246
247     /**
248      * Returns the field element for the specified fieldName in the class
249      * with the specified className.
250      * @param className the fully qualified name of the class which contains
251      * the field to be checked
252      * @param fieldName the name of the field to be checked
253      * @return the field element for the specified fieldName
254      */

255     public Object JavaDoc getField (String JavaDoc className, String JavaDoc fieldName) {
256         throw new UnsupportedOperationException JavaDoc();
257     }
258
259     /** Determines if the specified field element has a serializable type.
260      * A type is serializable if it is a primitive type, a class that implements
261      * java.io.Serializable or an interface that inherits from
262      * java.io.Serializable.
263      * Note, the field element is a model specific field representation as
264      * returned by a getField call executed on the same model instance.
265      * @param fieldElement the field element to be checked
266      * @return <code>true</code> if the field element has a serializable type;
267      * <code>false</code> otherwise.
268      * @see #getField
269      */

270     public boolean isSerializable (Object JavaDoc fieldElement)
271     {
272         throw new UnsupportedOperationException JavaDoc();
273     }
274
275     /**
276      * Determines if a field with the specified fieldName in the class
277      * with the specified className is an array.
278      * @param className the fully qualified name of the class which contains
279      * the field to be checked
280      * @param fieldName the name of the field to be checked
281      * @return <code>true</code> if this field name represents a java array
282      * field; <code>false</code> otherwise.
283      * @see #getFieldType
284      */

285     public boolean isArray (String JavaDoc className, String JavaDoc fieldName) {
286         throw new UnsupportedOperationException JavaDoc();
287     }
288
289     /** Returns the string representation of declaring class of
290      * the specified member element. Note, the member element is
291      * either a class element as returned by getClass, a field element
292      * as returned by getField, a constructor element as returned by
293      * getConstructor, or a method element as returned by getMethod
294      * executed on the same model instance.
295      * @param memberElement the member element to be checked
296      * @return the string representation of the declaring class of
297      * the specified memberElement
298      * @see #getClass
299      * @see #getField
300      * @see #getConstructor
301      * @see #getMethod
302      */

303     public String JavaDoc getDeclaringClass (Object JavaDoc memberElement)
304     {
305         throw new UnsupportedOperationException JavaDoc();
306     }
307
308     /** Returns the modifier mask for the specified member element.
309      * Note, the member element is either a class element as returned by
310      * getClass, a field element as returned by getField, a constructor element
311      * as returned by getConstructor, or a method element as returned by
312      * getMethod executed on the same model instance.
313      * @param memberElement the member element to be checked
314      * @return the modifier mask for the specified memberElement
315      * @see java.lang.reflect.Modifier
316      * @see #getClass
317      * @see #getField
318      * @see #getConstructor
319      * @see #getMethod
320      */

321     public int getModifiers (Object JavaDoc memberElement)
322     {
323         throw new UnsupportedOperationException JavaDoc();
324     }
325
326     /**
327      * Returns the PersistenceFieldElement with the supplied fieldName found
328      * in the supplied className.
329      * @param className the fully qualified name of the class which contains
330      * the field to be checked
331      * @param fieldName the name of the field to be checked
332      * @return the PersistenceFieldElement for the specified field,
333      * <code>null</code> if an error occurs or none exists
334      */

335     public PersistenceFieldElement getPersistenceField(String JavaDoc className,
336         String JavaDoc fieldName)
337     {
338         return getPersistenceFieldInternal(className, fieldName);
339     }
340
341     /**
342      * Determines if the specified className and fieldName pair represent a
343      * key field.
344      * @param className the fully qualified name of the class which contains
345      * the field to be checked
346      * @param fieldName the name of the field to be checked
347      * @return <code>true</code> if this field name represents a key field;
348      * <code>false</code> otherwise.
349      */

350     public boolean isKey (String JavaDoc className, String JavaDoc fieldName)
351     {
352         PersistenceFieldElement field =
353             getPersistenceField(className, fieldName);
354
355         return field != null ? field.isKey() : false;
356     }
357
358     private void debug (Object JavaDoc o) {
359         if (DEBUG)
360             System.out.println("EnhancerModel::" + o); // NOI18N
361
}
362 }
363
Popular Tags