1 17 18 package org.sape.carbon.core.config.node; 19 20 import java.io.IOException ; 21 import java.io.InputStream ; 22 import java.io.OutputStream ; 23 24 import org.sape.carbon.core.config.Configuration; 25 import org.sape.carbon.core.config.format.ConfigurationFormatException; 26 27 28 38 public class NestedConfigurationDocument 39 extends AbstractConfigurationDocument { 40 41 47 protected NestedConfigurationDocument( 48 AbstractConfigurationDocument parent, 49 String name) { 50 51 super( 52 parent, 53 name, 54 parent.getReadOrAlterNodeLock(), 55 parent.getAddOrLoadChildLock(), 56 parent.getFormatService()); 57 } 58 59 62 public Configuration readConfiguration() 63 throws NodeIOException, ConfigurationFormatException { 64 65 if (isRemoved()) { 66 throw new NodeRemovedException( 67 this.getClass(), 68 this); 69 } 70 71 return getConfiguration(); 74 } 75 76 79 public void writeConfiguration(Configuration config) 80 throws NodeIOException, ConfigurationFormatException { 81 82 if (isRemoved()) { 83 throw new NodeRemovedException( 84 this.getClass(), 85 this); 86 } 87 88 ConfigurationDocument parentDoc = 89 (ConfigurationDocument) getParent(); 90 91 Configuration parentConfig = parentDoc.readConfiguration(); 92 93 getFormatService().alterChildConfiguration( 94 parentConfig, 95 getName(), 96 config); 97 98 parentDoc.writeConfiguration(parentConfig); 99 } 100 101 105 public void onChange() { 106 issueNodeChangedEvent(); 107 } 108 109 118 protected InputStream openInputStream() throws IOException { 119 throw new UnsupportedOperationException ( 122 "openInputStream should not be " 123 + "called on NestedConfigurationDocuments"); 124 } 125 126 135 protected OutputStream openOutputStream() throws IOException { 136 throw new UnsupportedOperationException ( 139 "openOutputStream should not be " 140 + "called on NestedConfigurationDocuments"); 141 } 142 143 146 protected void destroyBackingData() throws NodeRemovalException { 147 try { 148 writeConfiguration(null); 149 150 } catch (NodeIOException nioe) { 151 throw new NodeRemovalException( 152 this.getClass(), 153 this, 154 nioe); 155 } catch (ConfigurationFormatException cfe) { 156 throw new NodeRemovalException( 157 this.getClass(), 158 this, 159 cfe); 160 } 161 } 162 163 166 protected boolean backingDataExists() { 167 try { 168 return (getConfiguration() != null); 169 170 } catch (NodeIOException e) { 171 return false; 172 } catch (ConfigurationFormatException e) { 173 return false; 174 } 175 } 176 179 public boolean isRemoved() { 180 if (getParent().isRemoved()) { 181 return true; 183 } else { 184 return super.isRemoved(); 185 } 186 } 187 188 196 private Configuration getConfiguration() 197 throws NodeIOException, ConfigurationFormatException { 198 199 Configuration parentConfig = 200 ((ConfigurationDocument) getParent()).readConfiguration(); 201 202 return 203 getFormatService().getChildConfiguration(parentConfig, getName()); 204 } 205 } 206 | Popular Tags |