KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.beans.PropertyChangeListener JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.HashMap JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.jar.JarOutputStream JavaDoc;
29
30 import javax.enterprise.deploy.model.DDBean JavaDoc;
31 import javax.enterprise.deploy.model.XpathEvent JavaDoc;
32 import javax.enterprise.deploy.spi.DConfigBean JavaDoc;
33 import javax.enterprise.deploy.spi.DConfigBeanRoot JavaDoc;
34 import javax.enterprise.deploy.spi.exceptions.BeanNotFoundException JavaDoc;
35 import javax.enterprise.deploy.spi.exceptions.ConfigurationException JavaDoc;
36
37 import org.jboss.deployment.spi.DeploymentMetaData;
38
39 /**
40  * @author Rob Stryker
41  * @version $Revision: 38480 $
42  */

43 public abstract class AbstractJBossConfigBean implements DConfigBean JavaDoc
44 {
45
46    protected DDBean JavaDoc myBean;
47    protected ArrayList JavaDoc myPropertyListeners;
48    protected HashMap JavaDoc xpaths;
49    protected DConfigBeanRoot JavaDoc myRoot;
50    protected ConfigBeanXPaths myPath;
51    protected ArrayList JavaDoc children;
52
53    public AbstractJBossConfigBean(DDBean JavaDoc bean, DConfigBeanRoot JavaDoc root, ConfigBeanXPaths path)
54    {
55       myBean = bean;
56       myRoot = root;
57       myPropertyListeners = new ArrayList JavaDoc();
58       xpaths = new HashMap JavaDoc();
59       myPath = path;
60       children = new ArrayList JavaDoc();
61
62       /*
63        * fill our map
64        * this map is to more easily parse through xpaths via map.get(string)
65        * rather than iterate through an arraylist until name matches
66        */

67
68       ConfigBeanXPaths xpathList = buildXPathList();
69       Iterator JavaDoc i = xpathList.getChildren().iterator();
70       while (i.hasNext())
71       {
72          ConfigBeanXPaths x = (ConfigBeanXPaths)i.next();
73          xpaths.put(x.getPath(), x);
74       }
75
76    }
77
78    public DDBean JavaDoc getDDBean()
79    {
80       return myBean;
81    }
82
83    public void addPropertyChangeListener(PropertyChangeListener JavaDoc pcl)
84    {
85       myPropertyListeners.add(pcl);
86    }
87
88    public void removePropertyChangeListener(PropertyChangeListener JavaDoc pcl)
89    {
90       myPropertyListeners.remove(pcl);
91    }
92
93    /**
94     * Removes the xpath of a given configbean from the list of this bean's
95     * xpaths (children so to speak). Then calls death.
96     */

97    public void removeDConfigBean(DConfigBean JavaDoc bean) throws BeanNotFoundException JavaDoc
98    {
99       //childList.remove(bean);
100
AbstractJBossConfigBean b = ((AbstractJBossConfigBean)bean);
101       Object JavaDoc o = xpaths.get(b.getPath());
102
103       if (o == null)
104       {
105          throw new BeanNotFoundException JavaDoc("Not Found");
106       }
107       children.remove(bean);
108       xpaths.remove(b.getPath());
109       b.death();
110    }
111
112    public String JavaDoc[] getXpaths()
113    {
114
115       Object JavaDoc[] paths = this.xpaths.values().toArray();
116       String JavaDoc[] retval = new String JavaDoc[paths.length];
117       for (int i = 0; i < paths.length; i++)
118       {
119          retval[i] = ((ConfigBeanXPaths)paths[i]).getPath();
120       }
121       return retval;
122
123    }
124
125    public DConfigBean JavaDoc getDConfigBean(DDBean JavaDoc bean) throws ConfigurationException JavaDoc
126    {
127       // get a child bean
128
String JavaDoc path = bean.getXpath();
129       ConfigBeanXPaths cPath = (ConfigBeanXPaths)xpaths.get(path);
130       if (cPath == null)
131       {
132          return null;
133       }
134
135       AbstractJBossConfigBean retBean = new JBossNullConfigBean(bean, this.myRoot, cPath);
136       children.add(retBean);
137       return retBean;
138    }
139
140    public class JBossNullConfigBean extends AbstractJBossConfigBean
141    {
142       public JBossNullConfigBean(DDBean JavaDoc bean, DConfigBeanRoot JavaDoc root, ConfigBeanXPaths path)
143       {
144          super(bean, root, path);
145       }
146
147       /**
148        * This bean requires no other xpaths.
149        */

150       protected ConfigBeanXPaths buildXPathList()
151       {
152          ConfigBeanXPaths pathRoot = new ConfigBeanXPaths("", null);
153          return pathRoot;
154       }
155
156       /**
157        * All children attempts will return null.
158        */

159       public DConfigBean JavaDoc getDConfigBean(DDBean JavaDoc bean) throws ConfigurationException JavaDoc
160       {
161          throw new ConfigurationException JavaDoc("Bean not found");
162       }
163    }
164
165    public String JavaDoc getPath()
166    {
167       return myPath.getPath();
168    }
169
170    /*
171     * Deletes the children, and also tells them to delete their children.
172     */

173    protected void death()
174    {
175       Iterator JavaDoc i = children.iterator();
176       while (i.hasNext())
177       {
178          AbstractJBossConfigBean b = (AbstractJBossConfigBean)i.next();
179          try
180          {
181             removeDConfigBean(b);
182          }
183          catch (BeanNotFoundException JavaDoc e)
184          {
185          }
186       }
187       xpaths.clear();
188    }
189
190    public void notifyDDChange(XpathEvent JavaDoc arg0)
191    {
192
193    }
194
195    // OVER RIDE ME
196
public void save(JarOutputStream JavaDoc stream, DeploymentMetaData metaData)
197    {
198
199    }
200
201    protected abstract ConfigBeanXPaths buildXPathList();
202
203 }
204
Popular Tags