KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > reflect > plugins > ConstructorInfoImpl


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.reflect.plugins;
23
24 import java.lang.reflect.Modifier JavaDoc;
25 import java.util.Arrays JavaDoc;
26
27 import org.jboss.reflect.spi.AnnotationValue;
28 import org.jboss.reflect.spi.ClassInfo;
29 import org.jboss.reflect.spi.ConstructorInfo;
30 import org.jboss.reflect.spi.MethodInfo;
31 import org.jboss.reflect.spi.ParameterInfo;
32 import org.jboss.reflect.spi.TypeInfo;
33 import org.jboss.util.JBossStringBuilder;
34 import org.jboss.util.NotImplementedException;
35
36 /**
37  * Constructor info
38  *
39  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
40  * @author <a HREF="mailto:adrian@jboss.org">Adrian Brock</a>
41  */

42 public class ConstructorInfoImpl extends AnnotationHolder implements ConstructorInfo
43 {
44    /** serialVersionUID */
45    private static final long serialVersionUID = 3256727273163272758L;
46    
47    /** The declring class */
48    protected ClassInfo declaringClass;
49    
50    /** The parameter types */
51    protected TypeInfo[] parameterTypes;
52    
53    /** The parameters */
54    protected ParameterInfo[] parameters;
55    
56    /** The exception types */
57    protected ClassInfo[] exceptionTypes;
58    
59    /** The modifiers */
60    protected int modifiers;
61    
62    /** The hash code */
63    protected int hash;
64
65    /**
66     * Create a new ConstructorInfo.
67     */

68    public ConstructorInfoImpl()
69    {
70    }
71
72    /**
73     * Create a new ConstructorInfo.
74     *
75     * @param annotations the annotations
76     * @param parameterTypes the parameter types
77     * @param parameterAnnotations the parameter annotations
78     * @param exceptionTypes the exception types
79     * @param modifiers the modifiers
80     * @param declaring the declaring class
81     */

82    public ConstructorInfoImpl(AnnotationValue[] annotations, TypeInfo[] parameterTypes, AnnotationValue[][] parameterAnnotations, ClassInfo[] exceptionTypes, int modifiers, ClassInfo declaring)
83    {
84       super(annotations);
85       if (parameterTypes == null)
86       {
87          this.parameterTypes = MethodInfo.NO_PARAMS_TYPES;
88          this.parameters = MethodInfo.NO_PARAMS;
89       }
90       else
91       {
92          this.parameterTypes = parameterTypes;
93          this.parameters = new ParameterInfoImpl[parameterTypes.length];
94          for (int i = 0; i < parameterTypes.length; ++i)
95             this.parameters[i] = new ParameterInfoImpl(parameterAnnotations[i], null, parameterTypes[i]);
96       }
97       if (exceptionTypes == null)
98          this.exceptionTypes = MethodInfo.NO_EXCEPTIONS;
99       else
100          this.exceptionTypes = exceptionTypes;
101       this.modifiers = modifiers;
102       this.declaringClass = declaring;
103       calculateHash();
104    }
105
106    /**
107     * Create a new ConstructorInfo.
108     *
109     * @param annotations the annotations
110     * @param parameters the parameters
111     * @param exceptionTypes the exception types
112     * @param modifiers the modifiers
113     * @param declaring the declaring class
114     */

115    public ConstructorInfoImpl(AnnotationValue[] annotations, ParameterInfo[] parameters, ClassInfo[] exceptionTypes, int modifiers, ClassInfo declaring)
116    {
117       super(annotations);
118       if (parameters == null || parameters.length == 0)
119       {
120          this.parameterTypes = MethodInfo.NO_PARAMS_TYPES;
121          this.parameters = MethodInfo.NO_PARAMS;
122       }
123       else
124       {
125          this.parameters = parameters;
126          this.parameterTypes = new TypeInfo[parameters.length];
127          for (int i = 0; i < parameters.length; ++i)
128             this.parameterTypes[i] = parameters[i].getParameterType();
129       }
130       if (exceptionTypes == null || exceptionTypes.length == 0)
131          this.exceptionTypes = MethodInfo.NO_EXCEPTIONS;
132       else
133          this.exceptionTypes = exceptionTypes;
134       this.modifiers = modifiers;
135       this.declaringClass = declaring;
136       calculateHash();
137    }
138    
139    public ClassInfo getDeclaringClass()
140    {
141       return declaringClass;
142    }
143
144    public TypeInfo[] getParameterTypes()
145    {
146       return parameterTypes;
147    }
148
149    public ParameterInfo[] getParameters()
150    {
151       return parameters;
152    }
153    
154    public ClassInfo[] getExceptionTypes()
155    {
156       return exceptionTypes;
157    }
158    
159    public int getModifiers()
160    {
161       return modifiers;
162    }
163    
164    public boolean isStatic()
165    {
166       return Modifier.isStatic(modifiers);
167    }
168    
169    public boolean isPublic()
170    {
171       return Modifier.isPublic(modifiers);
172    }
173    
174    public Object JavaDoc newInstance(Object JavaDoc[] args) throws Throwable JavaDoc
175    {
176       throw new NotImplementedException("newInstance");
177    }
178
179    protected void toString(JBossStringBuilder buffer)
180    {
181       buffer.append(Arrays.asList(parameterTypes));
182    }
183
184    public boolean equals(Object JavaDoc obj)
185    {
186       if (this == obj)
187          return true;
188       if (obj == null || obj instanceof ConstructorInfo == false)
189          return false;
190
191       final ConstructorInfo other = (ConstructorInfo) obj;
192       
193       if (declaringClass.equals(other.getDeclaringClass()) == false)
194          return false;
195       return (Arrays.equals(parameterTypes, other.getParameterTypes()));
196    }
197
198    public int hashCode()
199    {
200       return hash;
201    }
202
203    protected void calculateHash()
204    {
205       int result = declaringClass.hashCode();
206       if (parameterTypes != null)
207       {
208          for (int i = 0; i < parameterTypes.length; i++)
209          {
210             result = 29 * result + parameterTypes[i].hashCode();
211          }
212       }
213       hash = result;
214    }
215 }
216
Popular Tags