KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xml > internal > utils > synthetic > Class


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * $Id: Class.java,v 1.8 2004/02/17 04:23:24 minchau Exp $
18  */

19 package com.sun.org.apache.xml.internal.utils.synthetic;
20
21 import java.lang.reflect.Modifier JavaDoc;
22
23 import com.sun.org.apache.xml.internal.utils.synthetic.reflection.Constructor;
24 import com.sun.org.apache.xml.internal.utils.synthetic.reflection.Field;
25 import com.sun.org.apache.xml.internal.utils.synthetic.reflection.Method;
26
27 /* WORK NEEDED:
28     Factories/Libraries: We currently have forClass and
29     forName(request reified, complain if no real class),
30     and declareClass (request unreified, create unreified
31     if it doesn't exist). What about ther user expectations
32     -- should we have a full matrix, rather than asking
33     users to write wrappers?
34
35     Reflection doesn't tell us about deprecation. If we want
36     that info, MFC advises mousing our way into the bytecodes.
37     (Ugh). Should we at least model that for synthetics?
38 */

39
40 /**
41  * com.sun.org.apache.xml.internal.utils.synthetic.Class is a mutable equivalent of java.lang.Class.
42  * Instances represent classes and interfaces in a running Java
43  * application, or class descriptions under construction. In the
44  * former case, com.sun.org.apache.xml.internal.utils.synthetic.Class operates as a proxy for the
45  * "real" java.lang.Class object; in the latter, it consults
46  * data structures defined in the com.sun.org.apache.xml.internal.utils.synthetic.reflection.* package.
47  * <p>
48  * Unlike java.lang.Class, com.sun.org.apache.xml.internal.utils.synthetic.Class has a pair of factories
49  * (fromName and fromClass). It can also be switched from synthetic
50  * to proxy operation after construction, by setting the realClass
51  * property; this is intended to allow these definitions to be
52  * "compiled in place".
53  * <p>
54  * For convenient use, com.sun.org.apache.xml.internal.utils.synthetic.Class implements an extended
55  * version of the java.lang.Class API -- but is not a subclass
56  * thereof, since java.lang.Class is Final (presumably for
57  * security reasons).
58  * <p>
59  * DEVELOPMENT NOTE: Methods not yet implemented will throw
60  * IllegalStateException
61  * <p>
62  * I've added code to convert primitive names into their TYPEs,
63  * to accept foo[] as a synonym for [Lfoo, and to generate
64  * the right thing on output (getJava[Short]Name).
65  * Useful extension for code generation from Java-like
66  * source. We may want to factor these and toSource out, making
67  * com.sun.org.apache.xml.internal.utils.synthetic.Class addess only the JVM level and providing
68  * subclasses or access tools that handle language syntax
69  * (Java source, NetRexx source, etc.)
70  *
71  * @since 2000/2/10
72  * @xsl.usage internal
73  */

