1 19 20 package org.netbeans.modules.j2ee.oc4j.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.oc4j.config.gen.OrionApplication; 28 import org.openide.ErrorManager; 29 import org.openide.filesystems.FileUtil; 30 import org.openide.loaders.DataObjectNotFoundException; 31 32 38 public class EarDeploymentConfiguration extends OC4JDeploymentConfiguration { 39 40 private File file; 41 private OrionApplication orionApplication; 42 43 46 public EarDeploymentConfiguration(DeployableObject deployableObject) { 47 super(deployableObject); 48 } 49 50 56 public void init(File file, File resourceDir) { 57 super.init(resourceDir); 58 this.file = file; 59 getOC4JApplication(); 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 OrionApplication getOC4JApplication() { 76 if (orionApplication == null) { 77 try { 78 if (file.exists()) { 79 try { 81 orionApplication = orionApplication.createGraph(file); 82 } catch (IOException ioe) { 83 ErrorManager.getDefault().notify(ioe); 84 } catch (RuntimeException re) { 85 } 87 } else { 88 orionApplication = genereateOC4JApplication(); 90 writefile(file, orionApplication); 91 } 92 } catch (ConfigurationException ce) { 93 ErrorManager.getDefault().notify(ce); 94 } 95 } 96 return orionApplication; 97 } 98 99 101 public void save(OutputStream os) throws ConfigurationException { 102 OrionApplication orionApplication = getOC4JApplication(); 103 if (orionApplication == null) { 104 throw new ConfigurationException ("Cannot read configuration, it is probably in an inconsistent state."); } 106 try { 107 orionApplication.write(os); 108 } catch (IOException ioe) { 109 throw new ConfigurationException (ioe.getLocalizedMessage()); 110 } 111 } 112 113 115 118 private OrionApplication genereateOC4JApplication() { 119 return new OrionApplication(); 120 } 121 } | Popular Tags |