KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > velocity > tools > generic > ToolLoader


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

16
17 package org.apache.velocity.tools.generic;
18
19 /**
20  * <p>A view tool that allows template designers to load
21  * an arbitrary object into the context. Any object
22  * with a public constructor without parameters can be used
23  * as a view tool.</p>
24  *
25  * <p>THIS CLASS IS HERE AS A PROOF OF CONCEPT ONLY. IT IS NOT
26  * INTENDED FOR USE IN PRODUCTION ENVIRONMENTS. USE AT YOUR OWN RISK.</p>
27  *
28  * @author <a HREF="mailto:sidler@teamup.com">Gabe Sidler</a>
29  * @author <a HREF="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
30  *
31  * @version $Id: ToolLoader.java,v 1.4 2004/02/18 20:11:07 nbubna Exp $
32  * @deprecated This class will be removed after VelocityTools 1.1
33  */

34
35 public class ToolLoader
36 {
37
38     public ToolLoader()
39     {
40     }
41
42     /**
43      * Creates and returns an object of the specified classname.
44      * The object must have a valid default constructor.
45      *
46      * @param clazz the fully qualified class name of the object
47      * @return an instance of the specified class or null if the class
48      * could not be instantiated.
49      */

50     public Object JavaDoc load(String JavaDoc clazz)
51     {
52         try
53         {
54             return Class.forName(clazz).newInstance();
55         }
56         catch (Exception JavaDoc e)
57         {
58             return null;
59         }
60     }
61
62 }
63
Popular Tags