KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
33  * Represents an introspected java class.
34  */

35 public class JClassArray extends JClass {
36   private JClass _componentType;
37
38   JClassArray(JClass component)
39   {
40     if (component == null)
41       throw new NullPointerException JavaDoc();
42     
43     _componentType = component;
44   }
45   
46   /**
47    * Returns the class name.
48    */

49   public String JavaDoc getName()
50   {
51     return "[" + _componentType.getName();
52   }
53   
54   /**
55    * Returns true for a primitive class.
56    */

57   public boolean isPrimitive()
58   {
59     return false;
60   }
61   
62   /**
63    * Returns true for a public class.
64    */

65   public boolean isPublic()
66   {
67     return true;
68   }
69   
70   /**
71    * Returns true for an abstract class
72    */

73   public boolean isAbstract()
74   {
75     return false;
76   }
77   
78   /**
79    * Returns true for a final class
80    */

81   public boolean isFinal()
82   {
83     return true;
84   }
85   
86   /**
87    * Returns true for an interface
88    */

89   public boolean isInterface()
90   {
91     return false;
92   }
93
94   /**
95    * Returns the superclass.
96    */

97   public JClass getSuperClass()
98   {
99     return JClass.OBJECT;
100   }
101
102   /**
103    * Returns the interfaces.
104    */

105   public JClass []getInterfaces()
106   {
107     return new JClass[0];
108   }
109
110   /**
111    * Returns the constructors
112    */

113   public JMethod []getConstructors()
114   {
115     return new JMethod[0];
116   }
117
118   /**
119    * Returns true for an array class.
120    */

121   public boolean isArray()
122   {
123     return true;
124   }
125
126   /**
127    * Returns the component for a class.
128    */

129   public JClass getComponentType()
130   {
131     return _componentType;
132   }
133
134   /**
135    * Returns true if the jClass is assignable to the class.
136    */

137   public boolean isAssignableTo(Class JavaDoc cl)
138   {
139     return getName().equals(cl.getName());
140   }
141
142   /**
143    * Returns true if the jClass is assignable to the class.
144    */

145   public boolean isAssignableFrom(Class JavaDoc cl)
146   {
147     return getName().equals(cl.getName());
148   }
149
150   /**
151    * Returns true if the jClass is assignable to the class.
152    */

153   public boolean isAssignableFrom(JClass cl)
154   {
155     return getName().equals(cl.getName());
156   }
157   
158   /**
159    * Returns the declared methods
160    */

161   public JMethod []getDeclaredMethods()
162   {
163     return new JMethod[0];
164   }
165
166   /**
167    * Returns the public methods
168    */

169   public JMethod []getMethods()
170   {
171     return new JMethod[0];
172   }
173
174   /**
175    * Returns the matching method.
176    */

177   public JMethod getMethod(String JavaDoc name, JClass []param)
178   {
179     return null;
180   }
181
182   /**
183    * Returns the declared fields
184    */

185   public JField []getDeclaredFields()
186   {
187     return new JField[0];
188   }
189
190   /**
191    * Returns the fields
192    */

193   public JField []getFields()
194   {
195     return new JField[0];
196   }
197
198   /**
199    * Returns the printable name.
200    */

201   public String JavaDoc getPrintName()
202   {
203     if (isArray())
204       return getComponentType().getPrintName() + "[]";
205     else
206       return getName();
207   }
208
209   /**
210    * Returns a printable version of a class.
211    */

212   public String JavaDoc getShortName()
213   {
214     if (isArray())
215       return getComponentType().getShortName() + "[]";
216     else {
217       String JavaDoc name = getName();
218       
219       int p = name.lastIndexOf('.');
220
221       if (p >= 0)
222     return name.substring(p + 1);
223       else
224     return name;
225     }
226   }
227   
228   /**
229    * Returns the hash code
230    */

231   public int hashCode()
232   {
233     return getName().hashCode();
234   }
235   
236   /**
237    * Returns true if equals.
238    */

239   public boolean equals(Object JavaDoc o)
240   {
241     if (o == this)
242       return true;
243     else if (o == null || getClass() != o.getClass())
244       return false;
245
246     JClass jClass = (JClass) o;
247
248     // note that the equality test doesn't include the class loader
249
return getName().equals(jClass.getName());
250   }
251
252   public String JavaDoc toString()
253   {
254     return "JClass[" + getName() + "]";
255   }
256 }
257
Popular Tags