1 22 package org.jboss.deployment.spi.configurations; 23 24 import java.io.ByteArrayInputStream ; 25 import java.io.InputStream ; 26 import java.io.OutputStream ; 27 import java.util.HashMap ; 28 import java.util.Iterator ; 29 import java.util.jar.JarOutputStream ; 30 31 import javax.enterprise.deploy.model.DDBeanRoot ; 32 import javax.enterprise.deploy.model.DeployableObject ; 33 import javax.enterprise.deploy.spi.DConfigBeanRoot ; 34 import javax.enterprise.deploy.spi.DeploymentConfiguration ; 35 import javax.enterprise.deploy.spi.exceptions.BeanNotFoundException ; 36 import javax.enterprise.deploy.spi.exceptions.ConfigurationException ; 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 49 public class WarConfiguration implements DeploymentConfiguration 50 { 51 52 private DeployableObject deployable; 53 private HashMap configBeans; 54 55 public WarConfiguration(DeployableObject deployable) 56 { 57 this.deployable = deployable; 58 configBeans = new HashMap (); 60 } 61 62 public DeployableObject getDeployableObject() 63 { 64 return this.deployable; 65 } 66 67 public DConfigBeanRoot getDConfigBeanRoot(DDBeanRoot dd) throws ConfigurationException 68 { 69 if (configBeans.containsKey(dd.getFilename())) 71 { 72 return (DConfigBeanRoot )configBeans.get(dd.getFilename()); 73 } 74 75 if (dd.getFilename().equals("WEB-INF/web.xml")) 77 { 78 DConfigBeanRoot retval = new WarConfigBeanRoot(dd, deployable); 79 configBeans.put(dd.getFilename(), retval); 80 return retval; 81 } 82 83 return null; 86 } 87 88 public void removeDConfigBean(DConfigBeanRoot bean) throws BeanNotFoundException 89 { 90 String 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 ("BNF"); 99 } 100 } 101 102 public void save(OutputStream stream) throws ConfigurationException 103 { 104 JarOutputStream jos = null; 105 106 DeploymentMetaData metaData = new DeploymentMetaData("WRONG.war"); 108 109 try 110 { 111 jos = new JarOutputStream (stream); 112 } 113 catch (Exception e) 114 { 115 return; 116 } 117 if (jos == null) 118 return; 119 120 Iterator setIterator = configBeans.keySet().iterator(); 121 while (setIterator.hasNext()) 122 { 123 String key = (String )setIterator.next(); 124 JBossConfigBeanProxy val = (JBossConfigBeanProxy)configBeans.get(key); 125 val.save(jos, metaData); 126 } 127 try 128 { 129 String metaStr = metaData.toXMLString(); 130 JarUtils.addJarEntry(jos, DeploymentMetaData.ENTRY_NAME, new ByteArrayInputStream (metaStr.getBytes())); 131 jos.flush(); 132 jos.close(); 133 } 134 catch (Exception e) 135 { 136 System.out.println("config IO exception error: " + e.getMessage()); 137 } 138 } 139 140 public DConfigBeanRoot restoreDConfigBean(InputStream arg0, DDBeanRoot arg1) throws ConfigurationException 141 { 142 return null; 143 } 144 145 public void saveDConfigBean(OutputStream arg0, DConfigBeanRoot arg1) throws ConfigurationException 146 { 147 } 148 149 public void restore(InputStream arg0) throws ConfigurationException 150 { 151 } 152 153 } 154 | Popular Tags |