KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sape > carbon > services > config > classloader > AbstractClassloaderConfigurationDocumentFactory


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.services.config.classloader;
19
20 import org.sape.carbon.core.config.format.ConfigurationFormatService;
21 import org.sape.carbon.core.config.format.DefaultConfigurationFormatService;
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  * Base class for factories that construct
29  * <code>ClassloaderConfigurationDocument</code>s.
30  *
31  * Copyright 2003 Sapient
32  * @since carbon 2.0
33  * @author Greg Hinkle, April 2003
34  * @version $Revision: 1.4 $($Author: dvoet $ / $Date: 2003/11/11 21:19:58 $)
35  */

36 public abstract class AbstractClassloaderConfigurationDocumentFactory
37     implements NodeFactory {
38
39     private static final ConfigurationFormatService FORMAT_SERVICE =
40         new DefaultConfigurationFormatService();
41
42     /**
43      * Creates ClassloaderConfigurationDocument objects only as children
44      * of ClassloaderFolders.
45      *
46      * @throws InvalidParameterException if parent is not
47      * assignable from ClassloaderFolders
48      */

49     public Node getInstance(Node parent, String JavaDoc name)
50         throws NodeCreationException {
51
52         ClassloaderFolder parentFolder;
53         try {
54             parentFolder = (ClassloaderFolder) parent;
55         } catch(ClassCastException JavaDoc cce) {
56             throw new InvalidParameterException(
57                 this.getClass(),
58                 "parent is not assignable from ClassloaderFolder", cce);
59         }
60
61         // need to explicitly check for null, otherwise the following
62
// code will create a null.xml file
63
if (name == null) {
64             throw new InvalidParameterException(
65                 this.getClass(),
66                 "name cannot be null");
67         }
68
69         String JavaDoc entryName =
70             parentFolder.getResourcePath() +
71             name + getFileExtension();
72
73         return new ClassloaderConfigurationDocument(
74             parent,
75             name,
76             getConfigurationFormatService(),
77             entryName,
78             parentFolder.getConfigSource());
79     }
80
81     /**
82      * Gets the extension for the node being created by the factory.
83      * The extension is used to identify the type of node contained
84      * within the document (ConfigurationDocument or LinkNode at this time).
85      *
86      * @return String the file extension starting with a '.'
87      */

88     protected abstract String JavaDoc getFileExtension();
89
90     /**
91      * Method that determines which ConfigurationFormatService will be used
92      * within the ConfigurationDocuments of this package. The default
93      * implementation returns a static instance of
94      * org.sape.carbon.core.config.format.DefaultConfigurationFormatService.
95      * Override this method to
96      * change the ConfigurationFormatService used by the
97      * FileConfigurationDocument.
98      *
99      * @return ConfigurationFormatService
100      */

101     protected ConfigurationFormatService getConfigurationFormatService() {
102         return AbstractClassloaderConfigurationDocumentFactory.FORMAT_SERVICE;
103     }
104 }
Popular Tags