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