74 public class Class extends Object JavaDoc implements java.io.Serializable JavaDoc
75 {
76
77   /** Class descriptions currently existing. */
78   private static java.util.Hashtable JavaDoc global_classtable =
79     new java.util.Hashtable JavaDoc();
80
81   /** fully-qualified path.classname.
82    * @serial */

83   private java.lang.String JavaDoc name;
84
85   /**
86    * Actual Java class object. When present, all interactions
87    * are redirected to it. Allows our Class to function as a
88    * wrapper for the Java version (in lieu of subclassing or
89    * a shared Interface), and allows "in-place compilation"
90    * to replace a generated description with an
91    * directly runnable class.
92    * @serial
93    */

94   private java.lang.Class JavaDoc realclass = null;
95
96   /** Field modifiers: Java language modifiers for this class
97    * or interface, encoded in an integer.
98    * @serial
99    */

100   private int modifiers;
101
102   /** Field isInterface: True if the Class object represents
103    * an interface type.
104    * @serial */

105   private boolean isInterface = false;
106
107   /** Field superclass: If this object represents the class
108    * Object, this is null. Otherwise, the Class object that
109    * represents the superclass of that class. In proxy mode this
110    * is determined when needed. In synthesis mode it's explicitly
111    * set by the user, and if null the superclass will be assumed
112    * to be Object.
113    * @serial */

114   private Class JavaDoc superclass = null;
115
116   /** Field declaringclass: If this object represents an inner class,
117    * the Class object that represents the class that declared it.
118    * Otherwise null.
119    * @serial
120    * */

121   private Class JavaDoc declaringclass = null;
122
123   /** Field interfaces: A list of all interfaces implemented by the class
124    * or interface represented by this object.
125    * @serial
126    * */

127   private Class JavaDoc[] interfaces = new Class JavaDoc[0];
128
129   /** Field allclasses: an array containing Class objects representing all
130    * the public classes and interfaces that are members of the class
131    * represented by this Class object.
132    * @serial
133    */

134   private Class JavaDoc[] allclasses = new Class JavaDoc[0];
135
136   /** Field declaredclasses: an array of Class objects reflecting all the
137    * classes and interfaces declared as members of the class represented
138    * by this Class object. Excludes inherited classes and interfaces.
139    * @serial
140    */

141   private Class JavaDoc[] declaredclasses = new Class JavaDoc[0];
142
143   /** Field allconstructors: an array containing Constructor objects
144    * reflecting all the constructors of the class represented
145    * by this Class object. An array of length 0 is returned if the
146    * class has no public constructors. In proxy mode only public
147    * constructors will be displayed; in synthesis mode, all declared
148    * constructors will be displayed.
149    * @serial
150    * */

151   private Constructor[] allconstructors = new Constructor[0];
152
153   /** Field declaredconstructors: an array of Constructor objects
154    * reflecting all the constructors declared by the class
155    * represented by this Class object. Includes non-public
156    * constructors, but excludes inherited ones.
157    * @serial
158    * */

159   private Constructor[] declaredconstructors = new Constructor[0];
160
161   /** Field allmethods.
162    * @serial */

163   private Method[] allmethods = new Method[0];
164
165   /** Field declaredmethods.
166    * @serial */

167   private Method[] declaredmethods = new Method[0];
168
169   /** Field allfields.
170    * @serial */

171   private Field[] allfields = new Field[0];
172
173   /** Field declaredfields.
174    * @serial */

175   private Field[] declaredfields = new Field[0];
176
177   /** Field innerclasses.
178    * @serial */

179   private Class JavaDoc[] innerclasses = new Class JavaDoc[0];
180
181   /**
182    * Construct a synthetic class as proxy/wrapper for an existing
183    * Java Class. Non-public; most folks should use
184    * .forName and .forClass to request these wrappers, so they
185    * get the shared instances.
186    * <p>
187    * Creation date: (12-25-99 12:16:15 PM)
188    * @param realclass java.lang.Class
189    */

190   Class(java.lang.Class JavaDoc realclass)
191   {
192
193     this(realclass.getName());
194
195     try
196     {
197       setRealClass(realclass);
198     }
199     catch (SynthesisException e)
200     {
201       e.printStackTrace();
202     }
203   }
204
205   /**
206    * Construct a named-but-empty synthetic Class object.
207    * Non-public; most folks should use
208    * .forName and .forClass to request these wrappers, so they
209    * get the shared instances.
210    * <p>
211    * Creation date: (12-25-99 12:15:23 PM)
212    *
213    * @param fullname full name of the class that is synthetized.
214    */

215   Class(String JavaDoc fullname)
216   {
217
218     this.name = fullname;
219
220     global_classtable.put(fullname, this);
221   }
222
223   /**
224    * Returns the synthetic Class object associated with the "real"
225    * class specified, creating one if it didn't already exist.
226    * <p>
227    * For example, the following code fragment returns
228    * the runtime Class descriptor for the class named
229    * mypackage.MyClass.
230    * <code>
231    * Class t =
232    * Class.forName(java.lang.Class.forName("mypackage.MyClass"))
233    * </code>
234    * <p>
235    * Note that if the user has manually created a com.sun.org.apache.xml.internal.utils.synthetic.Class
236    * with the same name before this call is issued, that object
237    * will be found instead. See also the declareClass call.
238    * <p>
239    * We need a better way to declare/define array classes,
240    * given a class object (synthetic or not).
241    *
242    * @param cls the desired Java class.
243    * @return the synthetic Class descriptor for the specified class.
244    */

245   public static Class JavaDoc forClass(java.lang.Class JavaDoc cls)
246   {
247
248     if (cls == null)
249       return null;
250
251     Class JavaDoc ret = (Class JavaDoc) (global_classtable.get(cls.getName()));
252
253     if (null == ret)
254       ret = new Class JavaDoc(cls);
255
256     return ret;
257   }
258
259   /**
260    * Like forName, but if the classname doesn't have a package
261    * prefix we first attempt to look it up as one of our own
262    * inner clases. As with forName, if this can not be resolved
263    * we throw an exception.
264    *
265    * @param classname the full or partial class name.
266    *
267    * @return The Class name that matches the argument.
268    *
269    * @throws ClassNotFoundException
270    */

271   public Class JavaDoc forNameInContext(String JavaDoc classname)
272           throws ClassNotFoundException JavaDoc
273   {
274
275     for (int i = innerclasses.length - 1; i >= 0; --i)
276     {
277       if (classname.equals(innerclasses[i].getShortName()))
278         return innerclasses[i];
279     }
280
281     return forName(classname);
282   }
283
284   /**
285    * Returns the synthetic Class object associated with the class
286    * with the given fully-qualified name. If there isn't one, this
287    * method attempts to locate, load and link the standard java Class.
288    * If it succeeds, it returns a wrapped version of the Class object
289    * representing the class. If it fails, the method throws a
290    * ClassNotFoundException.
291    * <p>
292    * For example, the following code fragment returns
293    * the runtime Class descriptor for the class named
294    * mypackage.MyClass -- either as a synthetic or as
295    * a standard Java class.
296    * <code>
297    * Class t =
298    * Class.forName("mypackage.MyClass")
299    * </code>
300    * <p>
301    * I've added support for arrays -- assuming any name
302    * that ends with ']' is an array. It probably needs to be
303    * made smarter, possibly via a subclass of com.sun.org.apache.xml.internal.utils.synthetic.Class.
304    *
305    * @param className the fully qualified name of the desired class.
306    * @return the synthetic Class descriptor for the class with the specified name.
307    * @throws ClassNotFoundException if the class could not be found.
308    */

309   public static Class JavaDoc forName(String JavaDoc className) throws ClassNotFoundException JavaDoc
310   {
311
312     // ***** Experimental support for array syntax expressed
313
// per Java source rather than per JVM type formalism.
314
// Simpleminded, asssumes balanced []'s.
315
if (className.endsWith("]"))
316     {
317       StringBuffer JavaDoc arrayname = new StringBuffer JavaDoc();
318
319       for (int i = className.indexOf('['); i != -1;
320               i = className.indexOf('[', i + 1))
321       {
322         arrayname.append('[');
323       }
324
325       // Convert the classname to array-formalism
326
// Primitives have letters; objects are Lname;
327
// (Don't ask why long is spelled with a J and
328
// object is spelled with an L...)
329
String JavaDoc classname = className.substring(0, className.indexOf('['));
330
331       if ("byte".equals(classname))
332         arrayname.append('B');
333       else if ("char".equals(classname))
334         arrayname.append('C');
335       else if ("double".equals(classname))
336         arrayname.append('D');
337       else if ("float".equals(classname))
338         arrayname.append('F');
339       else if ("int".equals(classname))
340         arrayname.append('I');
341       else if ("long".equals(classname))
342         arrayname.append('J');
343       else if ("short".equals(classname))
344         arrayname.append('S');
345       else if ("boolean".equals(classname))
346         arrayname.append('Z');
347       else
348         arrayname.append('L').append(classname).append(';');
349
350       // Tail-call.
351
return forName(arrayname.toString());
352     }
353
354     Class JavaDoc ret = (Class JavaDoc) (global_classtable.get(className));
355
356     if (null == ret)
357     {
358
359       // ***** Experimental support for Java primitives
360
// Seems to me that mapping them into the "Type" is
361
// probably most useful
362
if ("boolean".equals(className))
363       {
364         ret = new Class JavaDoc(className);
365         ret.realclass = java.lang.Boolean.TYPE;
366       }
367       else if ("byte".equals(className))
368       {
369         ret = new Class JavaDoc(className);
370         ret.realclass = java.lang.Byte.TYPE;
371       }
372       else if ("char".equals(className))
373       {
374         ret = new Class JavaDoc(className);
375         ret.realclass = java.lang.Character.TYPE;
376       }
377       else if ("short".equals(className))
378       {
379         ret = new Class JavaDoc(className);
380         ret.realclass = java.lang.Short.TYPE;
381       }
382       else if ("int".equals(className))
383       {
384         ret = new Class JavaDoc(className);
385         ret.realclass = java.lang.Integer.TYPE;
386       }
387       else if ("long".equals(className))
388       {
389         ret = new Class JavaDoc(className);
390         ret.realclass = java.lang.Long.TYPE;
391       }
392       else if ("float".equals(className))
393       {
394         ret = new Class JavaDoc(className);
395         ret.realclass = java.lang.Float.TYPE;
396       }
397       else if ("double".equals(className))
398       {
399         ret = new Class JavaDoc(className);
400         ret.realclass = java.lang.Double.TYPE;
401       }
402       else if ("void".equals(className))
403       {
404
405         // ***** Void is an "absence of type". We might want to create
406
// a special object to represent it. This is a placeholder.
407
ret = new Class JavaDoc(className);
408         ret.realclass = java.lang.Class.forName("java.lang.Object");
409       }
410
411       // Other classes are just wrappered. Unknown classes throw a
412
// ClassNotFoundException; the user can switch to declareClass()
413
// if they're sure that an unreified class is OK.
414
else
415         ret = new Class JavaDoc(java.lang.Class.forName(className));
416     }
417
418     return ret;
419   }
420
421   /**
422    * Start to create a synthetic Class with the given fully-qualified
423    * name. If a Class by that name already exists, and it is not
424    * reified, it will be returned instead. If a reified Class _does_
425    * exist, we throw a synthesis exception.
426    *
427    * @param className the fully qualified name of the desired class.
428    * @return the synthetic Class descriptor for the class with the specified name.
429    * @throws SynthesisException if the class has been reified.
430    */

431   public static Class JavaDoc declareClass(String JavaDoc className) throws SynthesisException
432   {
433
434     Class JavaDoc ret = (Class JavaDoc) (global_classtable.get(className));
435
436     if (null == ret)
437       ret = new Class JavaDoc(className);
438
439     if (ret.realclass != null)
440       throw new SynthesisException(SynthesisException.REIFIED);
441
442     return ret;
443   }
444
445   /**
446    * Start to create a synthetic Class with the given fully-qualified
447    * name. If a Class by that name already exists,whether reified or
448    * not, it will be removed from the table and replaced by the new synthesis.
449    *
450    * NOTE THAT the replacement will not affect classes which
451    * have already refernced the old version. We could change that by
452    * having everyone reference everyone else via an indirection table.
453    *
454    * @param className the fully qualified name of the desired class.
455    * @return the synthetic Class descriptor for the class with the specified name.
456    */

457   public static Class JavaDoc reallyDeclareClass(String JavaDoc className)
458   {
459
460     Class JavaDoc ret = (Class JavaDoc) (global_classtable.get(className));
461
462     if (null != ret)
463       global_classtable.remove(ret);
464
465     ret = new Class JavaDoc(className);
466
467     return ret;
468   }
469
470   /**
471    * Returns an array containing Class objects
472    * representing all the public classes and interfaces
473    * that are members of the class represented by this
474    * Class object. This includes public class and
475    * interface members inherited from superclasses and
476    * public class and interface members declared by the
477    * class. Returns an array of length 0 if the class has
478    * no public member classes or interfaces, or if this
479    * Class object represents a primitive type.
480    * <p>
481    * NOTE: In a significant number of existing Java environments,
482    * this method is not implemented by the official Class object
483    * and always returns an empty array. So if you don't get any
484    * useful information from a proxied java.lang.Class, don't
485    * be surprised. I'm not sure if someone decided it was a
486    * potential security issue, or if Sun was lazy and everyone
487    * else followed suit.
488    * <p>
489    * ALSO NOTE: The above spec, as taken from java.lang.Class,
490    * doesn't provide any good way to distinguish the immediate
491    * superclass from all other superclasses. That makes it only
492    * marginally useful, which is no doubt one of the reasons folks
493    * have declined to implement it.
494    *
495    * @return an array of classes.
496    */

497   public Class JavaDoc[] getClasses()
498   {
499
500     if (realclass != null && allclasses == null)
501     {
502       java.lang.Class JavaDoc[] realDE = realclass.getClasses();
503
504       allclasses = new Class JavaDoc[realDE.length];
505
506       for (int i = 0; i < realDE.length; ++i)
507       {
508         allclasses[i] = forClass(realDE[i]);
509       }
510     }
511
512     return allclasses;
513   }
514
515   /**
516    * Determines the class loader for the class.
517    *
518    * the class loader that created the class or
519    * interface represented by this object, or null
520    * if the com.sun.org.apache.xml.internal.utils.synthetic.Class was not created by a class loader.
521    */

522   public ClassLoader JavaDoc getClassLoader()
523   {
524     return (realclass == null) ? null : realclass.getClassLoader();
525   }
526
527   /**
528    * If this class represents an array type, returns the
529    * Class object representing the component type of
530    * the array; otherwise returns null.
531    * <p>
532    * NOTE: Since com.sun.org.apache.xml.internal.utils.synthetic.Class doesn't yet attempt to model array
533    * types, this will currently return false unless we are
534    * proxying such a type.
535    *
536    * @return the Class object representing the component type of
537    * the array, otherwise returns null.
538    */

539   public Class JavaDoc getComponentType()
540   {
541     return realclass == null ? null : new Class JavaDoc(realclass.getComponentType());
542   }
543
544   /**
545    * Returns a Constructor object that reflects the
546    * specified public constructor of the class
547    * represented by this Class object. The
548    * parameterTypes parameter is an array of Class
549    * objects that identify the constructor's formal
550    * parameter types, in declared order.
551    * <p>
552    * The constructor to reflect is located by searching
553    * all the constructors of the class represented by this
554    * Class object for a public constructor with the
555    * exactly the same formal parameter types.
556    *
557    *
558    * @param parameterTypes array of Class
559    * objects that identify the constructor's formal
560    * parameter types, in declared order.
561    *
562    * @return a Constructor object that reflects the
563    * specified public constructor of the class
564    * represented by this Class object.
565    *
566    * @throws NoSuchMethodException
567    * if a matching method is not found.
568    * @throws SecurityException
569    * if access to the information is denied.
570    * @throws SynthesisException
571    */

572   public Constructor getConstructor(Class JavaDoc parameterTypes[])
573           throws NoSuchMethodException JavaDoc, SecurityException JavaDoc, SynthesisException
574   {
575
576     if (realclass == null)
577       throw new SynthesisException(SynthesisException.UNREIFIED);
578
579     java.lang.Class JavaDoc[] real = new java.lang.Class JavaDoc[parameterTypes.length];
580
581     for (int i = 0; i < parameterTypes.length; ++i)
582     {
583       if ((real[i] = parameterTypes[i].getRealClass()) == null)
584         throw new SynthesisException(SynthesisException.UNREIFIED);
585     }
586
587     return new Constructor(realclass.getConstructor(real), this);
588   }
589
590   /**
591    * Returns an array containing Constructor objects
592    * reflecting all the public constructors of the class
593    * represented by this Class object. An array of length
594    * 0 is returned if the class has no public
595    * constructors.
596    *
597    *
598    * @return an array containing Constructor objects
599    * reflecting all the public constructors of the class
600    * represented by this Class object.
601    *
602    * @throws SecurityException
603    * if access to the information is denied.
604    */

605   public Constructor[] getConstructors() throws SecurityException JavaDoc
606   {
607
608     if (realclass != null && allconstructors == null)
609     {
610       java.lang.reflect.Constructor JavaDoc[] realDC = realclass.getConstructors();
611
612       allconstructors = new Constructor[realDC.length];
613
614       for (int i = 0; i < realDC.length; ++i)
615       {
616         allconstructors[i] = new Constructor(realDC[i], this);
617       }
618     }
619
620     return allconstructors;
621   }
622
623   /**
624    * This method is not implemented in VAJAVA 3.0
625    * <p>
626    * Returns an array of Class objects reflecting all the
627    * classes and interfaces declared as members of the
628    * class represented by this Class object. This
629    * includes public, protected, default (package)
630    * access, and private classes and interfaces declared
631    * by the class, but excludes inherited classes and
632    * interfaces. Returns an array of length 0 if the class
633    * declares no classes or interfaces as members, or if
634    * this Class object represents a primitive type.
635    *
636    *
637    * @return an array of Class objects reflecting all the
638    * classes and interfaces declared as members of the
639    * class represented by this Class object.
640    *
641    * @throws SecurityException
642    * if access to the information is denied.
643    */

644   public Class JavaDoc[] getDeclaredClasses() throws SecurityException JavaDoc
645   {
646
647     // ***** This should really be a single class plus declared interfaces.
648
if (realclass != null && declaredclasses == null)
649     {
650       java.lang.Class JavaDoc[] realDE = realclass.getDeclaredClasses();
651
652       declaredclasses = new Class JavaDoc[realDE.length];
653
654       for (int i = 0; i < realDE.length; ++i)
655       {
656         declaredclasses[i] = forClass(realDE[i]);
657
658         if (!realDE[i].isInterface())
659           superclass = declaredclasses[i];
660       }
661     }
662
663     return declaredclasses;
664   }
665
666   /**
667    * Adds an "extends" description for the class or
668    * interface represented by this Class object
669    *
670    * @param newclass The class that this class extends.
671    * @throws SynthesisException
672    * if the class has been reified.
673    */

674   public void addExtends(Class JavaDoc newclass) throws SynthesisException
675   {
676
677     if (realclass != null)
678       throw new SynthesisException(SynthesisException.REIFIED);
679
680     Class JavaDoc[] scratch = new Class JavaDoc[declaredclasses.length + 1];
681
682     System.arraycopy(declaredclasses, 0, scratch, 0, declaredclasses.length);
683
684     scratch[declaredclasses.length] = newclass;
685     declaredclasses = scratch;
686   }
687
688   /**
689    * Returns a Constructor object that reflects the
690    * specified declared constructor of the class or
691    * interface represented by this Class object. The
692    * parameterTypes parameter is an array of Class
693    * objects that identify the constructor's formal
694    * parameter types, in declared order.
695    *
696    *
697    * @param parameterTypes array of Class
698    * objects that identify the constructor's formal
699    * parameter types, in declared order.
700    *
701    * @return a Constructor object that reflects the
702    * specified declared constructor of the class or
703    * interface represented by this Class object.
704    *
705    * @throws NoSuchMethodException
706    * if a matching method is not found.
707    * @throws SecurityException
708    * if access to the information is denied.
709    */

710   public Constructor getDeclaredConstructor(Class JavaDoc parameterTypes[])
711           throws NoSuchMethodException JavaDoc, SecurityException JavaDoc
712   {
713     throw new java.lang.IllegalStateException JavaDoc();
714   }
715
716   /**
717    * Adds a Constructor description for the class or
718    * interface represented by this Class object
719    *
720    * @return The constructor object.
721    *
722    * @throws SynthesisException
723    * if the class has been reified.
724    */

725   public Constructor declareConstructor() throws SynthesisException
726   {
727
728     if (realclass != null)
729       throw new SynthesisException(SynthesisException.REIFIED);
730
731     Constructor newctor = new Constructor(this);
732     Constructor[] scratch = new Constructor[declaredconstructors.length + 1];
733
734     System.arraycopy(declaredconstructors, 0, scratch, 0,
735                      declaredconstructors.length);
736
737     scratch[declaredconstructors.length] = newctor;
738     declaredconstructors = scratch;
739     scratch = new Constructor[allconstructors.length + 1];
740
741     System.arraycopy(allconstructors, 0, scratch, 0, allconstructors.length);
742
743     scratch[allconstructors.length] = newctor;
744     allconstructors = scratch;
745
746     return newctor;
747   }
748
749   /**
750    * State that this class implements a specified interface.
751    * This does not yet update allMethods or otherwise
752    * attempt to inherit data.
753    *
754    * @param newifce com.sun.org.apache.xml.internal.utils.synthetic.Class representing the interface we want to add.
755    *
756    * @return The new interface class.
757    *
758    * @throws com.sun.org.apache.xml.internal.utils.synthetic.SynthesisException if the Class isn't an interface
759    */

760   public Class JavaDoc declareInterface(Class JavaDoc newifce) throws SynthesisException
761   {
762
763     if (realclass != null)
764       throw new SynthesisException(SynthesisException.REIFIED);
765
766     if (!newifce.isInterface())
767       throw new SynthesisException(SynthesisException.SYNTAX,
768                                    newifce.getName() + " isn't an interface");
769
770     Class JavaDoc[] scratch = new Class JavaDoc[interfaces.length + 1];
771
772     System.arraycopy(interfaces, 0, scratch, 0, interfaces.length);
773
774     scratch[interfaces.length] = newifce;
775     interfaces = scratch;
776     scratch = new Class JavaDoc[allclasses.length + 1];
777
778     System.arraycopy(allclasses, 0, scratch, 0, allclasses.length);
779
780     scratch[allclasses.length] = newifce;
781     allclasses = scratch;
782
783     return newifce;
784   }
785
786   /**
787    * Returns an array of Constructor objects reflecting
788    * all the constructors declared by the class
789    * represented by this Class object. These are public,
790    * protected, default (package) access, and private
791    * constructors. Returns an array of length 0 if this
792    * Class object represents an interface or a primitive
793    * type.
794    * <p>
795    * See The Java Language Specification, section 8.2.
796    *
797    *
798    * @return an array of Constructor objects reflecting
799    * all the constructors declared by the class
800    * represented by this Class object.
801    *
802    * @throws SecurityException
803    * if access to the information is denied.
804    */

805   public Constructor[] getDeclaredConstructors() throws SecurityException JavaDoc
806   {
807
808     if (realclass != null && declaredconstructors == null)
809     {
810       java.lang.reflect.Constructor JavaDoc[] realDC =
811         realclass.getDeclaredConstructors();
812
813       declaredconstructors = new Constructor[realDC.length];
814
815       for (int i = 0; i < realDC.length; ++i)
816       {
817         declaredconstructors[i] = new Constructor(realDC[i], this);
818       }
819     }
820
821     return declaredconstructors;
822   }
823
824   /**
825    * Returns a Field object that reflects the specified
826    * declared field of the class or interface represented
827    * by this Class object. The name parameter is a
828    * String that specifies the simple name of the desired
829    * field.
830    *
831    *
832    * @param name String that specifies the simple name of the desired
833    * field.
834    *
835    * @return a Field object that reflects the specified
836    * declared field of the class or interface represented
837    * by this Class object.
838    *
839    * @throws NoSuchFieldException
840    * if a field with the specified name is not found.
841    * @throws SecurityException
842    * if access to the information is denied.
843    */

844   public Field getDeclaredField(String JavaDoc name)
845           throws NoSuchFieldException JavaDoc, SecurityException JavaDoc
846   {
847     throw new java.lang.IllegalStateException JavaDoc();
848   }
849
850   /**
851    * Adds a Field description for the class or
852    * interface represented by this Class object
853    *
854    *
855    * @param name The name of the field.
856    *
857    * @return The field description.
858    *
859    * @throws SynthesisException
860    * if the class has been reified.
861    */

862   public Field declareField(String JavaDoc name) throws SynthesisException
863   {
864
865     if (realclass != null)
866       throw new SynthesisException(SynthesisException.REIFIED);
867
868     Field newfield = new Field(name, this);
869     Field[] scratch = new Field[declaredfields.length + 1];
870
871     System.arraycopy(declaredfields, 0, scratch, 0, declaredfields.length);
872
873     scratch[declaredfields.length] = newfield;
874     declaredfields = scratch;
875     scratch = new Field[allfields.length + 1];
876
877     System.arraycopy(allfields, 0, scratch, 0, allfields.length);
878
879     scratch[allfields.length] = newfield;
880     allfields = scratch;
881
882     return newfield;
883   }
884
885   /**
886    * Returns an array of Field objects reflecting all the
887    * fields declared by the class or interface represented
888    * by this Class object. This includes public,
889    * protected, default (package) access, and private
890    * fields, but excludes inherited fields. Returns an
891    * array of length 0 if the class or interface declares
892    * no fields, or if this Class object represents a
893    * primitive type. See The Java Language
894    * Specification, sections 8.2 and 8.3.
895    *
896    *
897    * @return array of Field objects reflecting all the
898    * fields declared by the class or interface represented
899    * by this Class object.
900    *
901    * @throws SecurityException
902    * if access to the information is denied.
903    */

904   public Field[] getDeclaredFields() throws SecurityException JavaDoc
905   {
906
907     if (realclass != null && declaredfields == null)
908     {
909       java.lang.reflect.Field JavaDoc[] realDF = realclass.getDeclaredFields();
910
911       declaredfields = new Field[realDF.length];
912
913       for (int i = 0; i < realDF.length; ++i)
914       {
915         declaredfields[i] = new Field(realDF[i], this);
916       }
917     }
918
919     return declaredfields;
920   }
921
922   /**
923    * Returns a Method object that reflects the specified
924    * declared method of the class or interface
925    * represented by this Class object. The name
926    * parameter is a String that specifies the simple
927    * name of the desired method, and the
928    * parameterTypes parameter is an array of Class
929    * objects that identify the method's formal parameter
930    * types, in declared order.
931    *
932    *
933    * @param name String that specifies the simple
934    * name of the desired method.
935    *
936    * @param parameterTypes array of Class
937    * objects that identify the method's formal parameter
938    * types, in declared order.
939    *
940    * @return Method object that reflects the specified
941    * declared method of the class or interface
942    * represented by this Class object.
943    *
944    * @throws NoSuchMethodException
945    * if a matching method is not found.
946    * @throws SecurityException
947    * if access to the information is denied.
948    */

949   public Method getDeclaredMethod(String JavaDoc name, Class JavaDoc parameterTypes[])
950           throws NoSuchMethodException JavaDoc, SecurityException JavaDoc
951   {
952     throw new java.lang.IllegalStateException JavaDoc();
953   }
954
955   /**
956    * Adds a Method description for the class or
957    * interface represented by this Class object
958    *
959    *
960    * @param name Name of method.
961    *
962    * @return The method object.
963    *
964    * @throws SynthesisException
965    * if the class has been reified.
966    */

967   public Method declareMethod(String JavaDoc name) throws SynthesisException
968   {
969
970     if (realclass != null)
971       throw new SynthesisException(SynthesisException.REIFIED);
972
973     Method newMethod = new Method(name, this);
974     Method[] scratch = new