KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > beans > info > plugins > AbstractBeanInfo


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.beans.info.plugins;
23
24 import java.util.Iterator JavaDoc;
25 import java.util.List JavaDoc;
26 import java.util.Set JavaDoc;
27
28 import org.jboss.beans.info.spi.BeanInfo;
29 import org.jboss.beans.info.spi.BeanInfoFactory;
30 import org.jboss.beans.info.spi.EventInfo;
31 import org.jboss.beans.info.spi.PropertyInfo;
32 import org.jboss.classadapter.spi.ClassAdapter;
33 import org.jboss.joinpoint.spi.JoinpointFactory;
34 import org.jboss.reflect.spi.ClassInfo;
35 import org.jboss.reflect.spi.ConstructorInfo;
36 import org.jboss.reflect.spi.MethodInfo;
37 import org.jboss.repository.spi.MetaDataContext;
38 import org.jboss.repository.spi.MetaDataContextFactory;
39 import org.jboss.util.JBossObject;
40 import org.jboss.util.JBossStringBuilder;
41
42 /**
43  * BeanInfo.
44  *
45  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
46  * @version $Revision: 57133 $
47  */

48 public class AbstractBeanInfo extends JBossObject implements BeanInfo
49 {
50    /** The class name */
51    protected String JavaDoc name;
52    
53    /** The class adapter */
54    protected ClassAdapter classAdapter;
55    
56    /** The properties */
57    protected Set JavaDoc<PropertyInfo> properties;
58    
59    /** The constructors */
60    protected Set JavaDoc<ConstructorInfo> constructors;
61    
62    /** The methods */
63    protected Set JavaDoc<MethodInfo> methods;
64    
65    /** The events */
66    protected Set JavaDoc<EventInfo> events;
67    
68    /** The BeanInfoFactory */
69    protected BeanInfoFactory beanInfoFactory;
70
71
72    /**
73     * Create a new bean info
74     *
75     * @param beanInfoFactory the bean info factory
76     * @param classAdapter the class adapter
77     * @param properties the properties
78     * @param constructors the constructors
79     * @param methods the methods
80     * @param events the events
81     */

82    public AbstractBeanInfo(BeanInfoFactory beanInfoFactory, ClassAdapter classAdapter, Set JavaDoc<PropertyInfo> properties, Set JavaDoc<ConstructorInfo> constructors,
83          Set JavaDoc<MethodInfo> methods, Set JavaDoc<EventInfo> events)
84    {
85       this.beanInfoFactory = beanInfoFactory;
86       this.name = classAdapter.getClassInfo().getName();
87       this.classAdapter = classAdapter;
88       this.properties = properties;
89       if (properties != null && properties.isEmpty() == false)
90       {
91          for (Iterator JavaDoc i = properties.iterator(); i.hasNext();)
92          {
93             AbstractPropertyInfo ainfo = (AbstractPropertyInfo) i.next();
94             ainfo.beanInfo = this;
95          }
96       }
97       this.constructors = constructors;
98       this.methods = methods;
99       this.events = events;
100    }
101    
102    protected AbstractBeanInfo(AbstractBeanInfo template)
103    {
104       this.name = template.name;
105       this.classAdapter = template.classAdapter.getInstanceAdapter(template.classAdapter.getClassInfo());
106       this.properties = template.properties;
107       this.constructors = template.constructors;
108       this.methods = template.methods;
109       this.events = template.events;
110       this.beanInfoFactory = template.beanInfoFactory;
111    }
112
113    public String JavaDoc getName()
114    {
115       return name;
116    }
117    
118    public Set JavaDoc<PropertyInfo> getProperties()
119    {
120       return properties;
121    }
122    
123    public void setProperties(Set JavaDoc<PropertyInfo> properties)
124    {
125       this.properties = properties;
126    }
127    
128    public ClassInfo getClassInfo()
129    {
130       return classAdapter.getClassInfo();
131    }
132
133    public List JavaDoc<Object JavaDoc> getDependencies()
134    {
135       return classAdapter.getDependencies();
136    }
137
138    public JoinpointFactory getJoinpointFactory()
139    {
140       return classAdapter.getJoinpointFactory();
141    }
142    
143    public MetaDataContextFactory getMetaDataContextFactory()
144    {
145       return classAdapter.getMetaDataContextFactory();
146    }
147
148    public Set JavaDoc<ConstructorInfo> getConstructors()
149    {
150       return constructors;
151    }
152
153    public void setConstructors(Set JavaDoc<ConstructorInfo> constructors)
154    {
155       this.constructors = constructors;
156    }
157    
158    public Set JavaDoc<EventInfo> getEvents()
159    {
160       return events;
161    }
162
163    public void setEvents(Set JavaDoc<EventInfo> events)
164    {
165       this.events = events;
166    }
167    
168    public Set JavaDoc<MethodInfo> getMethods()
169    {
170       return methods;
171    }
172
173    public void setMethods(Set JavaDoc<MethodInfo> methods)
174    {
175       this.methods = methods;
176    }
177    
178    public BeanInfoFactory getBeanInfoFactory()
179    {
180       return beanInfoFactory;
181    }
182    
183    public MetaDataContext getMetaDataContext()
184    {
185       return classAdapter.getMetaDataContext();
186    }
187
188    public void setMetaDataContext(MetaDataContext metaCtx)
189    {
190       classAdapter.setMetaDataContext(metaCtx);
191    }
192
193    public boolean equals(Object JavaDoc object)
194    {
195       if (object == null || object instanceof AbstractBeanInfo == false)
196          return false;
197       
198       AbstractBeanInfo other = (AbstractBeanInfo) object;
199       if (notEqual(name, other.name))
200          return false;
201       else if (notEqual(classAdapter, other.classAdapter))
202          return false;
203       else if (notEqual(properties, other.properties))
204          return false;
205       else if (notEqual(methods, other.methods))
206          return false;
207       else if (notEqual(constructors, other.constructors))
208          return false;
209       else if (notEqual(events, other.events))
210          return false;
211       return true;
212    }
213    
214    public void toString(JBossStringBuilder buffer)
215    {
216       buffer.append("name=").append(name);
217       buffer.append(" classInfo=");
218       classAdapter.toShortString(buffer);
219       buffer.append(" properties=");
220       JBossObject.list(buffer, properties);
221       buffer.append(" methods=");
222       JBossObject.list(buffer, methods);
223       buffer.append(" constructors=");
224       JBossObject.list(buffer, constructors);
225       buffer.append(" events=");
226       JBossObject.list(buffer, events);
227    }
228    
229    public void toShortString(JBossStringBuilder buffer)
230    {
231       buffer.append(name);
232    }
233    
234    public int getHashCode()
235    {
236       return name.hashCode();
237    }
238
239
240    public BeanInfo getInstanceInfo()
241    {
242       return new AbstractInstanceBeanInfo(this);
243    }
244 }
245
Popular Tags