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.node.Node; 23 import org.sape.carbon.core.config.node.NodeCreationException; 24 import org.sape.carbon.core.config.node.NodeFactory; 25 import org.sape.carbon.core.exception.InvalidParameterException; 26 27 35 public class FileFolderFactory 36 implements NodeFactory { 37 38 50 public Node getInstance(Node parent, String name) 51 throws NodeCreationException { 52 53 FileFolder parentFileFolder; 54 try { 55 parentFileFolder = (FileFolder) parent; 56 } catch (ClassCastException cce) { 57 throw new InvalidParameterException( 58 this.getClass(), 59 "parent is not assignable from FileFolder", cce); 60 } 61 62 if (name == null) { 63 throw new InvalidParameterException( 64 this.getClass(), 65 "name cannot be null"); 66 } 67 68 File directory = 69 new File (parentFileFolder.getInternalFileObject(), name); 70 71 if (!directory.exists()) { 72 if (!directory.mkdir()) { 73 throw new NodeCreationException( 74 this.getClass(), 75 parent, name, "Could not create directory"); 76 } 77 } 78 79 return new FileFolder( 80 parent, 81 name, 82 parentFileFolder.getSubFolderFactory(), 83 parentFileFolder.getConfigurationDocumentFactory(), 84 parentFileFolder.getLinkNodeFactory(), 85 directory); 86 } 87 } | Popular Tags |