KickJava   Java API By Example, From Geeks To Geeks.

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


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
27 import org.jboss.beans.info.spi.PropertyInfo;
28 import org.jboss.beans.metadata.spi.MetaDataVisitor;
29 import org.jboss.beans.metadata.spi.MetaDataVisitorNode;
30 import org.jboss.beans.metadata.spi.PropertyMetaData;
31 import org.jboss.beans.metadata.spi.ValueMetaData;
32 import org.jboss.dependency.spi.ControllerState;
33 import org.jboss.kernel.spi.dependency.KernelControllerContext;
34 import org.jboss.util.JBossStringBuilder;
35
36 /**
37  * Metadata for a property.
38  *
39  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
40  * @version $Revision: 57133 $
41  */

42 public class AbstractPropertyMetaData extends AbstractFeatureMetaData implements PropertyMetaData, TypeProvider
43 {
44    /** The property name */
45    protected String JavaDoc name;
46
47    /** The property value */
48    protected ValueMetaData value;
49
50    /**
51     * Create a new property meta data
52     */

53    public AbstractPropertyMetaData()
54    {
55    }
56
57    /**
58     * Create a new property meta data
59     *
60     * @param name the name
61     * @param value the value
62     */

63    public AbstractPropertyMetaData(String JavaDoc name, Object JavaDoc value)
64    {
65       this.name = name;
66       this.value = new AbstractValueMetaData(value);
67    }
68
69    /**
70     * Create a new property meta data
71     *
72     * @param name the name
73     * @param value the string value
74     */

75    public AbstractPropertyMetaData(String JavaDoc name, String JavaDoc value)
76    {
77       this.name = name;
78       this.value = new StringValueMetaData(value);
79    }
80
81    /**
82     * Create a new attribute meta data
83     *
84     * @param name the name
85     * @param value the value meta data
86     */

87    public AbstractPropertyMetaData(String JavaDoc name, ValueMetaData value)
88    {
89       this.name = name;
90       this.value = value;
91    }
92
93    /**
94     * Create a new property meta data
95     *
96     * @param name the name
97     * @param value the string value
98     * @param type the type
99     */

100    public AbstractPropertyMetaData(String JavaDoc name, String JavaDoc value, String JavaDoc type)
101    {
102       this.name = name;
103       StringValueMetaData svmd = new StringValueMetaData(value);
104       svmd.setType(type);
105       this.value = svmd;
106    }
107
108    public String JavaDoc getName()
109    {
110       return name;
111    }
112
113    /**
114     * Set the name
115     *
116     * @param name the name
117     */

118    public void setName(String JavaDoc name)
119    {
120       this.name = name;
121       flushJBossObjectCache();
122    }
123
124    public ValueMetaData getValue()
125    {
126       return value;
127    }
128
129    /**
130     * Set the value
131     *
132     * @param value the value
133     */

134    public void setValue(ValueMetaData value)
135    {
136       this.value = value;
137       flushJBossObjectCache();
138    }
139
140    public void initialVisit(MetaDataVisitor visitor)
141    {
142       visitor.setContextState(ControllerState.CONFIGURED);
143       super.initialVisit(visitor);
144    }
145
146    public void addChildren(Set JavaDoc<MetaDataVisitorNode> children)
147    {
148       if (value != null)
149          children.add(value);
150    }
151
152    public Class JavaDoc getType(MetaDataVisitor visitor, MetaDataVisitorNode previous) throws Throwable JavaDoc
153    {
154       KernelControllerContext context = visitor.getControllerContext();
155       Set JavaDoc propertyInfos = context.getBeanInfo().getProperties();
156       if (propertyInfos != null)
157       {
158          for(Iterator JavaDoc it = propertyInfos.iterator(); it.hasNext();)
159          {
160             PropertyInfo pi = (PropertyInfo) it.next();
161             if (getName().equals(pi.getName()))
162             {
163                return applyCollectionOrMapCheck(pi.getType().getType());
164             }
165          }
166       }
167       throw new IllegalArgumentException JavaDoc("Should not be here - no matching propertyInfo: " + this);
168    }
169
170    public void toString(JBossStringBuilder buffer)
171    {
172       buffer.append("name=").append(name);
173       if (value != null)
174          buffer.append(" value=").append(value);
175       super.toString(buffer);
176    }
177
178    public void toShortString(JBossStringBuilder buffer)
179    {
180       buffer.append(name);
181    }
182 }
183
Popular Tags