KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.jboss.reflect.spi.AnnotatedInfo;
25 import org.jboss.reflect.spi.AnnotationValue;
26 import org.jboss.reflect.spi.ArrayInfo;
27 import org.jboss.reflect.spi.TypeInfo;
28
29 /**
30  * Array information
31  *
32  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
33  * @author <a HREF="mailto:adrian@jboss.org">Adrian Brock</a>
34  */

35 public class ArrayInfoImpl extends ClassInfoImpl implements ArrayInfo
36 {
37    /** serialVersionUID */
38    private static final long serialVersionUID = 3905804162787980599L;
39
40    /** The component type */
41    protected TypeInfo componentType;
42    
43    /** The hash code */
44    protected int hash = -1;
45
46    /**
47     * Create a new ArrayInfo.
48     */

49    public ArrayInfoImpl()
50    {
51    }
52
53    /**
54     * Create a new ArrayInfo.
55     *
56     * @param componentType the component type
57     */

58    public ArrayInfoImpl(TypeInfo componentType)
59    {
60       this.componentType = componentType;
61       calculateHash();
62    }
63
64    public TypeInfo getComponentType()
65    {
66       return componentType;
67    }
68
69    public String JavaDoc getName()
70    {
71       return "[L" + componentType.getName() + ";";
72    }
73    
74    public AnnotationValue getAnnotation(String JavaDoc name)
75    {
76       if (componentType instanceof AnnotatedInfo)
77       {
78          return ((AnnotatedInfo)componentType).getAnnotation(name);
79       }
80       else
81       {
82          return null;
83       }
84    }
85
86    public AnnotationValue[] getAnnotations()
87    {
88       if (componentType instanceof AnnotatedInfo)
89       {
90          return ((AnnotatedInfo)componentType).getAnnotations();
91       }
92       else
93       {
94          return UNKNOWN_ANNOTATIONS;
95       }
96    }
97
98    public boolean isAnnotationPresent(String JavaDoc name)
99    {
100       if (componentType instanceof AnnotatedInfo)
101       {
102          return ((AnnotatedInfo)componentType).isAnnotationPresent(name);
103       }
104       else
105       {
106          return false;
107       }
108    }
109
110    public boolean equals(Object JavaDoc o)
111    {
112       if (this == o) return true;
113       if (!(o instanceof ArrayInfoImpl)) return false;
114       if (!super.equals(o)) return false;
115
116       final ArrayInfoImpl arrayInfo = (ArrayInfoImpl) o;
117
118       if (!componentType.equals(arrayInfo.componentType)) return false;
119
120       return true;
121    }
122
123    public int hashCode() { return hash; }
124
125    /**
126     * Calculate the hash code
127     */

128    protected void calculateHash()
129    {
130       int result = super.hashCode();
131       result = 29 * result + componentType.hashCode();
132       hash = result;
133    }
134 }
135
Popular Tags