001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.deployment.spi.configurations;
023:
024: import java.io.ByteArrayInputStream;
025: import java.io.InputStream;
026: import java.io.OutputStream;
027: import java.util.HashMap;
028: import java.util.Iterator;
029: import java.util.jar.JarOutputStream;
030:
031: import javax.enterprise.deploy.model.DDBeanRoot;
032: import javax.enterprise.deploy.model.DeployableObject;
033: import javax.enterprise.deploy.spi.DConfigBeanRoot;
034: import javax.enterprise.deploy.spi.DeploymentConfiguration;
035: import javax.enterprise.deploy.spi.exceptions.BeanNotFoundException;
036: import javax.enterprise.deploy.spi.exceptions.ConfigurationException;
037:
038: import org.jboss.deployment.spi.DeploymentMetaData;
039: import org.jboss.deployment.spi.JarUtils;
040: import org.jboss.deployment.spi.beans.JBossConfigBeanProxy;
041: import org.jboss.deployment.spi.beans.WarConfigBeanRoot;
042:
043: /**
044: * The war configuration container.
045: *
046: * @author Rob Stryker
047: * @version $Revision: 57190 $
048: */
049: public class WarConfiguration implements DeploymentConfiguration {
050:
051: private DeployableObject deployable;
052: private HashMap configBeans;
053:
054: public WarConfiguration(DeployableObject deployable) {
055: this .deployable = deployable;
056: configBeans = new HashMap(); // maps filename to dconfigbean
057:
058: }
059:
060: public DeployableObject getDeployableObject() {
061: return this .deployable;
062: }
063:
064: public DConfigBeanRoot getDConfigBeanRoot(DDBeanRoot dd)
065: throws ConfigurationException {
066: // If they give us web.xml, return our jboss-web.xml config bean
067: if (configBeans.containsKey(dd.getFilename())) {
068: return (DConfigBeanRoot) configBeans.get(dd.getFilename());
069: }
070:
071: // Not found, so create it. (lazy initializing)
072: if (dd.getFilename().equals("WEB-INF/web.xml")) {
073: DConfigBeanRoot retval = new WarConfigBeanRoot(dd,
074: deployable);
075: configBeans.put(dd.getFilename(), retval);
076: return retval;
077: }
078:
079: // if they give us some other standard bean, return the jboss specific
080: // None implemented as of now
081: return null;
082: }
083:
084: public void removeDConfigBean(DConfigBeanRoot bean)
085: throws BeanNotFoundException {
086: String key = bean.getDDBean().getRoot().getFilename();
087: if (configBeans.containsKey(key)) {
088: System.out.println("its here... not anymore");
089: configBeans.remove(key);
090: } else {
091: throw new BeanNotFoundException("BNF");
092: }
093: }
094:
095: public void save(OutputStream stream) throws ConfigurationException {
096: JarOutputStream jos = null;
097:
098: // Setup deployment plan meta data with propriatary descriptor (jboss-web.xml)
099: DeploymentMetaData metaData = new DeploymentMetaData(
100: "WRONG.war");
101:
102: try {
103: jos = new JarOutputStream(stream);
104: } catch (Exception e) {
105: return;
106: }
107: if (jos == null)
108: return;
109:
110: Iterator setIterator = configBeans.keySet().iterator();
111: while (setIterator.hasNext()) {
112: String key = (String) setIterator.next();
113: JBossConfigBeanProxy val = (JBossConfigBeanProxy) configBeans
114: .get(key);
115: val.save(jos, metaData);
116: }
117: try {
118: String metaStr = metaData.toXMLString();
119: JarUtils.addJarEntry(jos, DeploymentMetaData.ENTRY_NAME,
120: new ByteArrayInputStream(metaStr.getBytes()));
121: jos.flush();
122: jos.close();
123: } catch (Exception e) {
124: System.out.println("config IO exception error: "
125: + e.getMessage());
126: }
127: }
128:
129: public DConfigBeanRoot restoreDConfigBean(InputStream arg0,
130: DDBeanRoot arg1) throws ConfigurationException {
131: return null;
132: }
133:
134: public void saveDConfigBean(OutputStream arg0, DConfigBeanRoot arg1)
135: throws ConfigurationException {
136: }
137:
138: public void restore(InputStream arg0) throws ConfigurationException {
139: }
140:
141: }
|