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: /**
033: * Represents an introspected java class.
034: */
035: public class JClassArray extends JClass {
036: private JClass _componentType;
037:
038: JClassArray(JClass component) {
039: if (component == null)
040: throw new NullPointerException();
041:
042: _componentType = component;
043: }
044:
045: /**
046: * Returns the class name.
047: */
048: public String getName() {
049: return "[" + _componentType.getName();
050: }
051:
052: /**
053: * Returns true for a primitive class.
054: */
055: public boolean isPrimitive() {
056: return false;
057: }
058:
059: /**
060: * Returns true for a public class.
061: */
062: public boolean isPublic() {
063: return true;
064: }
065:
066: /**
067: * Returns true for an abstract class
068: */
069: public boolean isAbstract() {
070: return false;
071: }
072:
073: /**
074: * Returns true for a final class
075: */
076: public boolean isFinal() {
077: return true;
078: }
079:
080: /**
081: * Returns true for an interface
082: */
083: public boolean isInterface() {
084: return false;
085: }
086:
087: /**
088: * Returns the superclass.
089: */
090: public JClass getSuperClass() {
091: return JClass.OBJECT;
092: }
093:
094: /**
095: * Returns the interfaces.
096: */
097: public JClass[] getInterfaces() {
098: return new JClass[0];
099: }
100:
101: /**
102: * Returns the constructors
103: */
104: public JMethod[] getConstructors() {
105: return new JMethod[0];
106: }
107:
108: /**
109: * Returns true for an array class.
110: */
111: public boolean isArray() {
112: return true;
113: }
114:
115: /**
116: * Returns the component for a class.
117: */
118: public JClass getComponentType() {
119: return _componentType;
120: }
121:
122: /**
123: * Returns true if the jClass is assignable to the class.
124: */
125: public boolean isAssignableTo(Class cl) {
126: return getName().equals(cl.getName());
127: }
128:
129: /**
130: * Returns true if the jClass is assignable to the class.
131: */
132: public boolean isAssignableFrom(Class cl) {
133: return getName().equals(cl.getName());
134: }
135:
136: /**
137: * Returns true if the jClass is assignable to the class.
138: */
139: public boolean isAssignableFrom(JClass cl) {
140: return getName().equals(cl.getName());
141: }
142:
143: /**
144: * Returns the declared methods
145: */
146: public JMethod[] getDeclaredMethods() {
147: return new JMethod[0];
148: }
149:
150: /**
151: * Returns the public methods
152: */
153: public JMethod[] getMethods() {
154: return new JMethod[0];
155: }
156:
157: /**
158: * Returns the matching method.
159: */
160: public JMethod getMethod(String name, JClass[] param) {
161: return null;
162: }
163:
164: /**
165: * Returns the declared fields
166: */
167: public JField[] getDeclaredFields() {
168: return new JField[0];
169: }
170:
171: /**
172: * Returns the fields
173: */
174: public JField[] getFields() {
175: return new JField[0];
176: }
177:
178: /**
179: * Returns the printable name.
180: */
181: public String getPrintName() {
182: if (isArray())
183: return getComponentType().getPrintName() + "[]";
184: else
185: return getName();
186: }
187:
188: /**
189: * Returns a printable version of a class.
190: */
191: public String getShortName() {
192: if (isArray())
193: return getComponentType().getShortName() + "[]";
194: else {
195: String name = getName();
196:
197: int p = name.lastIndexOf('.');
198:
199: if (p >= 0)
200: return name.substring(p + 1);
201: else
202: return name;
203: }
204: }
205:
206: /**
207: * Returns the hash code
208: */
209: public int hashCode() {
210: return getName().hashCode();
211: }
212:
213: /**
214: * Returns true if equals.
215: */
216: public boolean equals(Object o) {
217: if (o == this )
218: return true;
219: else if (o == null || getClass() != o.getClass())
220: return false;
221:
222: JClass jClass = (JClass) o;
223:
224: // note that the equality test doesn't include the class loader
225: return getName().equals(jClass.getName());
226: }
227:
228: public String toString() {
229: return "JClass[" + getName() + "]";
230: }
231: }
|