KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > deployment > spi > beans > JBossExample2ConfigBeanRoot


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.deployment.spi.beans;
23
24 import javax.enterprise.deploy.model.DDBean JavaDoc;
25 import javax.enterprise.deploy.model.DDBeanRoot JavaDoc;
26 import javax.enterprise.deploy.model.DeployableObject JavaDoc;
27 import javax.enterprise.deploy.spi.DConfigBean JavaDoc;
28 import javax.enterprise.deploy.spi.DConfigBeanRoot JavaDoc;
29 import javax.enterprise.deploy.spi.exceptions.ConfigurationException JavaDoc;
30
31 /**
32  * This class is an example of how to build config beans based on a number of
33  * required xpaths for a deployment descriptor.
34  *
35  * The required xpaths for this example class are: root-element/sub-element[@id]
36  * root-element/sub-element/name root-element/sub-element/class
37  *
38  * root-element/other-sub/name root-element/other-sub/description
39  *
40  * This example class will return the xpaths as ONE list. Any attempt to get a
41  * child bean will return a null-bean, as the children beans will not require
42  * additional xpaths.
43  * @author Rob Stryker
44  * @version $Revision: 38480 $
45  *
46  * TODO To change the template for this generated type comment go to
47  * Window - Preferences - Java - Code Style - Code Templates
48  */

49
50 public class JBossExample2ConfigBeanRoot extends JBossConfigBeanProxy implements DConfigBeanRoot JavaDoc
51 {
52
53    public JBossExample2ConfigBeanRoot(DDBeanRoot JavaDoc root)
54    {
55       JBossExample2MainConfigBean bean = new JBossExample2MainConfigBean(root, this, null);
56       DeployableObject JavaDoc deployment = root.getDeployableObject();
57       setBean(bean, deployment);
58    }
59
60    public DConfigBean JavaDoc getDConfigBean(DDBeanRoot JavaDoc arg0)
61    {
62       /*
63        * Get the filename for this bean root and send along
64        * a configbean for that type.
65        *
66        * This example assumes only one jboss-specific descriptor,
67        * so this method returns null.
68        */

69       return null;
70    }
71
72    private class JBossExample2MainConfigBean extends AbstractJBossConfigBean
73    {
74       public JBossExample2MainConfigBean(DDBean JavaDoc bean, DConfigBeanRoot JavaDoc root, ConfigBeanXPaths path)
75       {
76          super(bean, root, path);
77       }
78
79       /**
80        * In this example, every required xpath will be returned in ONE list.
81        *
82        * The required xpaths for this example class are: root-element/sub-element[@id]
83        * root-element/sub-element/name root-element/sub-element/class
84        *
85        * root-element/other-sub/name root-element/other-sub/description
86        */

87       protected ConfigBeanXPaths buildXPathList()
88       {
89          ConfigBeanXPaths pathRoot = new ConfigBeanXPaths("", null);
90
91          //ConfigBeanXPaths contextRoot =
92
new ConfigBeanXPaths("root-element/sub-element", pathRoot);
93          new ConfigBeanXPaths("root-element/other-sub", pathRoot);
94          return pathRoot;
95       }
96
97       /**
98        * Overloading the super-implementation so that we can return subtypes,
99        * such as JBossExample2SubElementConfigBean or JBossExample2OtherSubConfigBean
100        */

101       public DConfigBean JavaDoc getDConfigBean(DDBean JavaDoc bean) throws ConfigurationException JavaDoc
102       {
103          // get a child bean
104
String JavaDoc path = bean.getXpath();
105          ConfigBeanXPaths cPath = (ConfigBeanXPaths)xpaths.get(path);
106          if (cPath == null)
107          {
108             throw new ConfigurationException JavaDoc("Config Bean Not Found");
109          }
110
111          AbstractJBossConfigBean retBean;
112          if (bean.getXpath().equals("root-element/sub-element"))
113          {
114             retBean = new JBossExample2SubElementConfigBean(bean, this.myRoot, cPath);
115          }
116          else if (bean.getXpath().equals("root-element/other-sub"))
117          {
118             retBean = new JBossExample2OtherSubConfigBean(bean, this.myRoot, cPath);
119          }
120          else
121          {
122             retBean = new JBossNullConfigBean(bean, this.myRoot, cPath);
123          }
124
125          children.add(retBean);
126          return retBean;
127       }
128    }
129
130    public class JBossExample2SubElementConfigBean extends AbstractJBossConfigBean
131    {
132       public JBossExample2SubElementConfigBean(DDBean JavaDoc bean, DConfigBeanRoot JavaDoc root, ConfigBeanXPaths path)
133       {
134          super(bean, root, path);
135       }
136
137       /**
138        * The required xpaths for this example class are: root-element/sub-element[@id]
139        * root-element/sub-element/name root-element/sub-element/class
140        *
141        * However this class is a sub-element type, so we only need
142        * @id name class
143        */

144
145       protected ConfigBeanXPaths buildXPathList()
146       {
147          ConfigBeanXPaths pathRoot = new ConfigBeanXPaths("", null);
148          new ConfigBeanXPaths("@id", pathRoot);
149          new ConfigBeanXPaths("name", pathRoot);
150          new ConfigBeanXPaths("class", pathRoot);
151          return pathRoot;
152       }
153
154    }
155
156    public class JBossExample2OtherSubConfigBean extends AbstractJBossConfigBean
157    {
158       public JBossExample2OtherSubConfigBean(DDBean JavaDoc bean, DConfigBeanRoot JavaDoc root, ConfigBeanXPaths path)
159       {
160          super(bean, root, path);
161       }
162
163       /**
164        * The required xpaths for this example class are: root-element/other-sub/name
165        * root-element/other-sub/description
166        *
167        * However this class is a sub-element type, so we only need name
168        * description
169        */

170       protected ConfigBeanXPaths buildXPathList()
171       {
172          ConfigBeanXPaths pathRoot = new ConfigBeanXPaths("", null);
173          new ConfigBeanXPaths("name", pathRoot);
174          new ConfigBeanXPaths("description", pathRoot);
175          return pathRoot;
176       }
177    }
178 }
179
Popular Tags