org.apache.xalan.extensions
Class MethodResolver

java.lang.Object
  extended byorg.apache.xalan.extensions.MethodResolver

public class MethodResolver
extends Object

Utility class to help resolve method overloading with Xalan XSLT argument types.


Nested Class Summary
(package private) static class MethodResolver.ConversionInfo
          Simple class to hold information about allowed conversions and their relative scores, for use by the table below.
 
Field Summary
static int DYNAMIC
          Specifies a Dynamic method search.
static int INSTANCE_ONLY
          Specifies a search for instance methods only.
(package private) static MethodResolver.ConversionInfo[] m_booleanConversions
          Specification of conversions from XSLT type CLASS_BOOLEAN to allowed Java types.
(package private) static MethodResolver.ConversionInfo[][] m_conversions
          Order is significant in the list below, based on XObject.CLASS_XXX values.
(package private) static MethodResolver.ConversionInfo[] m_javaObjConversions
          Specification of conversions from XSLT type CLASS_UNKNOWN (i.e. some unknown Java object) to allowed Java types.
(package private) static MethodResolver.ConversionInfo[] m_nodesetConversions
          Specification of conversions from XSLT type CLASS_NODESET to allowed Java types.
(package private) static MethodResolver.ConversionInfo[] m_numberConversions
          Specification of conversions from XSLT type CLASS_NUMBER to allowed Java types.
(package private) static MethodResolver.ConversionInfo[] m_rtfConversions
          Specification of conversions from XSLT type CLASS_RTREEFRAG to allowed Java types.
(package private) static MethodResolver.ConversionInfo[] m_stringConversions
          Specification of conversions from XSLT type CLASS_STRING to allowed Java types.
private static int SCOREBASE
           
static int STATIC_AND_INSTANCE
          Specifies a search for both static and instance methods.
static int STATIC_ONLY
          Specifies a search for static methods only.
 
Constructor Summary
MethodResolver()
           
 
Method Summary
(package private) static Object convert(Object xsltObj, Class javaClass)
          Convert the given XSLT object to an object of the given class.
(package private) static Object convertDoubleToNumber(double num, Class javaClass)
          Do a standard conversion of a double to the specified type.
static void convertParams(Object[] argsIn, Object[][] argsOut, Class[] paramTypes, ExpressionContext exprContext)
          Convert a set of parameters based on a set of paramTypes.
private static String errArgs(Object[] xsltArgs, int startingArg)
           
private static String errString(String callType, String searchType, Class classObj, String funcName, int searchMethod, Object[] xsltArgs)
          Format the message for the NoSuchMethodException containing all the information about the method we're looking for.
static Constructor getConstructor(Class classObj, Object[] argsIn, Object[][] argsOut, ExpressionContext exprContext)
          Given a class, figure out the resolution of the Java Constructor from the XSLT argument types, and perform the conversion of the arguments.
static Method getElementMethod(Class classObj, String name)
          Given the name of a method, figure out the resolution of the Java Method
static Method getMethod(Class classObj, String name, Object[] argsIn, Object[][] argsOut, ExpressionContext exprContext, int searchMethod)
          Given the name of a method, figure out the resolution of the Java Method from the XSLT argument types, and perform the conversion of the arguments.
private static String replaceDash(String name)
          To support EXSLT extensions, convert names with dash to allowable Java names: e.g., convert abc-xyz to abcXyz.
static int scoreMatch(Class[] javaParamTypes, int javaParamsStart, Object[] xsltArgs, int score)
          Score the conversion of a set of XSLT arguments to a given set of Java parameters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATIC_ONLY

public static final int STATIC_ONLY
Specifies a search for static methods only.

See Also:
Constant Field Values

INSTANCE_ONLY

public static final int INSTANCE_ONLY
Specifies a search for instance methods only.

See Also:
Constant Field Values

STATIC_AND_INSTANCE

public static final int STATIC_AND_INSTANCE
Specifies a search for both static and instance methods.

See Also:
Constant Field Values

DYNAMIC

public static final int DYNAMIC
Specifies a Dynamic method search. If the method being evaluated is a static method, all arguments are used. Otherwise, it is an instance method and only arguments beginning with the second argument are used.

See Also:
Constant Field Values

SCOREBASE

private static final int SCOREBASE
See Also:
Constant Field Values

m_javaObjConversions

static MethodResolver.ConversionInfo[] m_javaObjConversions
Specification of conversions from XSLT type CLASS_UNKNOWN (i.e. some unknown Java object) to allowed Java types.


m_booleanConversions

static MethodResolver.ConversionInfo[] m_booleanConversions
Specification of conversions from XSLT type CLASS_BOOLEAN to allowed Java types.


m_numberConversions

static MethodResolver.ConversionInfo[] m_numberConversions
Specification of conversions from XSLT type CLASS_NUMBER to allowed Java types.


m_stringConversions

static MethodResolver.ConversionInfo[] m_stringConversions
Specification of conversions from XSLT type CLASS_STRING to allowed Java types.


m_rtfConversions

