1 19 20 package org.netbeans.modules.j2ee.jboss4.config; 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.jboss4.config.gen.JbossApp; 27 import org.openide.ErrorManager; 28 import org.openide.filesystems.FileUtil; 29 import org.openide.loaders.DataObjectNotFoundException; 30 31 32 38 public class EarDeploymentConfiguration extends JBDeploymentConfiguration { 39 40 private File jbossAppFile; 41 private JbossApp jbossApp; 42 43 46 public EarDeploymentConfiguration(DeployableObject deployableObject) { 47 super(deployableObject); 48 } 49 50 56 public void init(File file) { 57 this.jbossAppFile = file; 58 getJbossApp(); 59 if (deploymentDescriptorDO == null) { 60 try { 61 deploymentDescriptorDO = deploymentDescriptorDO.find(FileUtil.toFileObject(jbossAppFile)); 62 } catch(DataObjectNotFoundException donfe) { 63 ErrorManager.getDefault().notify(donfe); 64 } 65 } 66 } 67 68 74 public synchronized JbossApp getJbossApp() { 75 if (jbossApp == null) { 76 try { 77 if (jbossAppFile.exists()) { 78 try { 80 jbossApp = jbossApp.createGraph(jbossAppFile); 81 } catch (IOException ioe) { 82 ErrorManager.getDefault().notify(ioe); 83 } catch (RuntimeException re) { 84 } 86 } else { 87 jbossApp = genereatejbossApp(); 89 writefile(jbossAppFile, jbossApp); 90 } 91 } catch (ConfigurationException ce) { 92 ErrorManager.getDefault().notify(ce); 93 } 94 } 95 return jbossApp; 96 } 97 98 100 public void save(OutputStream os) throws ConfigurationException { 101 JbossApp jbossApp = getJbossApp(); 102 if (jbossApp == null) { 103 throw new ConfigurationException ("Cannot read configuration, it is probably in an inconsistent state."); } 105 try { 106 jbossApp.write(os); 107 } catch (IOException ioe) { 108 throw new ConfigurationException (ioe.getLocalizedMessage()); 109 } 110 } 111 112 114 117 private JbossApp genereatejbossApp() { 118 return new JbossApp(); 119 } 120 } 121 | Popular Tags |