KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > deployment > spi > configurations > WarConfiguration


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.configurations;
23
24 import java.io.ByteArrayInputStream JavaDoc;
25 import java.io.InputStream JavaDoc;
26 import java.io.OutputStream JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.jar.JarOutputStream JavaDoc;
30
31 import javax.enterprise.deploy.model.DDBeanRoot JavaDoc;
32 import javax.enterprise.deploy.model.DeployableObject JavaDoc;
33 import javax.enterprise.deploy.spi.DConfigBeanRoot JavaDoc;
34 import javax.enterprise.deploy.spi.DeploymentConfiguration JavaDoc;
35 import javax.enterprise.deploy.spi.exceptions.BeanNotFoundException JavaDoc;
36 import javax.enterprise.deploy.spi.exceptions.ConfigurationException JavaDoc;
37
38 import org.jboss.deployment.spi.DeploymentMetaData;
39 import org.jboss.deployment.spi.JarUtils;
40 import org.jboss.deployment.spi.beans.JBossConfigBeanProxy;
41 import org.jboss.deployment.spi.beans.WarConfigBeanRoot;
42
43 /**
44  * The war configuration container.
45  *
46  * @author Rob Stryker
47  * @version $Revision: 38480 $
48  */

49 public class WarConfiguration implements DeploymentConfiguration JavaDoc
50 {
51
52    private DeployableObject JavaDoc deployable;
53    private HashMap JavaDoc configBeans;
54
55    public WarConfiguration(DeployableObject JavaDoc deployable)
56    {
57       this.deployable = deployable;
58       configBeans = new HashMap JavaDoc(); // maps filename to dconfigbean
59

60    }
61
62    public DeployableObject JavaDoc getDeployableObject()
63    {
64       return this.deployable;
65    }
66
67    public DConfigBeanRoot JavaDoc getDConfigBeanRoot(DDBeanRoot JavaDoc dd) throws ConfigurationException JavaDoc
68    {
69       // If they give us web.xml, return our jboss-web.xml config bean
70
if (configBeans.containsKey(dd.getFilename()))
71       {
72          return (DConfigBeanRoot JavaDoc)configBeans.get(dd.getFilename());
73       }
74
75       // Not found, so create it. (lazy initializing)
76
if (dd.getFilename().equals("WEB-INF/web.xml"))
77       {
78          DConfigBeanRoot JavaDoc retval = new WarConfigBeanRoot(dd, deployable);
79          configBeans.put(dd.getFilename(), retval);
80          return retval;
81       }
82
83       // if they give us some other standard bean, return the jboss specific
84
// None implemented as of now
85
return null;
86    }
87
88    public void removeDConfigBean(DConfigBeanRoot JavaDoc bean) throws BeanNotFoundException JavaDoc
89    {
90       String JavaDoc key = bean.getDDBean().getRoot().getFilename();
91       if (configBeans.containsKey(key))
92       {
93          System.out.println("its here... not anymore");
94          configBeans.remove(key);
95       }
96       else
97       {
98          throw new BeanNotFoundException JavaDoc("BNF");
99       }
100    }
101
102    public void save(OutputStream JavaDoc stream) throws ConfigurationException JavaDoc
103    {
104       JarOutputStream JavaDoc jos = null;
105
106       // Setup deployment plan meta data with propriatary descriptor (jboss-web.xml)
107
DeploymentMetaData metaData = new DeploymentMetaData("WRONG.war");
108
109       try
110       {
111          jos = new JarOutputStream JavaDoc(stream);
112       }
113       catch (Exception JavaDoc e)
114       {
115          return;
116       }
117       if (jos == null)
118          return;
119
120       Iterator JavaDoc setIterator = configBeans.keySet().iterator();
121       while (setIterator.hasNext())
122       {
123          String JavaDoc key = (String JavaDoc)setIterator.next();
124          JBossConfigBeanProxy val = (JBossConfigBeanProxy)configBeans.get(key);
125          val.save(jos, metaData);
126       }
127       try
128       {
129          String JavaDoc metaStr = metaData.toXMLString();
130          JarUtils.addJarEntry(jos, DeploymentMetaData.ENTRY_NAME, new ByteArrayInputStream JavaDoc(metaStr.getBytes()));
131          jos.flush();
132          jos.close();
133       }
134       catch (Exception JavaDoc e)
135       {
136          System.out.println("config IO exception error: " + e.getMessage());
137       }
138    }
139
140    public DConfigBeanRoot JavaDoc restoreDConfigBean(InputStream JavaDoc arg0, DDBeanRoot JavaDoc arg1) throws ConfigurationException JavaDoc
141    {
142       return null;
143    }
144
145    public void saveDConfigBean(OutputStream JavaDoc arg0, DConfigBeanRoot JavaDoc arg1) throws ConfigurationException JavaDoc
146    {
147    }
148
149    public void restore(InputStream JavaDoc arg0) throws ConfigurationException JavaDoc
150    {
151    }
152
153 }
154
Popular Tags