KickJava   Java API By Example, From Geeks To Geeks.

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


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: Method.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 import com.sun.org.apache.xml.internal.utils.synthetic.SynthesisException;
22
23 /**
24  * A Method provides information about, and access to, a
25  * single method on a class or interface. The reflected
26  * method may be a class method or an instance method
27  * (including an abstract method).
28  * <p>
29  * A Method permits widening conversions to occur when
30  * matching the actual parameters to invokewith the
31  * underlying method's formal parameters, but it throws an
32  * IllegalArgumentException if a narrowing conversion
33  * would occur.
34  * <p>
35  * Need to add method body, a la Matt's codebuffer.
36  * That may or may not imply retaining the final return value
37  * separately and passing in a how-to-use-it mechanism...?
38  *
39  * @xsl.usage internal
40  */

41 public class Method extends EntryPoint implements Member
42 {
43
44   /**
45    * Insert the method's description here.
46    * <p>
47    * Creation date: (12-27-99 2:31:39 PM)
48    * @param realConstructor java.lang.reflect.Constructor
49    *
50    * @param name
51    * @param declaringclass
52    */

53   public Method(String JavaDoc name,
54                 com.sun.org.apache.xml.internal.utils.synthetic.Class declaringclass)
55   {
56
57     super(declaringclass);
58
59     this.name = name;
60   }
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 ctor
69    * @param declaringclass
70    */

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

85   public Method(java.lang.reflect.Method JavaDoc realmethod)
86   {
87     super(realmethod);
88   }
89
90   /**
91    * Returns a hashcode for this Method. The hashcode
92    * is computed as the exclusive-or of the hashcodes
93    * for the underlying method's declaring class name
94    * and the method's name.
95    *
96    */

97
98   /**
99    * Returns a hashcode for this Constructor. The
100    * hashcode for a Method is the hashcode for the
101    * underlying constructor's declaring class name,
102    * XORed with the name of this method.
103    */

104   public int hashCode()
105   {
106     return getDeclaringClass().getName().hashCode() ^ getName().hashCode();
107   }
108
109   /**
110    * Invokes the underlying method represented by this
111    * Method object, on the specified object with the
112    * specified parameters. Individual parameters are
113    * automatically unwrapped to match primitive
114    * formal parameters, and both primitive and
115    * reference parameters are subject to widening
116    * conversions as necessary. The value returned by
117    * the underlying method is automatically wrapped
118    * in an object if it has a primitive type.
119    *
120    * Method invocation proceeds with the following
121    * steps, in order:
122    *
123    * If the underlying method is static, then the
124    * specified object argument is ignored. It may be
125    * null.
126    *
127    * Otherwise, the method is an instance method. If
128    * the specified object argument is null, the
129    * invocation throws a NullPointerException.
130    * Otherwise, if the specified object argument is not
131    * an instance of the class or interface declaring the
132    * underlying method, the invocation throws an
133    * IllegalArgumentException.
134    *
135    * If this Method object enforces Java language access
136    * control and the underlying method is inaccessible,
137    * the invocation throws an IllegalAccessException.
138    *
139    * If the number of actual parameters supplied via
140    * args is different from the number of formal
141    * parameters required by the underlying method, the
142    * invocation throws an IllegalArgumentException.
143    *
144    * For each actual parameter in the supplied args
145    * array:
146    *
147    * If the corresponding formal parameter has a
148    * primitive type, an unwrapping conversion is
149    * attempted to convert the object value to a value of
150    * a primitive type. If this attempt fails, the
151    * invocation throws an IllegalArgumentException.
152    *
153    * If, after possible unwrapping, the parameter value
154    * cannot be converted to the corresponding formal
155    * parameter type by an identity or widening
156    * conversion, the invocation throws an
157    * IllegalArgumentException.
158    *
159    * If the underlying method is an instance method, it
160    * is invoked using dynamic method lookup as
161    * documented in The Java Language Specification,
162    * section 15.11.4.4; in particular, overriding based
163    * on the runtime type of the target object will occur.
164    *
165    * If the underlying method is static, it is invoked as
166    * exactly the method on the declaring class.
167    *
168    * Control transfers to the underlying method. If the
169    * method completes abruptly by throwing an
170    * exception, the exception is placed in an
171    * InvocationTargetException and thrown in turn to
172    * the caller of invoke.
173    *
174    * If the method completes normally, the value it
175    * returns is returned to the caller of invoke; if the
176    * value has a primitive type, it is first appropriately
177    * wrapped in an object. If the underlying method
178    * return type is void, the invocation returns null.
179    *
180    * Throws: IllegalAccessException
181    * if the underlying method is inaccessible.
182    * Throws: IllegalArgumentException
183    * if the number of actual and formal
184    * parameters differ, or if an unwrapping
185    * conversion fails.
186    * Throws: InvocationTargetException
187    * if the underlying method throws an
188    * exception.
189    * Throws: NullPointerException
190    * if the specified object is null.
191    *
192    * @param obj
193    * @param args
194    *
195    *
196    * @throws IllegalAccessException
197    * @throws IllegalArgumentException
198    * @throws java.lang.reflect.InvocationTargetException
199    */

200   public Object JavaDoc invoke(Object JavaDoc obj, Object JavaDoc args[])
201           throws IllegalAccessException JavaDoc, IllegalArgumentException JavaDoc,
202                  java.lang.reflect.InvocationTargetException JavaDoc
203   {
204
205     if (realep != null)
206       return ((java.lang.reflect.Method JavaDoc) realep).invoke(obj, args);
207     else
208       throw new IllegalAccessException JavaDoc(
209         "Un-reified com.sun.org.apache.xml.internal.utils.synthetic.Class doesn't yet support invocation");
210   }
211
212   /**
213    * Method setReturnType
214    *
215    *
216    * @param returntype
217    *
218    * @throws SynthesisException
219    */

220   public void setReturnType(com.sun.org.apache.xml.internal.utils.synthetic.Class returntype)
221           throws SynthesisException
222   {
223
224     if (realep != null)
225       throw new SynthesisException(SynthesisException.REIFIED);
226
227     this.returntype = returntype;
228   }
229 }
230
Popular Tags