KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > bytecode > JMethodWrapper


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.bytecode;
31
32 import java.lang.reflect.Method JavaDoc;
33 import java.lang.reflect.Modifier JavaDoc;
34 import java.lang.reflect.ParameterizedType JavaDoc;
35 import java.lang.reflect.Type JavaDoc;
36
37 /**
38  * Wrapper around the Java Method for a JMethod.
39  */

40 public class JMethodWrapper extends JMethod {
41   private JClassLoader _loader;
42
43   private Method JavaDoc _method;
44
45   public JMethodWrapper(Method JavaDoc method, JClassLoader loader)
46   {
47     if (loader == null)
48       throw new NullPointerException JavaDoc();
49
50     _method = method;
51     _loader = loader;
52   }
53
54   /**
55    * Returns the method name.
56    */

57   public String JavaDoc getName()
58   {
59     return _method.getName();
60   }
61
62   /**
63    * Returns true for a static method.
64    */

65   public boolean isStatic()
66   {
67     return Modifier.isStatic(_method.getModifiers());
68   }
69
70   /**
71    * Returns true for a private method
72    */

73   public boolean isPrivate()
74   {
75     return Modifier.isPrivate(_method.getModifiers());
76   }
77
78   /**
79    * Returns true for a public method.
80    */

81   public boolean isPublic()
82   {
83     return Modifier.isPublic(_method.getModifiers());
84   }
85
86   /**
87    * Returns true for a final method.
88    */

89   public boolean isFinal()
90   {
91     return Modifier.isFinal(_method.getModifiers());
92   }
93
94   /**
95    * Returns true for an abstract method.
96    */

97   public boolean isAbstract()
98   {
99     return Modifier.isAbstract(_method.getModifiers());
100   }
101
102   /**
103    * Returns the declaring type.
104    */

105   public JClass getDeclaringClass()
106   {
107     return _loader.forName(_method.getDeclaringClass().getName());
108   }
109
110   /**
111    * Returns the return type.
112    */

113   public JClass getReturnType()
114   {
115     return _loader.forName(_method.getReturnType().getName());
116   }
117
118   /**
119    * Returns the return type.
120    */

121   public JType getGenericReturnType()
122   {
123     try {
124       Type JavaDoc retType = _method.getGenericReturnType();
125
126       if (retType instanceof Class JavaDoc)
127   return _loader.forName(((Class JavaDoc) retType).getName());
128       else
129   return new JTypeWrapper(_loader, (ParameterizedType JavaDoc) retType);
130     } catch (NoSuchMethodError JavaDoc e) {
131       return getReturnType();
132     }
133
134   }
135
136   /**
137    * Returns the parameter types.
138    */

139   public JClass []getParameterTypes()
140   {
141     Class JavaDoc []types = _method.getParameterTypes();
142
143     JClass []jTypes = new JClass[types.length];
144
145     for (int i = 0; i < types.length; i++) {
146       jTypes[i] = _loader.forName(types[i].getName());
147     }
148
149     return jTypes;
150   }
151
152   /**
153    * Returns the exception types.
154    */

155   public JClass []getExceptionTypes()
156   {
157     Class JavaDoc []types = _method.getExceptionTypes();
158
159     JClass []jTypes = new JClass[types.length];
160
161     for (int i = 0; i < types.length; i++) {
162       jTypes[i] = _loader.forName(types[i].getName());
163     }
164
165     return jTypes;
166   }
167
168   /**
169    * Returns the annotations.
170    */

171   public JAnnotation []getDeclaredAnnotations()
172   {
173     return new JAnnotation[0];
174   }
175 }
176
Popular Tags