KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > beans > metadata > plugins > AbstractFeatureMetaData


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.metadata.plugins;
23
24 import java.util.Iterator JavaDoc;
25 import java.util.Set JavaDoc;
26 import java.util.Collection JavaDoc;
27 import java.util.Map JavaDoc;
28
29 import org.jboss.beans.metadata.spi.AnnotationMetaData;
30 import org.jboss.beans.metadata.spi.FeatureMetaData;
31 import org.jboss.beans.metadata.spi.MetaDataVisitor;
32 import org.jboss.beans.metadata.spi.MetaDataVisitorNode;
33 import org.jboss.util.collection.CollectionsFactory;
34 import org.jboss.util.JBossObject;
35 import org.jboss.util.JBossStringBuilder;
36
37 /**
38  * General metadata.
39  *
40  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
41  * @version $Revision: 56022 $
42  */

43 public abstract class AbstractFeatureMetaData extends JBossObject implements FeatureMetaData, TypeProvider
44 {
45    /** The description */
46    protected String JavaDoc description;
47
48    /** The annotations */
49    protected Set JavaDoc<AnnotationMetaData> annotations;
50
51    /**
52     * Create a new meta data
53     */

54    public AbstractFeatureMetaData()
55    {
56    }
57    
58    /**
59     * Set the description.
60     *
61     * @param description the description.
62     */

63    public void setDescription(String JavaDoc description)
64    {
65       this.description = description;
66       flushJBossObjectCache();
67    }
68
69    /**
70     * Set the annotations.
71     *
72     * @param annotations Set<AnnotationMetaData>
73     */

74    public void setAnnotations(Set JavaDoc<AnnotationMetaData> annotations)
75    {
76       this.annotations = annotations;
77       flushJBossObjectCache();
78    }
79    
80    public String JavaDoc getDescription()
81    {
82       return description;
83    }
84    
85    public Set JavaDoc<AnnotationMetaData> getAnnotations()
86    {
87       return annotations;
88    }
89
90    public void initialVisit(MetaDataVisitor visitor)
91    {
92       visitor.initialVisit(this);
93    }
94
95    public void describeVisit(MetaDataVisitor vistor)
96    {
97       vistor.describeVisit(this);
98    }
99
100    protected Class JavaDoc applyCollectionOrMapCheck(Class JavaDoc clazz) throws Throwable JavaDoc
101    {
102       // todo - some generics check
103
if (Collection JavaDoc.class.isAssignableFrom(clazz) || Map JavaDoc.class.isAssignableFrom(clazz))
104       {
105          throw new IllegalArgumentException JavaDoc("Should not be here - set element/value class type in collection/map: " + this);
106       }
107       return clazz;
108    }
109
110    public Iterator JavaDoc<? extends MetaDataVisitorNode> getChildren()
111    {
112       Set JavaDoc<MetaDataVisitorNode> children = CollectionsFactory.createLazySet();
113       addChildren(children);
114       if (children.size() == 0)
115          return null;
116       else
117          return children.iterator();
118    }
119    
120    protected void addChildren(Set JavaDoc<MetaDataVisitorNode> children)
121    {
122       if (annotations != null && annotations.size() > 0)
123          children.addAll(annotations);
124    }
125    
126    public void toString(JBossStringBuilder buffer)
127    {
128       if (description != null)
129          buffer.append("description=").append(description);
130       if (annotations != null)
131          buffer.append(" annotations=").append(annotations);
132    }
133    
134    public void toShortString(JBossStringBuilder buffer)
135    {
136       buffer.append(description);
137    }
138 }
139
Popular Tags