KickJava   Java API By Example, From Geeks To Geeks.

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


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.Set JavaDoc;
25 import java.util.Stack JavaDoc;
26
27 import org.jboss.beans.metadata.spi.MetaDataVisitor;
28 import org.jboss.beans.metadata.spi.MetaDataVisitorNode;
29 import org.jboss.beans.metadata.spi.ParameterMetaData;
30 import org.jboss.beans.metadata.spi.ValueMetaData;
31 import org.jboss.kernel.plugins.config.Configurator;
32 import org.jboss.kernel.spi.config.KernelConfigurator;
33 import org.jboss.kernel.spi.dependency.KernelController;
34 import org.jboss.kernel.spi.dependency.KernelControllerContext;
35 import org.jboss.util.JBossStringBuilder;
36
37 /**
38  * Metadata for a parameter.
39  *
40  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
41  * @version $Revision: 58417 $
42  */

43 public class AbstractParameterMetaData extends AbstractFeatureMetaData implements ParameterMetaData
44 {
45    /**
46     * The parameter type
47     */

48    protected String JavaDoc type;
49
50    /**
51     * The parameter value
52     */

53    protected ValueMetaData value;
54
55    /**
56     * The index in parameter list
57     */

58    protected int index;
59
60    /**
61     * Create a new parameter meta data
62     */

63    public AbstractParameterMetaData()
64    {
65    }
66
67    /**
68     * Create a new parameter meta data
69     *
70     * @param value the value
71     */

72    public AbstractParameterMetaData(Object JavaDoc value)
73    {
74       this.type = value.getClass().getName();
75       this.value = new AbstractValueMetaData(value);
76    }
77
78    /**
79     * Create a new parameter meta data
80     *
81     * @param value the value metadata
82     */

83    public AbstractParameterMetaData(ValueMetaData value)
84    {
85       this.value = value;
86    }
87
88    /**
89     * Create a new parameter meta data
90     *
91     * @param type the type
92     * @param value the value
93     */

94    public AbstractParameterMetaData(String JavaDoc type, Object JavaDoc value)
95    {
96       this.type = type;
97       this.value = new AbstractValueMetaData(value);
98    }
99
100    /**
101     * Create a new parameter meta data
102     *
103     * @param type the type
104     * @param value the string value
105     */

106    public AbstractParameterMetaData(String JavaDoc type, String JavaDoc value)
107    {
108       this.type = type;
109       this.value = new StringValueMetaData(value);
110    }
111
112    /**
113     * Create a new parameter meta data
114     *
115     * @param type the type
116     * @param value the value meta data
117     */

118    public AbstractParameterMetaData(String JavaDoc type, ValueMetaData value)
119    {
120       this.type = type;
121       this.value = value;
122    }
123
124    public String JavaDoc getType()
125    {
126       return type;
127    }
128
129    public void setType(String JavaDoc type)
130    {
131       this.type = type;
132       flushJBossObjectCache();
133    }
134
135    public ValueMetaData getValue()
136    {
137       return value;
138    }
139
140    public int getIndex()
141    {
142       return index;
143    }
144
145    public void setIndex(int index)
146    {
147       this.index = index;
148    }
149
150    public void setValue(ValueMetaData value)
151    {
152       this.value = value;
153       flushJBossObjectCache();
154    }
155
156    protected void addChildren(Set JavaDoc<MetaDataVisitorNode> children)
157    {
158       super.addChildren(children);
159       if (value != null)
160          children.add(value);
161    }
162
163    public Class JavaDoc getType(MetaDataVisitor visitor, MetaDataVisitorNode previous) throws Throwable JavaDoc
164    {
165       if (type != null)
166       {
167          KernelControllerContext context = visitor.getControllerContext();
168          ClassLoader JavaDoc cl = Configurator.getClassLoader(context.getBeanMetaData());
169          KernelController controller = (KernelController) context.getController();
170          KernelConfigurator configurator = controller.getKernel().getConfigurator();
171          return applyCollectionOrMapCheck(configurator.getClassInfo(type, cl).getType());
172       }
173       else
174       {
175          Stack JavaDoc<MetaDataVisitorNode> visitorNodeStack = visitor.visitorNodeStack();
176          // see AbstractInjectionValueMetaData.describeVisit
177
MetaDataVisitorNode node = visitorNodeStack.pop();
178          try
179          {
180             if (node instanceof TypeProvider)
181             {
182                TypeProvider typeProvider = (TypeProvider) node;
183                return typeProvider.getType(visitor, this);
184             }
185             else
186             {
187                throw new IllegalArgumentException JavaDoc(TypeProvider.ERROR_MSG);
188             }
189          }
190          finally
191          {
192             visitorNodeStack.push(node);
193          }
194       }
195    }
196
197    public void toString(JBossStringBuilder buffer)
198    {
199       buffer.append("type=").append(type);
200       buffer.append(" value=").append(value);
201       super.toString(buffer);
202    }
203
204    public void toShortString(JBossStringBuilder buffer)
205    {
206       buffer.append(type);
207    }
208 }
209
Popular Tags