1 17 18 package org.sape.carbon.core.config.node.file; 19 20 import java.io.File ; 21 import java.io.FileInputStream ; 22 import java.io.FileOutputStream ; 23 import java.io.IOException ; 24 import java.io.InputStream ; 25 import java.io.OutputStream ; 26 27 import org.sape.carbon.core.config.format.ConfigurationFormatService; 28 import org.sape.carbon.core.config.node.AbstractConfigurationDocument; 29 import org.sape.carbon.core.config.node.Node; 30 import org.sape.carbon.core.config.node.NodeRemovalException; 31 import org.sape.carbon.core.exception.InvalidParameterException; 32 33 47 public class FileConfigurationDocument extends AbstractConfigurationDocument { 48 49 50 private File file; 51 52 53 62 public FileConfigurationDocument( 63 Node parent, 64 String name, 65 ConfigurationFormatService formatter, 66 File file) { 67 68 super(parent, name, formatter); 69 70 if (file != null) { 71 this.file = file; 72 } else { 73 throw new InvalidParameterException( 74 this.getClass(), 75 "The [" 76 + getAbsoluteName() 77 + "] FileConfigurationDocument " 78 + "node file reference cannot be null"); 79 } 80 } 81 82 83 86 protected void destroyBackingData() throws NodeRemovalException { 87 if (!this.file.delete()) { 88 throw new NodeRemovalException( 91 this.getClass(), 92 this, 93 "File.delete() returned false"); 94 } 95 } 96 97 100 protected InputStream openInputStream() throws IOException { 101 return new FileInputStream (this.file); 102 } 103 104 107 protected OutputStream openOutputStream() throws IOException { 108 return new FileOutputStream (this.file); 109 } 110 111 114 protected boolean backingDataExists() { 115 return (this.file.exists() && !this.file.isDirectory()); 116 } 117 118 } | Popular Tags |