1 19 package org.netbeans.modules.j2ee.websphere6.config; 20 21 import java.io.File ; 22 import java.io.IOException ; 23 import java.io.OutputStream ; 24 import javax.enterprise.deploy.model.DeployableObject ; 25 import javax.enterprise.deploy.spi.exceptions.ConfigurationException ; 26 import org.netbeans.modules.j2ee.deployment.plugins.api.*; 27 import org.netbeans.modules.j2ee.websphere6.dd.beans.WSAppBnd; 28 import org.netbeans.modules.j2ee.websphere6.dd.beans.WSAppExt; 29 import org.openide.ErrorManager; 30 import org.openide.filesystems.*; 31 import org.openide.loaders.*; 32 import javax.enterprise.deploy.spi.DeploymentManager ; 33 import javax.enterprise.deploy.spi.exceptions.InvalidModuleException ; 34 import java.beans.PropertyChangeEvent ; 35 import java.beans.PropertyChangeListener ; 36 import org.netbeans.modules.j2ee.websphere6.util.*; 37 43 public class EarDeploymentConfiguration extends WSDeploymentConfiguration { 44 45 private File [] file; 46 WSAppBnd websphereApplicationBnd; 47 WSAppExt websphereApplicationExt; 48 51 public EarDeploymentConfiguration(DeploymentManager dm, 52 DeployableObject deployableObject, 53 InstanceProperties instanceProperties) throws InvalidModuleException { 54 super(dm,deployableObject,instanceProperties); 55 } 56 57 63 public void init(File [] file) { 64 this.file = file; 65 getWebSphereApplicationExt(); 66 getWebSphereApplicationBnd(); 67 68 correctDeploymentDescriptors(); 69 attachFOListener(); 70 71 if(file.length<=0) return; 72 if (dataObjects == null) { 73 dataObjects=new DataObject[file.length]; 74 for(int i=0;i<file.length;i++) { 75 if (dataObjects[i] == null) 76 try { 77 FileObject fo=FileUtil.toFileObject(file[i]); 78 dataObjects[i] = dataObjects[i].find(fo); 79 } catch(DataObjectNotFoundException donfe) { 80 ErrorManager.getDefault().notify(donfe); 81 } 82 } 83 84 } 85 } 86 87 88 89 92 public void propertyChange(PropertyChangeEvent evt) { 93 if (evt.getPropertyName() == DataObject.PROP_MODIFIED && 94 evt.getNewValue() == Boolean.FALSE) { 95 websphereApplicationExt = null; 97 websphereApplicationBnd = null; 98 } 99 } 100 101 107 public synchronized WSAppBnd getWebSphereApplicationBnd() { 108 109 try { 110 for(int i=0;i<file.length;i++) { 111 if (file[i].getName().equals("WebSphere6.dpf")) { 112 if(!file[i].exists()){writefile(file[i],null); 113 } 114 continue; 115 } 116 117 if(!(file[i].getName().equals("ibm-application-bnd.xmi"))) { 118 continue; 119 } 120 121 if(websphereApplicationBnd==null) { 122 123 if (file[i].exists()) { 124 try { 126 websphereApplicationBnd = new WSAppBnd(file[i],false); 128 } catch (IOException ioe) { 129 ErrorManager.getDefault().notify(ioe); 130 } catch (RuntimeException re) { 131 } 133 } else { 134 websphereApplicationBnd = new WSAppBnd(); 136 websphereApplicationBnd.setDefaults(); 137 writefile(file[i], websphereApplicationBnd); 138 } 139 } 140 break; 141 } 142 } catch (ConfigurationException ce) { 143 ErrorManager.getDefault().notify(ce); 144 } 145 146 return websphereApplicationBnd; 147 } 148 149 public synchronized WSAppExt getWebSphereApplicationExt() { 150 if(websphereApplicationExt==null) { 151 try { 152 for(int i=0;i<file.length;i++) { 153 if (file[i].getName().equals("WebSphere6.dpf")) { 154 if(!file[i].exists()){writefile(file[i],null); 155 } 156 continue; 157 } 158 159 if(!(file[i].getName().equals("ibm-application-ext.xmi"))) { 160 continue; 161 } 162 if (file[i].exists()) { 163 try { 165 websphereApplicationExt = new WSAppExt(file[i],false); 166 } catch (IOException ioe) { 168 ErrorManager.getDefault().notify(ioe); 169 } catch (RuntimeException re) { 170 } 172 } else { 173 websphereApplicationExt = new WSAppExt(); 175 websphereApplicationExt.setDefaults(); 176 writefile(file[i], websphereApplicationExt); 177 } 178 179 break; 180 } 181 } catch (ConfigurationException ce) { 182 ErrorManager.getDefault().notify(ce); 183 } 184 } 185 return websphereApplicationExt; 186 } 187 188 private void attachFOListener() { 189 String path = (file.length > 0) ? file[0].getPath() : ""; 190 File appInfFile = new File (path.substring(0, path.lastIndexOf(File.separator) + 1) + "application.xml"); 191 int appStart = 0; 192 if(appInfFile.exists()) { 193 FileObject fo = FileUtil.toFileObject(appInfFile); 194 195 fo.addFileChangeListener(new FileChangeAdapter() { 196 public void fileChanged(FileEvent fe) { 197 correctDeploymentDescriptors(); 198 } 199 }); 200 } 201 } 202 203 public void correctDeploymentDescriptors() { 204 if (WSDebug.isEnabled()) 205 WSDebug.notify(getClass(), "correcting application.xml"); 206 207 String path = (file.length > 0) ? file[0].getPath() : ""; 208 File appInfFile = new File (path.substring(0, path.lastIndexOf(File.separator) + 1) + "application.xml"); 209 int appStart = 0; 210 if(appInfFile.exists()) { 211 String contents = WSUtil.readFile(appInfFile); 212 if(contents != null) { 213 if((appStart=contents.indexOf("<application")) >= 0) { 214 String appAttr = contents.substring(appStart, contents.indexOf(">", appStart)); 215 if(!appAttr.contains(" id=")) { 216 WSUtil.writeFile(appInfFile , contents.replaceFirst("<application", "<application id=\"Application_ID\"\n")); 217 } 218 } 219 } 220 } 221 } 222 223 251 253 256 257 } 258 | Popular Tags |