KickJava   Java API By Example, From Geeks To Geeks.

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


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 JBossExample1ConfigBeanRoot extends JBossConfigBeanProxy implements DConfigBeanRoot JavaDoc
51 {
52
53    public JBossExample1ConfigBeanRoot(DDBeanRoot JavaDoc root)
54    {
55       JBossExample1MainConfigBean bean = new JBossExample1MainConfigBean(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 JBossExample1MainConfigBean extends AbstractJBossConfigBean
73    {
74       public JBossExample1MainConfigBean(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          // The constructor automatically sets parent and adds to child list of parent.
92
new ConfigBeanXPaths("root-element/sub-element[@id]", pathRoot);
93          new ConfigBeanXPaths("root-element/sub-element/name", pathRoot);
94          new ConfigBeanXPaths("root-element/sub-element/class", pathRoot);
95          new ConfigBeanXPaths("root-element/other-sub/name", pathRoot);
96          new ConfigBeanXPaths("root-element/other-sub/description", pathRoot);
97
98          return pathRoot;
99       }
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 = new JBossNullConfigBean(bean, this.myRoot, cPath);
112          children.add(retBean);
113          return retBean;
114       }
115    }
116
117 }
118
Popular Tags