KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > xml > xmlc > taskdef > XmlcUtils


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site (http://www.enhydra.org/).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  * $Id: XmlcUtils.java,v 1.1 2003/05/06 18:32:39 jkjome Exp $
22  */

23 package org.enhydra.xml.xmlc.taskdef;
24
25 import java.io.File JavaDoc;
26
27
28 /**
29  * Abstract base xmlc utilities class
30  *
31  * @author Robert Leftwich
32  * @version 1.0
33  */

34 public abstract class XmlcUtils {
35
36     /**
37      * The default extension for an XMLC options file.
38      */

39     public static final String JavaDoc DEFAULT_OPTIONS_FILETYPE = ".xmlc";
40
41     /**
42      * The name of the default XMLC options file.
43      */

44     public static final String JavaDoc DEFAULT_OPTIONS_FILENAME = "options" + DEFAULT_OPTIONS_FILETYPE;
45
46     /**
47      * The system property holding the classname of the class to
48      * instantiate when XmlcUtils.create() is called.
49      */

50     public static final String JavaDoc DEFAULT_UTILS_CLASS_KEY = "xmlcutils.classname";
51
52     /**
53      * The default classname of the class to
54      * instantiate when XmlcUtils.create() is called.
55      */

56     public static final String JavaDoc DEFAULT_UTILS_CLASS_NAME = DefaultXmlcUtilsImpl.class.getName();
57
58
59     /**
60      * Construct default XmlcUtils (protected to force the use
61      * of XmlcUtils.create() factory method).
62      */

63     protected XmlcUtils() {}
64
65     //===========================================================================
66
// QUERY METHODS
67
//===========================================================================
68

69     /**
70      * Get a list of options files for the specified directory.
71      * This method will search for the default options file name
72      * (options.xmlc) in the specified directory and the user.dir
73      * directory as well. It will return them in that order.
74      *
75      * @param theDirectory
76      * The directory to look in for the options file.
77      * @return An array of options files with absolute paths.
78      * An empty array if none found.
79      */

80     public abstract String JavaDoc[] getOptionFiles(File JavaDoc theDirectory);
81
82     /**
83      * Get a list of options files for the specified directory,
84      * having the specified name. This method will search for the
85      * specified options file name and the default options file name
86      * (options.xmlc) in the specified directory and the user.dir
87      * directory as well. It will return them in that order.
88      *
89      * @param theDirectory
90      * The directory to look in for the options file.
91      * @param theOptionsFileName
92      * The name of the options file to look for.
93      * @return An array of options files with absolute paths.
94      * An empty array if none found.
95      */

96     public abstract String JavaDoc[] getOptionFiles(File JavaDoc theDirectory, String JavaDoc theOptionsFileName);
97
98     /**
99      * Get a list of options files for the specified directory,
100      * having the specified names. This method will search for the
101      * specified options file names and the default options file name
102      * (options.xmlc) in the specified directory and the user.dir
103      * directory as well. It will return them in that order.
104      *
105      * @param theDirectory
106      * The directory to look in for the options file.
107      * @param theOptionsFileNames
108      * The list of names of the options file to look for.
109      * @return An array of options files with absolute paths.
110      * An empty array if none found.
111      */

112     public abstract String JavaDoc[] getOptionFiles(File JavaDoc theDirectory, String JavaDoc[] theOptionsFileNames);
113
114     /**
115      * Get a list of options files for the specified directories,
116      * having the specified name. This method will search for the
117      * specified options file name and the default options file name
118      * (options.xmlc) in the specified directories and the user.dir
119      * directory as well. It will return them in that order.
120      *
121      * @param theDirectories
122      * The list of directories to look in for the options files.
123      * @param theOptionsFileName
124      * The name of the options file to look for.
125      * @return An array of options files with absolute paths.
126      * An empty array if none found.
127      */

128     public abstract String JavaDoc[] getOptionFiles(File JavaDoc[] theDirectories, String JavaDoc theOptionsFileName);
129
130     /**
131      * Get a list of options files for the specified directories,
132      * having the specified names. This method will search for the
133      * specified options file names and the default options file name
134      * (options.xmlc) in the specified directories and the user.dir
135      * directory as well. It will return them in that order.
136      *
137      * @param theDirectories
138      * The list of directories to look in for the options files.
139      * @param theOptionsFileNames
140      * The list of names of the options file to look for.
141      * @return An array of options files with absolute paths.
142      * An empty array if none found.
143      */

144     public abstract String JavaDoc[] getOptionFiles(File JavaDoc[] theDirectories, String JavaDoc[] theOptionsFileNames);
145
146     /**
147      * Build a full base file name (i.e. with no file type) out of
148      * the specified components.
149      *
150      * Note that any directory prefix on the theBaseFileName file is stripped before
151      * thePackageDir is applied. So that the following call :
152      *
153      * buildFullBaseFileName("a.b.c", "foo/resources", "config/test.html");
154      *
155      * will return a string of "a/b/c/foo/resources/test"
156      *
157      * and this call :
158      *
159      * buildFullBaseFileName("a.b.c", "", "config/test.html");
160      *
161      * will return a string of "a/b/c/config/test"
162      *
163      * @param thePackageName
164      * The name of the package to prepend to the file name.
165      * This should be specified using the Java naming convention
166      * i.e. org.enhydra.xmlc
167      * @param thePackageDir
168      * The name of the directory to prepend to the file name.
169      * This is a directory path that can be specified using either '/' or '\'
170      * i.e. foo/resources
171      * @param theBaseFileName
172      * The base file name that the preceding strings are prepended to.
173      * @return A string representing the full path resulting from the specified components
174      * with all separators set to '/'
175      */

176     public abstract String JavaDoc buildFullBaseFileName(String JavaDoc thePackageName,
177                                                   String JavaDoc thePackageDir,
178                                                   String JavaDoc theBaseFileName);
179
180     /**
181      * Build a Java class name out of the specified components.
182      *
183      * @param theFullBaseFileName
184      * The full base file name (specified with '/' separators)
185      * and no file type. e.g. "org.enhydra.test"
186      * @param theModifier
187      * The file modifier to append to the class name
188      * e.g. HTML
189      * @return A Java class name string
190      */

191     public abstract String JavaDoc buildClassName(String JavaDoc theFullBaseFileName,
192                                          String JavaDoc theModifier);
193
194     /**
195      * Factory method for creating instances of the XmlcUtils class.
196      * The actual implementation instantiated is controlled by
197      * setting the system property DEFAULT_UTILS_CLASSKEY
198      * (currently 'xmlcutils.classname') to the fully qualified
199      * class name of the sub-class of XmlcUtils that you want to use.
200      * By default (or if the value specified is invalid) this
201      * method will return an instance of DefaultXmlcUtilsImpl
202      *
203      * @return An instance of a XmlcUtils class
204      */

205     public static XmlcUtils create() {
206         XmlcUtils retVal = null;
207         String JavaDoc defaultUtilsClassName = System.getProperty(DEFAULT_UTILS_CLASS_KEY, DEFAULT_UTILS_CLASS_NAME);
208         try {
209             Class JavaDoc classObj = Class.forName(defaultUtilsClassName, true, XmlcUtils.class.getClassLoader());
210             if (XmlcUtils.class.isAssignableFrom(classObj)) {
211                 retVal = (XmlcUtils)classObj.newInstance();
212             } else {
213                 //theirLogger.warn("A \"" + defaultUtilsClassName +
214
// "\" object is not an instance of a \"" +
215
// XmlcUtils.class.getName() + "\" object.");
216
System.out.println ("WARNING: A \"" + defaultUtilsClassName +
217                     "\" object is not an instance of a \""+
218                     XmlcUtils.class.getName() + "\" object.");
219             }
220         } catch (Exception JavaDoc e) {
221             //theirLogger.warn("Could not instantiate class [" + defaultUtilsClassName + "].", e);
222
System.out.println("WARNING: Could not instantiate class [" + defaultUtilsClassName + "]."+e);
223         }
224         if (null == retVal) retVal = new DefaultXmlcUtilsImpl();
225         return retVal;
226     }
227
228 }
229
Popular Tags