1 19 20 package org.netbeans.modules.j2ee.weblogic9.config; 21 22 import java.io.BufferedOutputStream ; 23 import java.io.File ; 24 import java.io.IOException ; 25 import java.io.InputStream ; 26 import java.io.OutputStream ; 27 import javax.enterprise.deploy.model.DDBeanRoot ; 28 import javax.enterprise.deploy.model.DeployableObject ; 29 import javax.enterprise.deploy.spi.DConfigBeanRoot ; 30 import javax.enterprise.deploy.spi.DeploymentConfiguration ; 31 import javax.enterprise.deploy.spi.exceptions.BeanNotFoundException ; 32 import javax.enterprise.deploy.spi.exceptions.ConfigurationException ; 33 import org.netbeans.modules.schema2beans.BaseBean; 34 import org.openide.filesystems.FileLock; 35 import org.openide.filesystems.FileObject; 36 import org.openide.filesystems.FileSystem; 37 import org.openide.filesystems.FileUtil; 38 import org.openide.loaders.DataObject; 39 import org.openide.util.NbBundle; 40 41 46 public abstract class WLDeploymentConfiguration implements DeploymentConfiguration { 47 48 protected DeployableObject deplObj; 49 protected DataObject dataObject; 50 51 54 public WLDeploymentConfiguration (DeployableObject deplObj) { 55 this.deplObj = deplObj; 56 } 57 58 public DataObject getDataObject() { 59 return dataObject; 60 } 61 62 64 public DeployableObject getDeployableObject () { 65 return deplObj; 66 } 67 68 70 public DConfigBeanRoot getDConfigBeanRoot (DDBeanRoot dDBeanRoot) 71 throws ConfigurationException { 72 return null; 73 } 74 75 public void removeDConfigBean (DConfigBeanRoot dConfigBeanRoot) 76 throws BeanNotFoundException { 77 throw new BeanNotFoundException ("bean not found " + dConfigBeanRoot); } 79 80 public void restore (InputStream is) 81 throws ConfigurationException { 82 } 83 84 public DConfigBeanRoot restoreDConfigBean (InputStream is, DDBeanRoot dDBeanRoot) 85 throws ConfigurationException { 86 return null; 87 } 88 89 public void saveDConfigBean (OutputStream os, DConfigBeanRoot dConfigBeanRoot) 90 throws ConfigurationException { 91 } 92 93 95 protected void writefile(final File file, final BaseBean bean) throws ConfigurationException { 96 try { 97 FileObject cfolder = FileUtil.toFileObject(file.getParentFile()); 98 if (cfolder == null) { 99 File parentFile = file.getParentFile(); 100 try { 101 cfolder = FileUtil.toFileObject(parentFile.getParentFile()).createFolder(parentFile.getName()); 102 } catch (IOException ioe) { 103 throw new ConfigurationException (NbBundle.getMessage(WLDeploymentConfiguration.class, "MSG_FailedToCreateConfigFolder", parentFile.getAbsolutePath())); 104 } 105 } 106 final FileObject folder = cfolder; 107 FileSystem fs = folder.getFileSystem(); 108 fs.runAtomicAction(new FileSystem.AtomicAction() { 109 public void run() throws IOException { 110 OutputStream os = null; 111 FileLock lock = null; 112 try { 113 String name = file.getName(); 114 FileObject configFO = folder.getFileObject(name); 115 if (configFO == null) { 116 configFO = folder.createData(name); 117 } 118 lock = configFO.lock(); 119 os = new BufferedOutputStream (configFO.getOutputStream(lock), 4086); 120 if (bean != null) { 122 bean.write(os); 123 } 124 } finally { 125 if (os != null) { 126 try { os.close(); } catch(IOException ioe) {} 127 } 128 if (lock != null) 129 lock.releaseLock(); 130 } 131 } 132 }); 133 } catch (IOException e) { 134 throw new ConfigurationException (e.getLocalizedMessage ()); 135 } 136 } 137 } 138 | Popular Tags |