KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.ByteArrayInputStream JavaDoc;
25 import java.io.InputStream JavaDoc;
26 import java.util.jar.JarOutputStream JavaDoc;
27
28 import javax.enterprise.deploy.model.DDBean JavaDoc;
29 import javax.enterprise.deploy.model.DDBeanRoot JavaDoc;
30 import javax.enterprise.deploy.model.DeployableObject JavaDoc;
31 import javax.enterprise.deploy.spi.DConfigBean JavaDoc;
32 import javax.enterprise.deploy.spi.DConfigBeanRoot JavaDoc;
33 import javax.enterprise.deploy.spi.exceptions.ConfigurationException JavaDoc;
34
35 import org.jboss.deployment.spi.DeploymentMetaData;
36 import org.jboss.deployment.spi.JarUtils;
37
38 /**
39  * This class is a jboss-web config bean with only one required xpaths for its
40  * deployment descriptor.
41  *
42  * The required xpath for this descriptor are: jboss-web/context-root
43  * @author Rob Stryker
44  * @version $Revision: 38480 $
45  */

46 public class WarConfigBeanRoot extends JBossConfigBeanProxy implements DConfigBeanRoot JavaDoc
47 {
48
49    public static final String JavaDoc jbossWebXml = "jboss-web";
50    public static final String JavaDoc jbossWebLocation = "!/WEB-INF/jboss-web.xml";
51    public static final String JavaDoc jbossWebLocationTrimmed = "jboss-web.xml";
52    public static final String JavaDoc deployPlanElement = "deployPlan";
53    public static final String JavaDoc contextRoot = "context-root";
54    public static final String JavaDoc archiveName = "archive-name";
55
56    public WarConfigBeanRoot(DDBeanRoot JavaDoc standard, DeployableObject JavaDoc deployable)
57    {
58       WarConfigBean bean = new WarConfigBean(standard, this, null);
59       setBean(bean, deployable);
60    }
61
62    public DConfigBean JavaDoc getDConfigBean(DDBeanRoot JavaDoc arg0)
63    {
64       /*
65        * Get the filename for this bean root and send along
66        * a configbean for that type.
67        *
68        * This class assumes only one jboss-specific descriptor,
69        * so this method returns null.
70        */

71       return null;
72    }
73
74    private class WarConfigBean extends AbstractJBossConfigBean
75    {
76       public WarConfigBean(DDBean JavaDoc bean, DConfigBeanRoot JavaDoc root, ConfigBeanXPaths path)
77       {
78          super(bean, root, path);
79       }
80
81       protected ConfigBeanXPaths buildXPathList()
82       {
83          ConfigBeanXPaths pathRoot = new ConfigBeanXPaths("", null);
84
85          // The constructor automatically sets parent and adds to child list of parent.
86
new ConfigBeanXPaths(jbossWebXml, pathRoot);
87          new ConfigBeanXPaths(deployPlanElement, pathRoot);
88          return pathRoot;
89       }
90
91       public DConfigBean JavaDoc getDConfigBean(DDBean JavaDoc bean) throws ConfigurationException JavaDoc
92       {
93          // get a child bean
94
String JavaDoc path = bean.getXpath();
95          ConfigBeanXPaths cPath = (ConfigBeanXPaths)xpaths.get(path);
96          if (cPath == null)
97          {
98             throw new ConfigurationException JavaDoc("Config Bean Not Found");
99          }
100
101          AbstractJBossConfigBean retBean = new JbossWebConfigBean(bean, this.myRoot, cPath);
102          children.add(retBean);
103          return retBean;
104       }
105
106       public void save(JarOutputStream JavaDoc jos, DeploymentMetaData metaData)
107       {
108          System.out.println("saving WarConfigBean");
109          DDBean JavaDoc[] jbossWeb = myBean.getChildBean(jbossWebXml);
110          DDBean JavaDoc[] deploymentPlan = myBean.getChildBean(deployPlanElement);
111          if (jbossWeb.length == 0)
112             return;
113          if (deploymentPlan.length == 0)
114             return;
115
116          DDBean JavaDoc plan = deploymentPlan[0];
117          String JavaDoc[] planNames = plan.getText(archiveName);
118          if (planNames.length == 0)
119             return;
120          String JavaDoc warFileName = planNames[0];
121
122          String JavaDoc webXml = jbossWeb[0].getText();
123          System.out.println("name: " + warFileName);
124          metaData.setDeploymentName(warFileName);
125          InputStream JavaDoc stream = new ByteArrayInputStream JavaDoc(webXml.getBytes());
126          try
127          {
128             JarUtils.addJarEntry(jos, jbossWebLocation, stream);
129             metaData.addEntry(metaData.getDeploymentName(), jbossWebLocationTrimmed);
130          }
131          catch (Exception JavaDoc e)
132          {
133             System.out.println("ERROR HERE in SAVE: " + e.getMessage());
134          }
135       }
136
137    }
138
139    public class JbossWebConfigBean extends AbstractJBossConfigBean
140    {
141       private String JavaDoc stringPath;
142
143       public JbossWebConfigBean(DDBean JavaDoc bean, DConfigBeanRoot JavaDoc root, ConfigBeanXPaths cPath)
144       {
145          super(bean, root, cPath);
146       }
147
148       protected ConfigBeanXPaths buildXPathList()
149       {
150          ConfigBeanXPaths pathRoot = new ConfigBeanXPaths("", null);
151          if (this.myPath.getPath().equals(jbossWebXml))
152             new ConfigBeanXPaths(contextRoot, pathRoot);
153          else if (this.myPath.getPath().equals(deployPlanElement))
154             new ConfigBeanXPaths(archiveName, pathRoot);
155          return pathRoot;
156       }
157
158    }
159
160 }
161
Popular Tags