1 22 package org.jboss.deployment.spi.beans; 23 24 import java.io.ByteArrayInputStream ; 25 import java.io.InputStream ; 26 import java.util.jar.JarOutputStream ; 27 28 import javax.enterprise.deploy.model.DDBean ; 29 import javax.enterprise.deploy.model.DDBeanRoot ; 30 import javax.enterprise.deploy.model.DeployableObject ; 31 import javax.enterprise.deploy.spi.DConfigBean ; 32 import javax.enterprise.deploy.spi.DConfigBeanRoot ; 33 import javax.enterprise.deploy.spi.exceptions.ConfigurationException ; 34 35 import org.jboss.deployment.spi.DeploymentMetaData; 36 import org.jboss.deployment.spi.JarUtils; 37 38 46 public class WarConfigBeanRoot extends JBossConfigBeanProxy implements DConfigBeanRoot 47 { 48 49 public static final String jbossWebXml = "jboss-web"; 50 public static final String jbossWebLocation = "!/WEB-INF/jboss-web.xml"; 51 public static final String jbossWebLocationTrimmed = "jboss-web.xml"; 52 public static final String deployPlanElement = "deployPlan"; 53 public static final String contextRoot = "context-root"; 54 public static final String archiveName = "archive-name"; 55 56 public WarConfigBeanRoot(DDBeanRoot standard, DeployableObject deployable) 57 { 58 WarConfigBean bean = new WarConfigBean(standard, this, null); 59 setBean(bean, deployable); 60 } 61 62 public DConfigBean getDConfigBean(DDBeanRoot arg0) 63 { 64 71 return null; 72 } 73 74 private class WarConfigBean extends AbstractJBossConfigBean 75 { 76 public WarConfigBean(DDBean bean, DConfigBeanRoot root, ConfigBeanXPaths path) 77 { 78 super(bean, root, path); 79 } 80 81 protected ConfigBeanXPaths buildXPathList() 82 { 83 ConfigBeanXPaths pathRoot = new ConfigBeanXPaths("", null); 84 85 new ConfigBeanXPaths(jbossWebXml, pathRoot); 87 new ConfigBeanXPaths(deployPlanElement, pathRoot); 88 return pathRoot; 89 } 90 91 public DConfigBean getDConfigBean(DDBean bean) throws ConfigurationException 92 { 93 String path = bean.getXpath(); 95 ConfigBeanXPaths cPath = (ConfigBeanXPaths)xpaths.get(path); 96 if (cPath == null) 97 { 98 throw new ConfigurationException ("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 jos, DeploymentMetaData metaData) 107 { 108 System.out.println("saving WarConfigBean"); 109 DDBean [] jbossWeb = myBean.getChildBean(jbossWebXml); 110 DDBean [] deploymentPlan = myBean.getChildBean(deployPlanElement); 111 if (jbossWeb.length == 0) 112 return; 113 if (deploymentPlan.length == 0) 114 return; 115 116 DDBean plan = deploymentPlan[0]; 117 String [] planNames = plan.getText(archiveName); 118 if (planNames.length == 0) 119 return; 120 String warFileName = planNames[0]; 121 122 String webXml = jbossWeb[0].getText(); 123 System.out.println("name: " + warFileName); 124 metaData.setDeploymentName(warFileName); 125 InputStream stream = new ByteArrayInputStream (webXml.getBytes()); 126 try 127 { 128 JarUtils.addJarEntry(jos, jbossWebLocation, stream); 129 metaData.addEntry(metaData.getDeploymentName(), jbossWebLocationTrimmed); 130 } 131 catch (Exception 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 stringPath; 142 143 public JbossWebConfigBean(DDBean bean, DConfigBeanRoot 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 |