KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xml > utils > synthetic > reflection > Constructor


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: Constructor.java,v 1.7 2004/02/17 04:24:21 minchau Exp $
18  */

19 package org.apache.xml.utils.synthetic.reflection;
20
21
22 /**
23  * Constructor provides information about, and access to, a
24  * single constructor for a class.
25  *
26  * Constructor permits widening conversions to occur when
27  * matching the actual parameters to newInstance() with
28  * the underlying constructor's formal parameters, but
29  * throws an IllegalArgumentException if a narrowing
30  * conversion would occur.
31  *
32  * @xsl.usage internal
33  */

34 public class Constructor extends EntryPoint implements Member
35 {
36
37   /**
38    * Actual Java class object. When present, all interactions
39    * are redirected to it. Allows our Class to function as a
40    * wrapper for the Java version (in lieu of subclassing or
41    * a shared Interface), and allows "in-place compilation"
42    * to replace a generated description with an
43    * directly runnable class.
44    */

45   private org.apache.xml.utils.synthetic.Class declaringclass = null;
46
47   /** Field realconstructor */
48   private java.lang.reflect.Constructor JavaDoc realconstructor = null;
49
50   /** Field parametertypes */
51   private org.apache.xml.utils.synthetic.Class[] parametertypes;
52
53   /** Field parameternames */
54   private String JavaDoc[] parameternames;
55
56   /** Field exceptiontypes */
57   private org.apache.xml.utils.synthetic.Class[] exceptiontypes;
58
59   /** Field modifiers */
60   private int modifiers;
61
62   /**
63    * Insert the method's description here.
64    * <p>
65    * Creation date: (12-27-99 2:31:39 PM)
66    * @param realConstructor java.lang.reflect.Constructor
67    *
68    * @param declaringclass
69    */

70   public Constructor(org.apache.xml.utils.synthetic.Class declaringclass)
71   {
72     super(declaringclass);
73   }
74
75   /**
76    * Insert the method's description here.
77    * <p>
78    * Creation date: (12-27-99 2:31:39 PM)
79    * @param realConstructor java.lang.reflect.Constructor
80    *
81    * @param ctor
82    * @param declaringclass
83    */

84   public Constructor(java.lang.reflect.Constructor JavaDoc ctor,
85                      org.apache.xml.utils.synthetic.Class declaringclass)
86   {
87     super(ctor, declaringclass);
88   }
89
90   /**
91    * Insert the method's description here.
92    * <p>
93    * Creation date: (12-27-99 2:31:39 PM)
94    * @param realConstructor java.lang.reflect.Constructor
95    *
96    * @param realconstructor
97    */

98   public Constructor(java.lang.reflect.Constructor JavaDoc realconstructor)
99   {
100     super(realconstructor);
101   }
102
103   /**
104    * Returns a hashcode for this Constructor. The
105    * hashcode is the same as the hashcode for the
106    * underlying constructor's declaring class name.
107    *
108    * ($objectName$) @return
109    */

110   public int hashCode()
111   {
112     return getDeclaringClass().getName().hashCode();
113   }
114
115   /**
116    * Uses the constructor represented by this
117    * Constructor object to create and initialize a new
118    * instance of the constructor's declaring class, with
119    * the specified initialization parameters. Individual
120    * parameters are automatically unwrapped to match
121    * primitive formal parameters, and both primitive
122    * and reference parameters are subject to widening
123    * conversions as necessary. Returns the newly
124    * created and initialized object.
125    * <p>
126    * Creation proceeds with the following steps, in
127    * order:
128    * <p>
129    * If the class that declares the underlying constructor
130    * represents an abstract class, the creation throws an
131    * InstantiationException.
132    * <p>
133    * If this Constructor object enforces Java language
134    * access control and the underlying constructor is
135    * inaccessible, the creation throws an
136    * IllegalAccessException.
137    * <p>
138    * If the number of actual parameters supplied via
139    * initargs is different from the number of formal
140    * parameters required by the underlying constructor,
141    * the creation throws an IllegalArgumentException.
142    * <p>
143    * A new instance of the constructor's declaring class
144    * is created, and its fields are initialized to their
145    * default initial values.
146    * <p>
147    * For each actual parameter in the supplied initargs
148    * array:
149    * <p>
150    * If the corresponding formal parameter has a
151    * primitive type, an unwrapping conversion is
152    * attempted to convert the object value to a value of
153    * the primitive type. If this attempt fails, the
154    * creation throws an IllegalArgumentException.
155    * <p>
156    *
157    * If, after possible unwrapping, the parameter value
158    * cannot be converted to the corresponding formal
159    * parameter type by an identity or widening
160    * conversion, the creation throws an
161    * IllegalArgumentException.
162    * <p>
163    * Control transfers to the underlying constructor to
164    * initialize the new instance. If the constructor
165    * completes abruptly by throwing an exception, the
166    * exception is placed in an
167    * InvocationTargetException and thrown in turn to
168    * the caller of newInstance.
169    * <p>
170    * If the constructor completes normally, returns the
171    * newly created and initialized instance.
172    *
173    *
174    * @param initargs initialization arguments.
175    *
176    * @return The new instance.
177    * @throws IllegalAccessException
178    * if the underlying constructor is inaccessible.
179    * @throws IllegalArgumentException
180    * if the number of actual and formal
181    * parameters differ, or if an unwrapping
182    * conversion fails.
183    * @throws InstantiationException
184    * if the class that declares the underlying
185    * constructor represents an abstract class.
186    * @throws InvocationTargetException
187    * if the underlying constructor throws an
188    * exception.
189    * @throws java.lang.reflect.InvocationTargetException
190    */

191   public Object JavaDoc newInstance(Object JavaDoc initargs[])
192           throws InstantiationException JavaDoc, IllegalAccessException JavaDoc,
193                  IllegalArgumentException JavaDoc,
194                  java.lang.reflect.InvocationTargetException JavaDoc
195   {
196
197     if (realep != null)
198       return ((java.lang.reflect.Constructor JavaDoc) realep).newInstance(initargs);
199     else
200       throw new InstantiationException JavaDoc(
201         "Un-reified org.apache.xml.utils.synthetic.Class doesn't yet support invocation");
202   }
203 }
204
Popular Tags