KickJava   Java API By Example, From Geeks To Geeks.

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


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.Collections JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.Stack JavaDoc;
27
28 import org.jboss.beans.metadata.spi.MetaDataVisitor;
29 import org.jboss.beans.metadata.spi.MetaDataVisitorNode;
30 import org.jboss.beans.metadata.spi.ValueMetaData;
31 import org.jboss.reflect.spi.TypeInfo;
32 import org.jboss.util.JBossObject;
33 import org.jboss.util.JBossStringBuilder;
34
35 /**
36  * Plain value.
37  *
38  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
39  * @version $Revision: 58417 $
40  */

41 public class AbstractValueMetaData extends JBossObject implements ValueMetaData, TypeProvider
42 {
43    /**
44     * The value
45     */

46    protected Object JavaDoc value;
47
48    /**
49     * Create a new plain value
50     */

51    public AbstractValueMetaData()
52    {
53    }
54
55    /**
56     * Create a new plain value
57     *
58     * @param value the value
59     */

60    public AbstractValueMetaData(Object JavaDoc value)
61    {
62       this.value = value;
63    }
64
65    public Object JavaDoc getValue()
66    {
67       return value;
68    }
69
70    public void setValue(Object JavaDoc value)
71    {
72       this.value = value;
73       flushJBossObjectCache();
74    }
75
76    public Object JavaDoc getUnderlyingValue()
77    {
78       return value;
79    }
80
81    public Object JavaDoc getValue(TypeInfo info, ClassLoader JavaDoc cl) throws Throwable JavaDoc
82    {
83       return value;
84    }
85
86    public void initialVisit(MetaDataVisitor visitor)
87    {
88       visitor.initialVisit(this);
89    }
90
91    public void describeVisit(MetaDataVisitor vistor)
92    {
93       vistor.describeVisit(this);
94    }
95
96    public Class JavaDoc getType(MetaDataVisitor visitor, MetaDataVisitorNode previous) throws Throwable JavaDoc
97    {
98       Stack JavaDoc<MetaDataVisitorNode> visitorNodeStack = visitor.visitorNodeStack();
99       // see AbstractInjectionValueMetaData.describeVisit
100
MetaDataVisitorNode node = visitorNodeStack.pop();
101       try
102       {
103          if (node instanceof TypeProvider)
104          {
105             TypeProvider typeProvider = (TypeProvider) node;
106             return typeProvider.getType(visitor, this);
107          }
108          else
109          {
110             throw new IllegalArgumentException JavaDoc(TypeProvider.ERROR_MSG);
111          }
112       }
113       finally
114       {
115          visitorNodeStack.push(node);
116       }
117    }
118
119    public Iterator JavaDoc<? extends MetaDataVisitorNode> getChildren()
120    {
121       if (value instanceof MetaDataVisitorNode)
122          return Collections.singletonList((MetaDataVisitorNode) value).iterator();
123       return null;
124    }
125
126    public void toString(JBossStringBuilder buffer)
127    {
128       buffer.append("value=").append(value);
129    }
130
131    public void toShortString(JBossStringBuilder buffer)
132    {
133       buffer.append(value);
134    }
135 }
136
Popular Tags