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. * A Method provides information about, and access to, a
  63. * single method on a class or interface. The reflected
  64. * method may be a class method or an instance method
  65. * (including an abstract method).
  66. * <p>
  67. * A Method permits widening conversions to occur when
  68. * matching the actual parameters to invokewith the
  69. * underlying method's formal parameters, but it throws an
  70. * IllegalArgumentException if a narrowing conversion
  71. * would occur.
  72. * <p>
  73. * Need to add method body, a la Matt's codebuffer.
  74. * That may or may not imply retaining the final return value
  75. * separately and passing in a how-to-use-it mechanism...?
  76. *
  77. */
  78. public class Method extends EntryPoint implements Member
  79. {
  80. /**
  81. * Insert the method's description here.
  82. * <p>
  83. * Creation date: (12-27-99 2:31:39 PM)
  84. * @param realConstructor java.lang.reflect.Constructor
  85. *
  86. * @param name
  87. * @param declaringclass
  88. */
  89. public Method(String name,
  90. org.apache.xml.utils.synthetic.Class declaringclass)
  91. {
  92. super(declaringclass);
  93. this.name = name;
  94. }
  95. /**
  96. * Insert the method's description here.
  97. * <p>
  98. * Creation date: (12-27-99 2:31:39 PM)
  99. * @param realConstructor java.lang.reflect.Constructor
  100. *
  101. * @param ctor
  102. * @param declaringclass
  103. */
  104. public Method(java.lang.reflect.Method ctor,
  105. org.apache.xml.utils.synthetic.Class declaringclass)
  106. {
  107. super(ctor, declaringclass);
  108. }
  109. /**
  110. * Insert the method's description here.
  111. * <p>
  112. * Creation date: (12-27-99 2:31:39 PM)
  113. * @param realConstructor java.lang.reflect.Constructor
  114. *
  115. * @param realmethod
  116. */
  117. public Method(java.lang.reflect.Method realmethod)
  118. {
  119. super(realmethod);
  120. }
  121. /**
  122. * Returns a hashcode for this Method. The hashcode
  123. * is computed as the exclusive-or of the hashcodes
  124. * for the underlying method's declaring class name
  125. * and the method's name.
  126. *
  127. */
  128. /**
  129. * Returns a hashcode for this Constructor. The
  130. * hashcode for a Method is the hashcode for the
  131. * underlying constructor's declaring class name,
  132. * XORed with the name of this method.
  133. */
  134. public int hashCode()
  135. {
  136. return getDeclaringClass().getName().hashCode() ^ getName().hashCode();
  137. }
  138. /**
  139. * Invokes the underlying method represented by this
  140. * Method object, on the specified object with the
  141. * specified parameters. Individual parameters are
  142. * automatically unwrapped to match primitive
  143. * formal parameters, and both primitive and
  144. * reference parameters are subject to widening
  145. * conversions as necessary. The value returned by
  146. * the underlying method is automatically wrapped
  147. * in an object if it has a primitive type.
  148. *
  149. * Method invocation proceeds with the following
  150. * steps, in order:
  151. *
  152. * If the underlying method is static, then the
  153. * specified object argument is ignored. It may be
  154. * null.
  155. *
  156. * Otherwise, the method is an instance method. If
  157. * the specified object argument is null, the
  158. * invocation throws a NullPointerException.
  159. * Otherwise, if the specified object argument is not
  160. * an instance of the class or interface declaring the
  161. * underlying method, the invocation throws an
  162. * IllegalArgumentException.
  163. *
  164. * If this Method object enforces Java language access
  165. * control and the underlying method is inaccessible,
  166. * the invocation throws an IllegalAccessException.
  167. *
  168. * If the number of actual parameters supplied via
  169. * args is different from the number of formal
  170. * parameters required by the underlying method, the
  171. * invocation throws an IllegalArgumentException.
  172. *
  173. * For each actual parameter in the supplied args
  174. * array:
  175. *
  176. * If the corresponding formal parameter has a
  177. * primitive type, an unwrapping conversion is
  178. * attempted to convert the object value to a value of
  179. * a primitive type. If this attempt fails, the
  180. * invocation throws an IllegalArgumentException.
  181. *
  182. * If, after possible unwrapping, the parameter value
  183. * cannot be converted to the corresponding formal
  184. * parameter type by an identity or widening
  185. * conversion, the invocation throws an
  186. * IllegalArgumentException.
  187. *
  188. * If the underlying method is an instance method, it
  189. * is invoked using dynamic method lookup as
  190. * documented in The Java Language Specification,
  191. * section 15.11.4.4; in particular, overriding based
  192. * on the runtime type of the target object will occur.
  193. *
  194. * If the underlying method is static, it is invoked as
  195. * exactly the method on the declaring class.
  196. *
  197. * Control transfers to the underlying method. If the
  198. * method completes abruptly by throwing an
  199. * exception, the exception is placed in an
  200. * InvocationTargetException and thrown in turn to
  201. * the caller of invoke.
  202. *
  203. * If the method completes normally, the value it
  204. * returns is returned to the caller of invoke; if the
  205. * value has a primitive type, it is first appropriately
  206. * wrapped in an object. If the underlying method
  207. * return type is void, the invocation returns null.
  208. *
  209. * Throws: IllegalAccessException
  210. * if the underlying method is inaccessible.
  211. * Throws: IllegalArgumentException
  212. * if the number of actual and formal
  213. * parameters differ, or if an unwrapping
  214. * conversion fails.
  215. * Throws: InvocationTargetException
  216. * if the underlying method throws an
  217. * exception.
  218. * Throws: NullPointerException
  219. * if the specified object is null.
  220. *
  221. * @param obj
  222. * @param args
  223. *
  224. *
  225. * @throws IllegalAccessException
  226. * @throws IllegalArgumentException
  227. * @throws java.lang.reflect.InvocationTargetException
  228. */
  229. public Object invoke(Object obj, Object args[])
  230. throws IllegalAccessException, IllegalArgumentException,
  231. java.lang.reflect.InvocationTargetException
  232. {
  233. if (realep != null)
  234. return ((java.lang.reflect.Method) realep).invoke(obj, args);
  235. else
  236. throw new IllegalAccessException(
  237. "Un-reified org.apache.xml.utils.synthetic.Class doesn't yet support invocation");
  238. }
  239. /**
  240. * Method setReturnType
  241. *
  242. *
  243. * @param returntype
  244. *
  245. * @throws SynthesisException
  246. */
  247. public void setReturnType(org.apache.xml.utils.synthetic.Class returntype)
  248. throws SynthesisException
  249. {
  250. if (realep != null)
  251. throw new SynthesisException(SynthesisException.REIFIED);
  252. this.returntype = returntype;
  253. }
  254. }