KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sape > carbon > core > config > node > file > FileFolderFactory


1 /*
2  * The contents of this file are subject to the Sapient Public License
3  * Version 1.0 (the "License"); you may not use this file except in compliance
4  * with the License. You may obtain a copy of the License at
5  * http://carbon.sf.net/License.html.
6  *
7  * Software distributed under the License is distributed on an "AS IS" basis,
8  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
9  * the specific language governing rights and limitations under the License.
10  *
11  * The Original Code is The Carbon Component Framework.
12  *
13  * The Initial Developer of the Original Code is Sapient Corporation
14  *
15  * Copyright (C) 2003 Sapient Corporation. All Rights Reserved.
16  */

17
18 package org.sape.carbon.core.config.node.file;
19
20 import java.io.File JavaDoc;
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 /**
28  * Factory for creating folders nodes on a file system
29  *
30  * Copyright 2002 Sapient
31  * @since carbon 1.0
32  * @author Douglas Voet, April 2002
33  * @version $Revision: 1.17 $($Author: dvoet $ / $Date: 2003/05/05 21:21:19 $)
34  */

35 public class FileFolderFactory
36     implements NodeFactory {
37
38     /**
39      * Only creates sub folders of other FileFolders
40      *
41      * @param parent the parent node for the node being created
42      * @param name the name of the node being created
43      * @return a newly constructed node
44      *
45      * @throws InvalidParameterException if parent is not assignable
46      * from FileFolder
47      * @throws NodeCreationException indicates an error loading the node
48      * @see NodeFactory#getInstance
49      */

50     public Node getInstance(Node parent, String JavaDoc name)
51         throws NodeCreationException {
52
53         FileFolder parentFileFolder;
54         try {
55             parentFileFolder = (FileFolder) parent;
56         } catch (ClassCastException JavaDoc 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 JavaDoc directory =
69             new File JavaDoc(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