1 17 18 package org.sape.carbon.core.config.node.file; 19 20 import java.io.File ; 21 22 import org.sape.carbon.core.config.format.ConfigurationFormatService; 23 import org.sape.carbon.core.config.format.DefaultConfigurationFormatService; 24 import org.sape.carbon.core.config.node.Node; 25 import org.sape.carbon.core.config.node.NodeCreationException; 26 import org.sape.carbon.core.config.node.NodeFactory; 27 import org.sape.carbon.core.exception.InvalidParameterException; 28 29 30 39 public abstract class AbstractFileConfigurationDocumentFactory 40 implements NodeFactory { 41 42 43 private static final ConfigurationFormatService FORMAT_SERVICE = 44 new DefaultConfigurationFormatService(); 45 46 59 public Node getInstance(Node parent, String name) 60 throws NodeCreationException { 61 62 FileFolder parentFileFolder; 63 try { 64 parentFileFolder = (FileFolder) parent; 65 } catch (ClassCastException cce) { 66 throw new InvalidParameterException( 67 this.getClass(), 68 "parent is not assignable from FileFolder", cce); 69 } 70 71 if (name == null) { 74 throw new InvalidParameterException( 75 this.getClass(), 76 "name cannot be null"); 77 } 78 79 File file = new File (parentFileFolder.getInternalFileObject(), 80 name + getFileExtension()); 81 82 92 return new FileConfigurationDocument( 93 parent, 94 name, 95 getConfigurationFormatService(), 96 file); 97 } 98 99 106 protected abstract String getFileExtension(); 107 108 119 protected ConfigurationFormatService getConfigurationFormatService() { 120 return AbstractFileConfigurationDocumentFactory.FORMAT_SERVICE; 121 } 122 } | Popular Tags |