static MethodResolver.ConversionInfo[] m_rtfConversions
Specification of conversions from XSLT type CLASS_RTREEFRAG to allowed Java types.


m_nodesetConversions

static MethodResolver.ConversionInfo[] m_nodesetConversions
Specification of conversions from XSLT type CLASS_NODESET to allowed Java types. (This is the same as for CLASS_RTREEFRAG)


m_conversions

static MethodResolver.ConversionInfo[][] m_conversions
Order is significant in the list below, based on XObject.CLASS_XXX values.

Constructor Detail

MethodResolver

public MethodResolver()
Method Detail

getConstructor

public static Constructor getConstructor(Class classObj,
                                         Object[] argsIn,
                                         Object[][] argsOut,
                                         ExpressionContext exprContext)
                                  throws NoSuchMethodException,
                                         SecurityException,
                                         javax.xml.transform.TransformerException
Given a class, figure out the resolution of the Java Constructor from the XSLT argument types, and perform the conversion of the arguments.

Parameters:
classObj - the Class of the object to be constructed.
argsIn - An array of XSLT/XPath arguments.
argsOut - An array of the exact size as argsIn, which will be populated with converted arguments if a suitable method is found.
Returns:
A constructor that will work with the argsOut array.
Throws:
javax.xml.transform.TransformerException - may be thrown for Xalan conversion exceptions.
NoSuchMethodException
SecurityException

getMethod

public static Method getMethod(Class classObj,
                               String name,
                               Object[] argsIn,
                               Object[][] argsOut,
                               ExpressionContext exprContext,
                               int searchMethod)
                        throws NoSuchMethodException,
                               SecurityException,
                               javax.xml.transform.TransformerException
Given the name of a method, figure out the resolution of the Java Method from the XSLT argument types, and perform the conversion of the arguments.

Parameters:
classObj - The Class of the object that should have the method.
name - The name of the method to be invoked.
argsIn - An array of XSLT/XPath arguments.
argsOut - An array of the exact size as argsIn, which will be populated with converted arguments if a suitable method is found.
Returns:
A method that will work with the argsOut array.
Throws:
javax.xml.transform.TransformerException - may be thrown for Xalan conversion exceptions.
NoSuchMethodException
SecurityException

replaceDash

private static String replaceDash(String name)
To support EXSLT extensions, convert names with dash to allowable Java names: e.g., convert abc-xyz to abcXyz. Note: dashes only appear in middle of an EXSLT function or element name.


getElementMethod

public static Method getElementMethod(Class classObj,
                                      String name)
                               throws NoSuchMethodException,
                                      SecurityException,
                                      javax.xml.transform.TransformerException
Given the name of a method, figure out the resolution of the Java Method

Parameters:
classObj - The Class of the object that should have the method.
name - The name of the method to be invoked.
Returns:
A method that will work to be called as an element.
Throws:
javax.xml.transform.TransformerException - may be thrown for Xalan conversion exceptions.
NoSuchMethodException
SecurityException

convertParams

public static void convertParams(Object[] argsIn,
                                 Object[][] argsOut,
                                 Class[] paramTypes,
                                 ExpressionContext exprContext)
                          throws javax.xml.transform.TransformerException
Convert a set of parameters based on a set of paramTypes.

Parameters:
argsIn - An array of XSLT/XPath arguments.
argsOut - An array of the exact size as argsIn, which will be populated with converted arguments.
paramTypes - An array of class objects, of the exact same size as argsIn and argsOut.
Throws:
javax.xml.transform.TransformerException - may be thrown for Xalan conversion exceptions.

scoreMatch

public static int scoreMatch(Class[] javaParamTypes,
                             int javaParamsStart,
                             Object[] xsltArgs,
                             int score)
Score the conversion of a set of XSLT arguments to a given set of Java parameters. If any invocations of this function for a method with the same name return the same positive value, then a conflict has occured, and an error should be signaled.

Parameters:
javaParamTypes - Must be filled with valid class names, and of the same length as xsltArgs.
xsltArgs - Must be filled with valid object instances, and of the same length as javeParamTypes.
Returns:
-1 for no allowed conversion, or a positive score that is closer to zero for more preferred, or further from zero for less preferred.

convert

static Object convert(Object xsltObj,
                      Class javaClass)
               throws javax.xml.transform.TransformerException
Convert the given XSLT object to an object of the given class.

Parameters:
xsltObj - The XSLT object that needs conversion.
javaClass - The type of object to convert to.
Throws:
javax.xml.transform.TransformerException - may be thrown for Xalan conversion exceptions.

convertDoubleToNumber

static Object convertDoubleToNumber(double num,
                                    Class javaClass)
Do a standard conversion of a double to the specified type.

Parameters:
num - The number to be converted.
javaClass - The class type to be converted to.
Returns:
An object specified by javaClass, or a Double instance.

errString

private static String errString(String callType,
                                String searchType,
                                Class classObj,
                                String funcName,
                                int searchMethod,
                                Object[] xsltArgs)
Format the message for the NoSuchMethodException containing all the information about the method we're looking for.


errArgs

private static String errArgs(Object[] xsltArgs,
                              int startingArg)