KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > config > plugins > AbstractConfiguration


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.config.plugins;
23
24 import org.jboss.beans.info.spi.BeanInfo;
25 import org.jboss.beans.info.spi.BeanInfoFactory;
26 import org.jboss.classadapter.spi.ClassAdapter;
27 import org.jboss.classadapter.spi.ClassAdapterFactory;
28 import org.jboss.classadapter.spi.DependencyBuilder;
29 import org.jboss.config.spi.Configuration;
30 import org.jboss.joinpoint.spi.JoinpointFactoryBuilder;
31 import org.jboss.reflect.spi.ClassInfo;
32 import org.jboss.reflect.spi.TypeInfo;
33 import org.jboss.reflect.spi.TypeInfoFactory;
34 import org.jboss.repository.spi.MetaDataContextFactory;
35 import org.jboss.util.NestedRuntimeException;
36
37 /**
38  * Abstract configuration.
39  *
40  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
41  * @version $Revision: 44529 $
42  */

43 public abstract class AbstractConfiguration implements Configuration
44 {
45    /** The default bean info factory */
46    private BeanInfoFactory beanInfoFactory;
47    
48    /** The default class adaptor factory */
49    private ClassAdapterFactory classAdapterFactory;
50    
51    /** The default type info factory */
52    private TypeInfoFactory typeInfoFactory;
53    
54    /** The default type joinpoint factory builder */
55    private JoinpointFactoryBuilder joinpointFactoryBuilder;
56    
57    /** The default metadata context factory */
58    private MetaDataContextFactory metaDataContextFactory;
59    
60    /** The dependency builder */
61    private DependencyBuilder dependencyBuilder;
62
63    /**
64     * Create an abstract configuration
65     */

66    public AbstractConfiguration()
67    {
68    }
69    
70    public BeanInfo getBeanInfo(String JavaDoc className, ClassLoader JavaDoc cl) throws Throwable JavaDoc
71    {
72       ClassAdapter classAdapter = getClassAdapterFactory().getClassAdapter(className, cl);
73       return getBeanInfoFactory().getBeanInfo(classAdapter);
74    }
75    
76    public BeanInfo getBeanInfo(Class JavaDoc clazz) throws Throwable JavaDoc
77    {
78       ClassAdapter classAdapter = getClassAdapterFactory().getClassAdapter(clazz);
79       return getBeanInfoFactory().getBeanInfo(classAdapter);
80    }
81    
82    public BeanInfo getBeanInfo(TypeInfo typeInfo) throws Throwable JavaDoc
83    {
84       ClassAdapter classAdapter = getClassAdapterFactory().getClassAdapter(typeInfo);
85       return getBeanInfoFactory().getBeanInfo(classAdapter);
86    }
87    
88    public ClassInfo getClassInfo(String JavaDoc className, ClassLoader JavaDoc cl) throws Throwable JavaDoc
89    {
90       ClassAdapter classAdapter = getClassAdapterFactory().getClassAdapter(className, cl);
91       return classAdapter.getClassInfo();
92    }
93    
94    public ClassInfo getClassInfo(Class JavaDoc clazz) throws Throwable JavaDoc
95    {
96       ClassAdapter classAdapter = getClassAdapterFactory().getClassAdapter(clazz);
97       return classAdapter.getClassInfo();
98    }
99
100    public TypeInfoFactory getTypeInfoFactory()
101    {
102       if (typeInfoFactory == null)
103       {
104          try
105          {
106             typeInfoFactory = createDefaultTypeInfoFactory();
107          }
108          catch (RuntimeException JavaDoc e)
109          {
110             throw e;
111          }
112          catch (Error JavaDoc e)
113          {
114             throw e;
115          }
116          catch (Throwable JavaDoc t)
117          {
118             throw new NestedRuntimeException("Cannot create TypeInfoFactory", t);
119          }
120       }
121       return typeInfoFactory;
122    }
123
124    public JoinpointFactoryBuilder getJoinpointFactoryBuilder()
125    {
126       if (joinpointFactoryBuilder == null)
127       {
128          try
129          {
130             joinpointFactoryBuilder = createDefaultJoinpointFactoryBuilder();
131          }
132          catch (RuntimeException JavaDoc e)
133          {
134             throw e;
135          }
136          catch (Error JavaDoc e)
137          {
138             throw e;
139          }
140          catch (Throwable JavaDoc t)
141          {
142             throw new NestedRuntimeException("Cannot create JoinpointFactoryBuilder", t);
143          }
144       }
145       return joinpointFactoryBuilder;
146    }
147
148    public MetaDataContextFactory getMetaDataContextFactory()
149    {
150       if (metaDataContextFactory == null)
151       {
152          try
153          {
154             metaDataContextFactory = createDefaultMetaDataContextFactory();
155          }
156          catch (RuntimeException JavaDoc e)
157          {
158             throw e;
159          }
160          catch (Error JavaDoc e)
161          {
162             throw e;
163          }
164          catch (Throwable JavaDoc t)
165          {
166             throw new NestedRuntimeException("Cannot create MetaDataContextFactory", t);
167          }
168       }
169       return metaDataContextFactory;
170    }
171
172    public DependencyBuilder getDependencyBuilder()
173    {
174       if (dependencyBuilder == null)
175       {
176          try
177          {
178             dependencyBuilder = createDefaultDependencyBuilder();
179          }
180          catch (RuntimeException JavaDoc e)
181          {
182             throw e;
183          }
184          catch (Error JavaDoc e)
185          {
186             throw e;
187          }
188          catch (Throwable JavaDoc t)
189          {
190             throw new NestedRuntimeException("Cannot create DependencyBuilder", t);
191          }
192       }
193       return dependencyBuilder;
194    }
195
196    /**
197     * Get the BeanInfoFactory
198     *
199     * @return the BeanInfoFactory
200     * @throws Throwable for any error
201     */

202    protected BeanInfoFactory getBeanInfoFactory() throws Throwable JavaDoc
203    {
204       if (beanInfoFactory == null)
205          beanInfoFactory = createDefaultBeanInfoFactory();
206       return beanInfoFactory;
207    }
208
209    /**
210     * Get the class adapter factory
211     *
212     * @return the ClassAdapterFactory
213     * @throws Throwable for any error
214     */

215    protected ClassAdapterFactory getClassAdapterFactory() throws Throwable JavaDoc
216    {
217       if (classAdapterFactory == null)
218          classAdapterFactory = createDefaultClassAdapterFactory();
219       return classAdapterFactory;
220    }
221    
222    /**
223     * Create the default bean info factory
224     *
225     * @return the bean info factory
226     * @throws Throwable for any error
227     */

228    protected abstract BeanInfoFactory createDefaultBeanInfoFactory() throws Throwable JavaDoc;
229
230    /**
231     * Create the default class adapter factory
232     *
233     * @return the class adapter factory
234     * @throws Throwable for any error
235     */

236    protected abstract ClassAdapterFactory createDefaultClassAdapterFactory() throws Throwable JavaDoc;
237
238    /**
239     * Create the default type info factory
240     *
241     * @return the type info factory
242     * @throws Throwable for any error
243     */

244    protected abstract TypeInfoFactory createDefaultTypeInfoFactory() throws Throwable JavaDoc;
245
246    /**
247     * Create the default joinpoint factory builder
248     *
249     * @return the joinpoint factory builder
250     * @throws Throwable for any error
251     */

252    protected abstract JoinpointFactoryBuilder createDefaultJoinpointFactoryBuilder() throws Throwable JavaDoc;
253
254    /**
255     * Create the default metadata context factory
256     *
257     * @return the metadata context factory
258     * @throws Throwable for any error
259     */

260    protected abstract MetaDataContextFactory createDefaultMetaDataContextFactory() throws Throwable JavaDoc;
261
262    /**
263     * Create the default dependency builder
264     *
265     * @return the dependency builder
266     * @throws Throwable for any error
267     */

268    protected abstract DependencyBuilder createDefaultDependencyBuilder() throws Throwable JavaDoc;
269 }
270
Popular Tags