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 com.sun.org.apache.xml.internal.utils.synthetic.reflection;
  20. /**
  21. * Constructor provides information about, and access to, a
  22. * single constructor for a class.
  23. *
  24. * Constructor permits widening conversions to occur when
  25. * matching the actual parameters to newInstance() with
  26. * the underlying constructor's formal parameters, but
  27. * throws an IllegalArgumentException if a narrowing
  28. * conversion would occur.
  29. *
  30. * @xsl.usage internal
  31. */
  32. public class Constructor extends EntryPoint implements Member
  33. {
  34. /**
  35. * Actual Java class object. When present, all interactions
  36. * are redirected to it. Allows our Class to function as a
  37. * wrapper for the Java version (in lieu of subclassing or
  38. * a shared Interface), and allows "in-place compilation"
  39. * to replace a generated description with an
  40. * directly runnable class.
  41. */
  42. private com.sun.org.apache.xml.internal.utils.synthetic.Class declaringclass = null;
  43. /** Field realconstructor */
  44. private java.lang.reflect.Constructor realconstructor = null;
  45. /** Field parametertypes */
  46. private com.sun.org.apache.xml.internal.utils.synthetic.Class[] parametertypes;
  47. /** Field parameternames */
  48. private String[] parameternames;
  49. /** Field exceptiontypes */
  50. private com.sun.org.apache.xml.internal.utils.synthetic.Class[] exceptiontypes;
  51. /** Field modifiers */
  52. private int modifiers;
  53. /**
  54. * Insert the method's description here.
  55. * <p>
  56. * Creation date: (12-27-99 2:31:39 PM)
  57. * @param realConstructor java.lang.reflect.Constructor
  58. *
  59. * @param declaringclass
  60. */
  61. public Constructor(com.sun.org.apache.xml.internal.utils.synthetic.Class declaringclass)
  62. {
  63. super(declaringclass);
  64. }
  65. /**
  66. * Insert the method's description here.
  67. * <p>
  68. * Creation date: (12-27-99 2:31:39 PM)
  69. * @param realConstructor java.lang.reflect.Constructor
  70. *
  71. * @param ctor
  72. * @param declaringclass
  73. */
  74. public Constructor(java.lang.reflect.Constructor ctor,
  75. com.sun.org.apache.xml.internal.utils.synthetic.Class declaringclass)
  76. {
  77. super(ctor, declaringclass);
  78. }
  79. /**
  80. * Insert the method's description here.
  81. * <p>
  82. * Creation date: (12-27-99 2:31:39 PM)
  83. * @param realConstructor java.lang.reflect.Constructor
  84. *
  85. * @param realconstructor
  86. */
  87. public Constructor(java.lang.reflect.Constructor realconstructor)
  88. {
  89. super(realconstructor);
  90. }
  91. /**
  92. * Returns a hashcode for this Constructor. The
  93. * hashcode is the same as the hashcode for the
  94. * underlying constructor's declaring class name.
  95. *
  96. * ($objectName$) @return
  97. */
  98. public int hashCode()
  99. {
  100. return getDeclaringClass().getName().hashCode();
  101. }
  102. /**
  103. * Uses the constructor represented by this
  104. * Constructor object to create and initialize a new
  105. * instance of the constructor's declaring class, with
  106. * the specified initialization parameters. Individual
  107. * parameters are automatically unwrapped to match
  108. * primitive formal parameters, and both primitive
  109. * and reference parameters are subject to widening
  110. * conversions as necessary. Returns the newly
  111. * created and initialized object.
  112. * <p>
  113. * Creation proceeds with the following steps, in
  114. * order:
  115. * <p>
  116. * If the class that declares the underlying constructor
  117. * represents an abstract class, the creation throws an
  118. * InstantiationException.
  119. * <p>
  120. * If this Constructor object enforces Java language
  121. * access control and the underlying constructor is
  122. * inaccessible, the creation throws an
  123. * IllegalAccessException.
  124. * <p>
  125. * If the number of actual parameters supplied via
  126. * initargs is different from the number of formal
  127. * parameters required by the underlying constructor,
  128. * the creation throws an IllegalArgumentException.
  129. * <p>
  130. * A new instance of the constructor's declaring class
  131. * is created, and its fields are initialized to their
  132. * default initial values.
  133. * <p>
  134. * For each actual parameter in the supplied initargs
  135. * array:
  136. * <p>
  137. * If the corresponding formal parameter has a
  138. * primitive type, an unwrapping conversion is
  139. * attempted to convert the object value to a value of
  140. * the primitive type. If this attempt fails, the
  141. * creation throws an IllegalArgumentException.
  142. * <p>
  143. *
  144. * If, after possible unwrapping, the parameter value
  145. * cannot be converted to the corresponding formal
  146. * parameter type by an identity or widening
  147. * conversion, the creation throws an
  148. * IllegalArgumentException.
  149. * <p>
  150. * Control transfers to the underlying constructor to
  151. * initialize the new instance. If the constructor
  152. * completes abruptly by throwing an exception, the
  153. * exception is placed in an
  154. * InvocationTargetException and thrown in turn to
  155. * the caller of newInstance.
  156. * <p>
  157. * If the constructor completes normally, returns the
  158. * newly created and initialized instance.
  159. *
  160. *
  161. * @param initargs initialization arguments.
  162. *
  163. * @return The new instance.
  164. * @throws IllegalAccessException
  165. * if the underlying constructor is inaccessible.
  166. * @throws IllegalArgumentException
  167. * if the number of actual and formal
  168. * parameters differ, or if an unwrapping
  169. * conversion fails.
  170. * @throws InstantiationException
  171. * if the class that declares the underlying
  172. * constructor represents an abstract class.
  173. * @throws InvocationTargetException
  174. * if the underlying constructor throws an
  175. * exception.
  176. * @throws java.lang.reflect.InvocationTargetException
  177. */
  178. public Object newInstance(Object initargs[])
  179. throws InstantiationException, IllegalAccessException,
  180. IllegalArgumentException,
  181. java.lang.reflect.InvocationTargetException
  182. {
  183. if (realep != null)
  184. return ((java.lang.reflect.Constructor) realep).newInstance(initargs);
  185. else
  186. throw new InstantiationException(
  187. "Un-reified com.sun.org.apache.xml.internal.utils.synthetic.Class doesn't yet support invocation");
  188. }
  189. }