KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > beans > metadata > plugins > factory > GenericBeanFactoryMetaData


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2006, 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.factory;
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.HashSet JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.Map JavaDoc;
28 import java.util.Set JavaDoc;
29
30 import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
31 import org.jboss.beans.metadata.plugins.AbstractConstructorMetaData;
32 import org.jboss.beans.metadata.plugins.AbstractDependencyValueMetaData;
33 import org.jboss.beans.metadata.plugins.AbstractMapMetaData;
34 import org.jboss.beans.metadata.plugins.AbstractParameterMetaData;
35 import org.jboss.beans.metadata.plugins.AbstractPropertyMetaData;
36 import org.jboss.beans.metadata.plugins.AbstractValueMetaData;
37 import org.jboss.beans.metadata.spi.*;
38 import org.jboss.kernel.plugins.bootstrap.basic.KernelConstants;
39 import org.jboss.kernel.spi.config.KernelConfigurator;
40
41 /**
42  * GenericBeanFactoryMetaData.
43  *
44  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
45  * @version $Revision: 57307 $
46  */

47 public class GenericBeanFactoryMetaData extends AbstractBeanMetaData
48 {
49    /**
50     * Create a new GenericBeanFactoryMetaData.
51     */

52    public GenericBeanFactoryMetaData()
53    {
54       setBean(GenericBeanFactory.class.getName());
55       AbstractConstructorMetaData constructor = new AbstractConstructorMetaData();
56       ArrayList JavaDoc<ParameterMetaData> parameters = new ArrayList JavaDoc<ParameterMetaData>();
57       parameters.add(new AbstractParameterMetaData(KernelConfigurator.class.getName(), new AbstractDependencyValueMetaData(KernelConstants.KERNEL_CONFIGURATOR_NAME)));
58       constructor.setParameters(parameters);
59       setConstructor(constructor);
60       setProperties(new HashSet JavaDoc<PropertyMetaData>());
61    }
62    
63    /**
64     * Create a new GenericBeanFactoryMetaData.
65     *
66     * @param name the name
67     */

68    public GenericBeanFactoryMetaData(String JavaDoc name)
69    {
70       this();
71       setName(name);
72    }
73    
74    /**
75     * Create a new GenericBeanFactoryMetaData.
76     *
77     * @param name the name
78     * @param bean the bean class name
79     */

80    public GenericBeanFactoryMetaData(String JavaDoc name, String JavaDoc bean)
81    {
82       this(name);
83       setBeanClass(bean);
84    }
85
86    /**
87     * Get the class of the bean created
88     *
89     * @return the class
90     */

91    public String JavaDoc getBeanClass()
92    {
93       AbstractPropertyMetaData prop = (AbstractPropertyMetaData) getProperty("bean");
94       if (prop != null)
95       {
96          AbstractValueMetaData value = (AbstractValueMetaData) prop.getValue();
97          if (value != null)
98             return (String JavaDoc) value.getUnderlyingValue();
99       }
100       return null;
101    }
102
103    /**
104     * Set the class of the bean created
105     *
106     * @param beanClass the class
107     */

108    public void setBeanClass(String JavaDoc beanClass)
109    {
110       Set JavaDoc<PropertyMetaData> properties = getProperties();
111       properties.add(new AbstractPropertyMetaData("bean", new AbstractValueMetaData(beanClass)));
112    }
113    
114    public void setClassLoader(ClassLoaderMetaData classLoader)
115    {
116       super.setClassLoader(classLoader);
117       Set JavaDoc<PropertyMetaData> properties = getProperties();
118       properties.add(new AbstractPropertyMetaData("classLoader", new AbstractValueMetaData(classLoader)));
119    }
120
121    /**
122     * Set the bean constructor
123     *
124     * @param constructor the constructor
125     */

126    public void setBeanConstructor(ConstructorMetaData constructor)
127    {
128       Set JavaDoc<PropertyMetaData> properties = getProperties();
129       properties.add(new AbstractPropertyMetaData("constructor", new AbstractValueMetaData(constructor)));
130    }
131    
132    /**
133     * Get a bean property
134     *
135     * @param name the name
136     * @return the value metadata
137     */

138    public ValueMetaData getBeanProperty(String JavaDoc name)
139    {
140       if (name == null)
141          throw new IllegalArgumentException JavaDoc("Null name");
142       PropertyMetaData properties = getProperty("properties");
143       if (properties == null)
144          return null;
145       AbstractMapMetaData map = (AbstractMapMetaData) properties.getValue();
146       for (Iterator JavaDoc i = map.entrySet().iterator(); i.hasNext();)
147       {
148          Map.Entry JavaDoc entry = (Map.Entry JavaDoc) i.next();
149          ValueMetaData key = (ValueMetaData) entry.getKey();
150          if (key.getUnderlyingValue().equals(name))
151          {
152             ValueMetaData vmd = (ValueMetaData) entry.getValue();
153             return (ValueMetaData) vmd.getUnderlyingValue();
154          }
155       }
156       return null;
157    }
158    
159    /**
160     * Add a bean property
161     *
162     * @param property the property
163     */

164    public void addBeanProperty(PropertyMetaData property)
165    {
166       PropertyMetaData properties = getProperty("properties");
167
168       AbstractMapMetaData map;
169       if (properties == null)
170       {
171          map = new AbstractMapMetaData();
172          properties = new AbstractPropertyMetaData("properties", map);
173          addProperty(properties);
174       }
175       else
176       {
177          map = (AbstractMapMetaData) properties.getValue();
178       }
179       
180       ValueMetaData valueMetaData = property.getValue();
181       valueMetaData = new AbstractValueMetaData(valueMetaData);
182       map.put(new AbstractValueMetaData(property.getName()), valueMetaData);
183    }
184    
185    public void setBeanCreate(LifecycleMetaData lifecycle)
186    {
187       Set JavaDoc<PropertyMetaData> properties = getProperties();
188       properties.add(new AbstractPropertyMetaData("create", new AbstractValueMetaData(lifecycle)));
189    }
190    
191    public void setBeanStart(LifecycleMetaData lifecycle)
192    {
193       Set JavaDoc<PropertyMetaData> properties = getProperties();
194       properties.add(new AbstractPropertyMetaData("start", new AbstractValueMetaData(lifecycle)));
195    }
196 }
197
Popular Tags