1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 1999 The Apache Software Foundation. All rights
  6. * reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Xalan" and "Apache Software Foundation" must
  28. * not be used to endorse or promote products derived from this
  29. * software without prior written permission. For written
  30. * permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * nor may "Apache" appear in their name, without prior written
  34. * permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation and was
  52. * originally based on software copyright (c) 1999, Lotus
  53. * Development Corporation., http://www.lotus.com. For more
  54. * information on the Apache Software Foundation, please see
  55. * <http://www.apache.org/>.
  56. */
  57. package org.apache.xml.utils.synthetic.reflection;
  58. import java.lang.reflect.InvocationTargetException;
  59. import org.apache.xml.utils.synthetic.SynthesisException;
  60. /**
  61. * <meta name="usage" content="internal"/>
  62. * Constructor provides information about, and access to, a
  63. * single constructor for a class.
  64. *
  65. * Constructor permits widening conversions to occur when
  66. * matching the actual parameters to newInstance() with
  67. * the underlying constructor's formal parameters, but
  68. * throws an IllegalArgumentException if a narrowing
  69. * conversion would occur.
  70. *
  71. */
  72. public class Constructor extends EntryPoint implements Member
  73. {
  74. /**
  75. * Actual Java class object. When present, all interactions
  76. * are redirected to it. Allows our Class to function as a
  77. * wrapper for the Java version (in lieu of subclassing or
  78. * a shared Interface), and allows "in-place compilation"
  79. * to replace a generated description with an
  80. * directly runnable class.
  81. */
  82. private org.apache.xml.utils.synthetic.Class declaringclass = null;
  83. /** Field realconstructor */
  84. private java.lang.reflect.Constructor realconstructor = null;
  85. /** Field parametertypes */
  86. private org.apache.xml.utils.synthetic.Class[] parametertypes;
  87. /** Field parameternames */
  88. private String[] parameternames;
  89. /** Field exceptiontypes */
  90. private org.apache.xml.utils.synthetic.Class[] exceptiontypes;
  91. /** Field modifiers */
  92. private int modifiers;
  93. /**
  94. * Insert the method's description here.
  95. * <p>
  96. * Creation date: (12-27-99 2:31:39 PM)
  97. * @param realConstructor java.lang.reflect.Constructor
  98. *
  99. * @param declaringclass
  100. */
  101. public Constructor(org.apache.xml.utils.synthetic.Class declaringclass)
  102. {
  103. super(declaringclass);
  104. }
  105. /**
  106. * Insert the method's description here.
  107. * <p>
  108. * Creation date: (12-27-99 2:31:39 PM)
  109. * @param realConstructor java.lang.reflect.Constructor
  110. *
  111. * @param ctor
  112. * @param declaringclass
  113. */
  114. public Constructor(java.lang.reflect.Constructor ctor,
  115. org.apache.xml.utils.synthetic.Class declaringclass)
  116. {
  117. super(ctor, declaringclass);
  118. }
  119. /**
  120. * Insert the method's description here.
  121. * <p>
  122. * Creation date: (12-27-99 2:31:39 PM)
  123. * @param realConstructor java.lang.reflect.Constructor
  124. *
  125. * @param realconstructor
  126. */
  127. public Constructor(java.lang.reflect.Constructor realconstructor)
  128. {
  129. super(realconstructor);
  130. }
  131. /**
  132. * Returns a hashcode for this Constructor. The
  133. * hashcode is the same as the hashcode for the
  134. * underlying constructor's declaring class name.
  135. *
  136. * ($objectName$) @return
  137. */
  138. public int hashCode()
  139. {
  140. return getDeclaringClass().getName().hashCode();
  141. }
  142. /**
  143. * Uses the constructor represented by this
  144. * Constructor object to create and initialize a new
  145. * instance of the constructor's declaring class, with
  146. * the specified initialization parameters. Individual
  147. * parameters are automatically unwrapped to match
  148. * primitive formal parameters, and both primitive
  149. * and reference parameters are subject to widening
  150. * conversions as necessary. Returns the newly
  151. * created and initialized object.
  152. * <p>
  153. * Creation proceeds with the following steps, in
  154. * order:
  155. * <p>
  156. * If the class that declares the underlying constructor
  157. * represents an abstract class, the creation throws an
  158. * InstantiationException.
  159. * <p>
  160. * If this Constructor object enforces Java language
  161. * access control and the underlying constructor is
  162. * inaccessible, the creation throws an
  163. * IllegalAccessException.
  164. * <p>
  165. * If the number of actual parameters supplied via
  166. * initargs is different from the number of formal
  167. * parameters required by the underlying constructor,
  168. * the creation throws an IllegalArgumentException.
  169. * <p>
  170. * A new instance of the constructor's declaring class
  171. * is created, and its fields are initialized to their
  172. * default initial values.
  173. * <p>
  174. * For each actual parameter in the supplied initargs
  175. * array:
  176. * <p>
  177. * If the corresponding formal parameter has a
  178. * primitive type, an unwrapping conversion is
  179. * attempted to convert the object value to a value of
  180. * the primitive type. If this attempt fails, the
  181. * creation throws an IllegalArgumentException.
  182. * <p>
  183. *
  184. * If, after possible unwrapping, the parameter value
  185. * cannot be converted to the corresponding formal
  186. * parameter type by an identity or widening
  187. * conversion, the creation throws an
  188. * IllegalArgumentException.
  189. * <p>
  190. * Control transfers to the underlying constructor to
  191. * initialize the new instance. If the constructor
  192. * completes abruptly by throwing an exception, the
  193. * exception is placed in an
  194. * InvocationTargetException and thrown in turn to
  195. * the caller of newInstance.
  196. * <p>
  197. * If the constructor completes normally, returns the
  198. * newly created and initialized instance.
  199. *
  200. *
  201. * @param initargs initialization arguments.
  202. *
  203. * @return The new instance.
  204. * @throws IllegalAccessException
  205. * if the underlying constructor is inaccessible.
  206. * @throws IllegalArgumentException
  207. * if the number of actual and formal
  208. * parameters differ, or if an unwrapping
  209. * conversion fails.
  210. * @throws InstantiationException
  211. * if the class that declares the underlying
  212. * constructor represents an abstract class.
  213. * @throws InvocationTargetException
  214. * if the underlying constructor throws an
  215. * exception.
  216. * @throws java.lang.reflect.InvocationTargetException
  217. */
  218. public Object newInstance(Object initargs[])
  219. throws InstantiationException, IllegalAccessException,
  220. IllegalArgumentException,
  221. java.lang.reflect.InvocationTargetException
  222. {
  223. if (realep != null)
  224. return ((java.lang.reflect.Constructor) realep).newInstance(initargs);
  225. else
  226. throw new InstantiationException(
  227. "Un-reified org.apache.xml.utils.synthetic.Class doesn't yet support invocation");
  228. }
  229. }