KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sape > carbon > services > config > jar > AbstractJarConfigurationDocumentFactory


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.jar;
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>JarConfigurationDocument</code>s.
30  *
31  * Copyright 2002 Sapient
32  * @since carbon 1.0
33  * @author Douglas Voet, March 2002
34  * @version $Revision: 1.3 $($Author: dvoet $ / $Date: 2003/05/05 21:21:09 $)
35  */

36 public abstract class AbstractJarConfigurationDocumentFactory
37     implements NodeFactory {
38
39     /**
40      * holds a reference to the format service.
41      */

42     private static final ConfigurationFormatService FORMAT_SERVICE =
43         new DefaultConfigurationFormatService();
44
45     /**
46      * Creates FileConfigurationDocument objects only as children
47      * of FileFolders.
48      *
49      * @param parent the parent of the node
50      * @param name the name of the node
51      * @return the newly created node
52      * @throws InvalidParameterException if parent is not
53      * assignable from FileFolder
54      * @throws NodeCreationException indicates an error creating the node
55      * @see NodeFactory#getInstance
56      */

57     public Node getInstance(Node parent, String JavaDoc name)
58         throws NodeCreationException {
59
60         JarFolder parentJarFolder;
61         try {
62             parentJarFolder = (JarFolder) parent;
63         } catch (ClassCastException JavaDoc cce) {
64             throw new InvalidParameterException(
65                 this.getClass(),
66                 "parent is not assignable from JarFolder", cce);
67         }
68
69         // need to explicitly check for null, otherwise the following
70
// code will create a null.xml file
71
if (name == null) {
72             throw new InvalidParameterException(
73                 this.getClass(),
74                 "name cannot be null");
75         }
76
77         String JavaDoc entryName =
78             parentJarFolder.getInternalJarEntryName()
79                 + name + getFileExtension();
80
81         return new JarConfigurationDocument(
82             parent,
83             name,
84             getConfigurationFormatService(),
85             parentJarFolder.getReadWriteLock(),
86             parentJarFolder.getInternalJarFile(),
87             entryName);
88     }
89
90     /**
91      * Gets the file extension for the node being created by the factory.
92      * The extension is used to identify the type of node contained
93      * within the document (ConfigurationDocument or LinkNode at this time).
94      *
95      * @return String the file extension starting with a '.'
96      */

97     protected abstract String JavaDoc getFileExtension();
98
99     /**
100      * Method that determines which ConfigurationFormatService will be used
101      * within the ConfigurationDocuments of the file package. The default
102      * implementation returns a static instance of
103      * org.sape.carbon.core.config.format.DefaultConfigurationFormatService.
104      * Override this method to
105      * change the ConfigurationFormatService used by the
106      * FileConfigurationDocument.
107      *
108      * @return ConfigurationFormatService
109      */

110     protected ConfigurationFormatService getConfigurationFormatService() {
111         return AbstractJarConfigurationDocumentFactory.FORMAT_SERVICE;
112     }
113 }
Popular Tags