1 19 20 package org.netbeans.modules.j2ee.weblogic9.config; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.io.OutputStream ; 25 import javax.enterprise.deploy.model.DeployableObject ; 26 import javax.enterprise.deploy.spi.exceptions.ConfigurationException ; 27 import org.netbeans.modules.j2ee.weblogic9.config.gen.WeblogicApplication; 28 import org.openide.ErrorManager; 29 import org.openide.filesystems.FileUtil; 30 import org.openide.loaders.DataObjectNotFoundException; 31 32 33 39 public class EarDeploymentConfiguration extends WLDeploymentConfiguration { 40 41 private File file; 42 private WeblogicApplication weblogicApplication; 43 44 47 public EarDeploymentConfiguration(DeployableObject deployableObject) { 48 super(deployableObject); 49 } 50 51 57 public void init(File file) { 58 this.file = file; 59 getWeblogicApplication(); 60 if (dataObject == null) { 61 try { 62 dataObject = dataObject.find(FileUtil.toFileObject(file)); 63 } catch(DataObjectNotFoundException donfe) { 64 ErrorManager.getDefault().notify(donfe); 65 } 66 } 67 } 68 69 75 public synchronized WeblogicApplication getWeblogicApplication() { 76 if (weblogicApplication == null) { 77 try { 78 if (file.exists()) { 79 try { 81 weblogicApplication = weblogicApplication.createGraph(file); 82 } catch (IOException ioe) { 83 ErrorManager.getDefault().notify(ioe); 84 } catch (RuntimeException re) { 85 } 87 } else { 88 weblogicApplication = genereateweblogicApplication(); 90 writefile(file, weblogicApplication); 91 } 92 } catch (ConfigurationException ce) { 93 ErrorManager.getDefault().notify(ce); 94 } 95 } 96 return weblogicApplication; 97 } 98 99 101 public void save(OutputStream os) throws ConfigurationException { 102 WeblogicApplication weblogicApplication = getWeblogicApplication(); 103 if (weblogicApplication == null) { 104 throw new ConfigurationException ("Cannot read configuration, it is probably in an inconsistent state."); } 106 try { 107 weblogicApplication.write(os); 108 } catch (IOException ioe) { 109 throw new ConfigurationException (ioe.getLocalizedMessage()); 110 } 111 } 112 113 115 118 private WeblogicApplication genereateweblogicApplication() { 119 return new WeblogicApplication(); 120 } 121 } 122 | Popular Tags |