6
|
1 |
/*
|
|
2 |
* reserved comment block
|
|
3 |
* DO NOT REMOVE OR ALTER!
|
|
4 |
*/
|
|
5 |
/*
|
|
6 |
* Copyright 1999-2004 The Apache Software Foundation.
|
|
7 |
*
|
|
8 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9 |
* you may not use this file except in compliance with the License.
|
|
10 |
* 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, software
|
|
15 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17 |
* See the License for the specific language governing permissions and
|
|
18 |
* limitations under the License.
|
|
19 |
*/
|
|
20 |
/*
|
|
21 |
* $Id: FuncLoader.java,v 1.1.2.1 2005/08/01 01:30:35 jeffsuttor Exp $
|
|
22 |
*/
|
|
23 |
package com.sun.org.apache.xpath.internal.compiler;
|
|
24 |
|
|
25 |
import javax.xml.transform.TransformerException;
|
|
26 |
|
|
27 |
import com.sun.org.apache.xpath.internal.functions.Function;
|
12458
|
28 |
import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
|
|
29 |
import com.sun.org.apache.xalan.internal.utils.ConfigurationError;
|
6
|
30 |
|
|
31 |
/**
|
|
32 |
* Lazy load of functions into the function table as needed, so we don't
|
|
33 |
* have to load all the functions allowed in XPath and XSLT on startup.
|
|
34 |
* @xsl.usage advanced
|
|
35 |
*/
|
|
36 |
public class FuncLoader
|
|
37 |
{
|
|
38 |
|
|
39 |
/** The function ID, which may correspond to one of the FUNC_XXX values
|
|
40 |
* found in {@link com.sun.org.apache.xpath.internal.compiler.FunctionTable}, but may
|
|
41 |
* be a value installed by an external module. */
|
|
42 |
private int m_funcID;
|
|
43 |
|
|
44 |
/** The class name of the function. Must not be null. */
|
|
45 |
private String m_funcName;
|
|
46 |
|
|
47 |
/**
|
|
48 |
* Get the local class name of the function class. If function name does
|
|
49 |
* not have a '.' in it, it is assumed to be relative to
|
|
50 |
* 'com.sun.org.apache.xpath.internal.functions'.
|
|
51 |
*
|
|
52 |
* @return The class name of the {com.sun.org.apache.xpath.internal.functions.Function} class.
|
|
53 |
*/
|
|
54 |
public String getName()
|
|
55 |
{
|
|
56 |
return m_funcName;
|
|
57 |
}
|
|
58 |
|
|
59 |
/**
|
|
60 |
* Construct a function loader
|
|
61 |
*
|
|
62 |
* @param funcName The class name of the {com.sun.org.apache.xpath.internal.functions.Function}
|
|
63 |
* class, which, if it does not have a '.' in it, is assumed to
|
|
64 |
* be relative to 'com.sun.org.apache.xpath.internal.functions'.
|
|
65 |
* @param funcID The function ID, which may correspond to one of the FUNC_XXX
|
|
66 |
* values found in {@link com.sun.org.apache.xpath.internal.compiler.FunctionTable}, but may
|
|
67 |
* be a value installed by an external module.
|
|
68 |
*/
|
|
69 |
public FuncLoader(String funcName, int funcID)
|
|
70 |
{
|
|
71 |
|
|
72 |
super();
|
|
73 |
|
|
74 |
m_funcID = funcID;
|
|
75 |
m_funcName = funcName;
|
|
76 |
}
|
|
77 |
|
|
78 |
/**
|
|
79 |
* Get a Function instance that this instance is liaisoning for.
|
|
80 |
*
|
|
81 |
* @return non-null reference to Function derivative.
|
|
82 |
*
|
|
83 |
* @throws javax.xml.transform.TransformerException if ClassNotFoundException,
|
|
84 |
* IllegalAccessException, or InstantiationException is thrown.
|
|
85 |
*/
|
|
86 |
Function getFunction() throws TransformerException
|
|
87 |
{
|
|
88 |
try
|
|
89 |
{
|
|
90 |
String className = m_funcName;
|
|
91 |
if (className.indexOf(".") < 0) {
|
|
92 |
className = "com.sun.org.apache.xpath.internal.functions." + className;
|
|
93 |
}
|
|
94 |
//hack for loading only built-in function classes.
|
|
95 |
String subString = className.substring(0,className.lastIndexOf('.'));
|
|
96 |
if(!(subString.equals ("com.sun.org.apache.xalan.internal.templates") ||
|
|
97 |
subString.equals ("com.sun.org.apache.xpath.internal.functions"))) {
|
|
98 |
throw new TransformerException("Application can't install his own xpath function.");
|
|
99 |
}
|
|
100 |
|
12458
|
101 |
return (Function) ObjectFactory.newInstance(className, true);
|
6
|
102 |
|
|
103 |
}
|
12458
|
104 |
catch (ConfigurationError e)
|
6
|
105 |
{
|
|
106 |
throw new TransformerException(e.getException());
|
|
107 |
}
|
|
108 |
}
|
|
109 |
}
|