1 19 package org.netbeans.modules.j2ee.websphere6.config; 20 21 import java.io.File ; 22 import java.io.FileNotFoundException ; 23 import java.io.FileOutputStream ; 24 import java.io.IOException ; 25 import java.io.OutputStream ; 26 import java.io.StringReader ; 27 import java.util.Date ; 28 import java.util.Iterator ; 29 import javax.enterprise.deploy.model.DeployableObject ; 30 import javax.enterprise.deploy.spi.exceptions.ConfigurationException ; 31 import javax.xml.namespace.NamespaceContext ; 32 import javax.xml.namespace.QName ; 33 import javax.xml.transform.stream.StreamSource ; 34 import javax.xml.xpath.XPathExpressionException ; 35 import javax.xml.xpath.XPathVariableResolver ; 36 import org.netbeans.modules.j2ee.deployment.plugins.api.*; 37 import org.netbeans.modules.j2ee.websphere6.config.sync.EjbSynchronizer; 38 import org.netbeans.modules.j2ee.websphere6.dd.beans.DDXmiConstants; 39 import org.netbeans.modules.j2ee.websphere6.dd.beans.EjbBindingsType; 40 import org.netbeans.modules.j2ee.websphere6.dd.beans.WSEjbBnd; 41 import org.netbeans.modules.j2ee.websphere6.dd.beans.WSEjbExt; 42 import org.netbeans.modules.j2ee.websphere6.util.*; 43 import org.openide.ErrorManager; 44 import org.openide.filesystems.FileChangeAdapter; 45 import org.openide.filesystems.FileUtil; 46 import org.openide.loaders.*; 47 import javax.enterprise.deploy.spi.DeploymentManager ; 48 import javax.enterprise.deploy.spi.exceptions.InvalidModuleException ; 49 import javax.xml.parsers.DocumentBuilder ; 50 import javax.xml.parsers.DocumentBuilderFactory ; 51 import javax.xml.transform.Transformer ; 52 import javax.xml.transform.TransformerException ; 53 import javax.xml.transform.TransformerFactory ; 54 import javax.xml.transform.dom.DOMSource ; 55 import javax.xml.transform.stream.StreamResult ; 56 import javax.xml.xpath.XPath ; 57 import javax.xml.xpath.XPathConstants ; 58 import javax.xml.xpath.XPathFactory ; 59 import javax.xml.xpath.XPathFactoryConfigurationException ; 60 import org.openide.filesystems.FileEvent; 61 import org.openide.filesystems.FileObject; 62 import org.w3c.dom.Attr ; 63 import org.w3c.dom.Document ; 64 import org.w3c.dom.Element ; 65 import org.w3c.dom.Node ; 66 import org.w3c.dom.NodeList ; 67 import org.xml.sax.EntityResolver ; 68 69 77 public class EjbDeploymentConfiguration extends WSDeploymentConfiguration { 78 private File [] files; 79 80 private WSEjbExt WSEjbJarExt; 81 private WSEjbBnd WSEjbJarBnd; 82 83 84 private String IDENTITY_XSLT_WITH_INDENT = 85 "<xsl:stylesheet version='1.0' " + "xmlns:xsl='http://www.w3.org/1999/XSL/Transform' " + "xmlns:xalan='http://xml.apache.org/xslt' " + "exclude-result-prefixes='xalan'>" + "<xsl:output method='xml' indent='yes' " + "xalan:indent-amount='4'/>" + "<xsl:template match='@*|node()'>" + "<xsl:copy>" + "<xsl:apply-templates select='@*|node()'/>" + "</xsl:copy>" + "</xsl:template>" + "</xsl:stylesheet>"; 98 99 102 public EjbDeploymentConfiguration(DeploymentManager dm, 103 DeployableObject deployableObject, 104 InstanceProperties ip) throws InvalidModuleException { 105 super(dm,deployableObject,ip); 106 } 107 108 114 public void init(File [] files) { 115 this.files = files; 116 getWSEjbJarExt(); 117 getWSEjbJarBnd(); 118 119 String path = 120 ((files.length > 0) ? files[0].getParent() : ""); 122 File ejbJar = 123 new File (path + File.separator + "ejb-jar.xml"); 125 File ibmejbjarbndFile = null; 126 127 if (files.length > 0) { 128 if (dataObjects == null) { 129 dataObjects = new DataObject[files.length]; 130 try { 131 for (int i = 0; i < dataObjects.length; i++) { 132 dataObjects[i] = dataObjects[i].find( 133 FileUtil.toFileObject(files[i])); 134 } 135 } catch(DataObjectNotFoundException donfe) { 136 ErrorManager.getDefault().notify(donfe); 137 } 138 } 139 140 for (int i = 0; i < files.length; i++) { 141 WSDebug.notify(files[i].getName()); 142 if (files[i].getName().equals("ibm-ejb-jar-bnd.xmi")) { 143 ibmejbjarbndFile = files[i]; 144 } 145 } 146 } 147 148 if (ejbJar.exists()) { 149 String contents = WSUtil.readFile(ejbJar); 150 151 String ID = "id=\"ID_ejb_jar\""; 152 if(contents!=null && contents.indexOf(ID)==-1) { 153 String EjbJarTagOpen = "<ejb-jar"; 154 String EjbJarTagClose = ">"; 155 int startIndex = contents.indexOf(EjbJarTagOpen); 156 if(startIndex!=-1) { 157 String afterTageOpen = contents.substring(startIndex + EjbJarTagOpen.length()); 158 String tag = afterTageOpen.substring(0,afterTageOpen.indexOf(EjbJarTagClose)); 159 if(tag.indexOf(ID)==-1) { 160 WSUtil.writeFile(ejbJar , contents.replaceFirst(EjbJarTagOpen + " ", 161 EjbJarTagOpen + " " + ID +" \n ")); 162 } 163 } 164 } 165 166 final EjbSynchronizer ejbSync = new EjbSynchronizer(ejbJar, ibmejbjarbndFile); 167 ejbSync.addSyncFile(ejbJar); 168 } 169 } 170 171 178 public synchronized WSEjbExt getWSEjbJarExt() { 179 if (WSEjbJarExt == null) { 180 try { 181 for (int i = 0; i < files.length; i++) { 182 if (!files[i].getName().equals("ibm-ejb-jar-ext.xmi")) { 183 continue; 184 } 185 186 if (files[i].exists()) { 187 try { 188 WSEjbJarExt = new WSEjbExt(files[i],false); 189 } catch (IOException ioe) { 190 ErrorManager.getDefault().notify(ioe); 191 } catch (RuntimeException re) { 192 } 194 } else { 195 WSEjbJarExt = new WSEjbExt(); 197 WSEjbJarExt.setDefaults(); 198 writefile(files[i], WSEjbJarExt); 199 } 200 } 201 } catch (ConfigurationException ce) { 202 ErrorManager.getDefault().notify(ce); 203 } 204 } 205 206 return WSEjbJarExt; 207 } 208 209 216 public synchronized WSEjbBnd getWSEjbJarBnd() { 217 if (WSEjbJarBnd == null) { 218 try { 219 for (int i = 0; i < files.length; i++) { 220 if (!files[i].getName().equals("ibm-ejb-jar-bnd.xmi")) { 221 continue; 222 } 223 224 if (files[i].exists()) { 225 try { 226 WSEjbJarBnd = new WSEjbBnd(files[i], false); 227 } catch (IOException ioe) { 228 ErrorManager.getDefault().notify(ioe); 229 } catch (RuntimeException re) { 230 } 232 } else { 233 WSEjbJarBnd = new WSEjbBnd(); 234 WSEjbJarBnd.setDefaults(); 235 writefile(files[i], WSEjbJarBnd); 236 } 237 } 238 } catch (ConfigurationException ce) { 239 ErrorManager.getDefault().notify(ce); 240 } 241 } 242 243 return WSEjbJarBnd; 244 } 245 private class EjbJarNSC implements NamespaceContext { 246 public String getPrefix(String namespaceURI) { 247 return "ejbbnd"; 248 } 249 public String getNamespaceURI(String prefix) { 250 return "ejbbnd.xmi"; 251 } 252 public Iterator getPrefixes(String namespaceURI) { 253 return null; 254 } 255 } 256 257 } 258 | Popular Tags |