001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.bytecode;
031:
032: import java.lang.reflect.Constructor;
033: import java.lang.reflect.Modifier;
034:
035: /**
036: * Wrapper around the Java Constructor for a JMethod.
037: */
038: public class JConstructorWrapper extends JMethod {
039: private JClassLoader _loader;
040:
041: private Constructor _method;
042:
043: public JConstructorWrapper(Constructor method, JClassLoader loader) {
044: if (loader == null)
045: throw new NullPointerException();
046:
047: _method = method;
048: _loader = loader;
049: }
050:
051: /**
052: * Returns the method name.
053: */
054: public String getName() {
055: return _method.getName();
056: }
057:
058: /**
059: * Returns true for a static method.
060: */
061: public boolean isStatic() {
062: return Modifier.isStatic(_method.getModifiers());
063: }
064:
065: /**
066: * Returns true for a private method
067: */
068: public boolean isPrivate() {
069: return Modifier.isPrivate(_method.getModifiers());
070: }
071:
072: /**
073: * Returns true for a public method.
074: */
075: public boolean isPublic() {
076: return Modifier.isPublic(_method.getModifiers());
077: }
078:
079: /**
080: * Returns true for a protected method.
081: */
082: public boolean isProtected() {
083: return Modifier.isProtected(_method.getModifiers());
084: }
085:
086: /**
087: * Returns true for a final method.
088: */
089: public boolean isFinal() {
090: return Modifier.isFinal(_method.getModifiers());
091: }
092:
093: /**
094: * Returns true for an abstract method.
095: */
096: public boolean isAbstract() {
097: return Modifier.isAbstract(_method.getModifiers());
098: }
099:
100: /**
101: * Returns the declaring type.
102: */
103: public JClass getDeclaringClass() {
104: return _loader.forName(_method.getDeclaringClass().getName());
105: }
106:
107: /**
108: * Returns the return type.
109: */
110: public JClass getReturnType() {
111: throw new UnsupportedOperationException();
112: }
113:
114: /**
115: * Returns the return type.
116: */
117: public JType getGenericReturnType() {
118: throw new UnsupportedOperationException();
119: }
120:
121: /**
122: * Returns the parameter types.
123: */
124: public JClass[] getParameterTypes() {
125: Class[] types = _method.getParameterTypes();
126:
127: JClass[] jTypes = new JClass[types.length];
128:
129: for (int i = 0; i < types.length; i++) {
130: jTypes[i] = _loader.forName(types[i].getName());
131: }
132:
133: return jTypes;
134: }
135:
136: /**
137: * Returns the exception types.
138: */
139: public JClass[] getExceptionTypes() {
140: Class[] types = _method.getExceptionTypes();
141:
142: JClass[] jTypes = new JClass[types.length];
143:
144: for (int i = 0; i < types.length; i++) {
145: jTypes[i] = _loader.forName(types[i].getName());
146: }
147:
148: return jTypes;
149: }
150:
151: /**
152: * Returns the annotations.
153: */
154: public JAnnotation[] getDeclaredAnnotations() {
155: return new JAnnotation[0];
156: }
157: }
|