01: package org.apache.velocity.runtime.resource.loader;
02:
03: /*
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
20: */
21:
22: import org.apache.velocity.runtime.RuntimeServices;
23: import org.apache.velocity.util.ClassUtils;
24: import org.apache.velocity.util.StringUtils;
25:
26: /**
27: * Factory to grab a template loader.
28: *
29: * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
30: * @version $Id: ResourceLoaderFactory.java 463298 2006-10-12 16:10:32Z henning $
31: */
32: public class ResourceLoaderFactory {
33: /**
34: * Gets the loader specified in the configuration file.
35: * @param rs
36: * @param loaderClassName
37: * @return TemplateLoader
38: * @throws Exception
39: */
40: public static ResourceLoader getLoader(RuntimeServices rs,
41: String loaderClassName) throws Exception {
42: ResourceLoader loader = null;
43:
44: try {
45: loader = (ResourceLoader) ClassUtils
46: .getNewInstance(loaderClassName);
47:
48: rs.getLog().debug(
49: "ResourceLoader instantiated: "
50: + loader.getClass().getName());
51:
52: return loader;
53: }
54: // The ugly three strike again: ClassNotFoundException,IllegalAccessException,InstantiationException
55: catch (Exception e) {
56: rs
57: .getLog()
58: .error(
59: "Problem instantiating the template loader.\n"
60: + "Look at your properties file and make sure the\n"
61: + "name of the template loader is correct. Here is the\n"
62: + "error:", e);
63:
64: throw new Exception(
65: "Problem initializing template loader: "
66: + loaderClassName + "\nError is: "
67: + StringUtils.stackTrace(e));
68: }
69: }
70: }
|