KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xpath > compiler > FuncLoader


1 /*
2  * Copyright 1999-2004 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  * $Id: FuncLoader.java,v 1.10 2004/02/23 10:29:37 aruny Exp $
18  */

19 package org.apache.xpath.compiler;
20
21 import javax.xml.transform.TransformerException JavaDoc;
22
23 import org.apache.xpath.functions.Function;
24
25 /**
26  * Lazy load of functions into the function table as needed, so we don't
27  * have to load all the functions allowed in XPath and XSLT on startup.
28  * @xsl.usage advanced
29  */

30 public class FuncLoader
31 {
32
33   /** The function ID, which may correspond to one of the FUNC_XXX values
34    * found in {@link org.apache.xpath.compiler.FunctionTable}, but may
35    * be a value installed by an external module. */

36   private int m_funcID;
37
38   /** The class name of the function. Must not be null. */
39   private String JavaDoc m_funcName;
40
41   /**
42    * Get the local class name of the function class. If function name does
43    * not have a '.' in it, it is assumed to be relative to
44    * 'org.apache.xpath.functions'.
45    *
46    * @return The class name of the {org.apache.xpath.functions.Function} class.
47    */

48   public String JavaDoc getName()
49   {
50     return m_funcName;
51   }
52
53   /**
54    * Construct a function loader
55    *
56    * @param funcName The class name of the {org.apache.xpath.functions.Function}
57    * class, which, if it does not have a '.' in it, is assumed to
58    * be relative to 'org.apache.xpath.functions'.
59    * @param funcID The function ID, which may correspond to one of the FUNC_XXX
60    * values found in {@link org.apache.xpath.compiler.FunctionTable}, but may
61    * be a value installed by an external module.
62    */

63   public FuncLoader(String JavaDoc funcName, int funcID)
64   {
65
66     super();
67
68     m_funcID = funcID;
69     m_funcName = funcName;
70   }
71
72   /**
73    * Get a Function instance that this instance is liaisoning for.
74    *
75    * @return non-null reference to Function derivative.
76    *
77    * @throws javax.xml.transform.TransformerException if ClassNotFoundException,
78    * IllegalAccessException, or InstantiationException is thrown.
79    */

80   public Function getFunction() throws TransformerException JavaDoc
81   {
82     try
83     {
84       String JavaDoc className = m_funcName;
85       if (className.indexOf(".") < 0) {
86         className = "org.apache.xpath.functions." + className;
87       }
88
89       return (Function) ObjectFactory.newInstance(
90         className, ObjectFactory.findClassLoader(), true);
91     }
92     catch (ObjectFactory.ConfigurationError e)
93     {
94       throw new TransformerException JavaDoc(e.getException());
95     }
96   }
97 }
98
Popular Tags