KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > velocity > runtime > resource > loader > ResourceLoaderFactory


1 package org.apache.velocity.runtime.resource.loader;
2
3 /*
4  * Copyright 2001,2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import org.apache.velocity.runtime.RuntimeServices;
20 import org.apache.velocity.util.StringUtils;
21
22 /**
23  * Factory to grab a template loader.
24  *
25  * @author <a HREF="mailto:jvanzyl@apache.org">Jason van Zyl</a>
26  * @version $Id: ResourceLoaderFactory.java,v 1.6.8.1 2004/03/03 23:23:02 geirm Exp $
27  */

28 public class ResourceLoaderFactory
29 {
30     /**
31      * Gets the loader specified in the configuration file.
32      * @return TemplateLoader
33      */

34     public static ResourceLoader getLoader(RuntimeServices rs, String JavaDoc loaderClassName)
35      throws Exception JavaDoc
36     {
37         ResourceLoader loader = null;
38         
39         try
40         {
41             loader = ((ResourceLoader)Class.forName(loaderClassName)
42                 .newInstance());
43             
44             rs.info("Resource Loader Instantiated: " +
45                 loader.getClass().getName());
46             
47             return loader;
48         }
49         catch( Exception JavaDoc e)
50         {
51             rs.error("Problem instantiating the template loader.\n" +
52                           "Look at your properties file and make sure the\n" +
53                           "name of the template loader is correct. Here is the\n" +
54                           "error: " + StringUtils.stackTrace(e));
55             
56             throw new Exception JavaDoc("Problem initializing template loader: " + loaderClassName +
57             "\nError is: " + StringUtils.stackTrace(e));
58         }
59     }
60 }
61
Popular Tags