com.novell.xsl.extensions
Class ECMAScriptFunctionImpl

java.lang.Object
  extended bycom.novell.xml.xpath.Function
      extended bycom.novell.xsl.extensions.ECMAScriptFunction
          extended bycom.novell.xsl.extensions.ECMAScriptFunctionImpl

public class ECMAScriptFunctionImpl
extends ECMAScriptFunction

This class represents a java class member with a particular name. This class is only used during the parsing stage. The getInstance() member returns the actual JavaMethodInstance object that is used by the FunctionCall object.


Field Summary
protected  ClassLoader classLoader
           
static String ECMASCRIPT_EXTENSION_FUNCTION_NAMESPACE
          The start of the URI used to signify extension functions and non-built in extension elements: "http://www.novell.com/nxsl/ecmascript"
static String ECMASCRIPT_SCOPE_PROPERTY
          The name of the property in the ExpressionContext that holds the ECMAScript execution environment
protected static Class nativeReturnType
           
protected static Class undefinedReturnType
           
 
Fields inherited from class com.novell.xsl.extensions.ECMAScriptFunction
defaultParameterType, defaultReturnType, optArgs, scriptAttr
 
Constructor Summary
ECMAScriptFunctionImpl(ExpandedQName name, ClassLoader classLoader)
          Construct a placeholder for the function library for the desired java class member(s).
 
Method Summary
 boolean available(ExpressionContext eContext)
          Checks whether or not the function that this object represents actual has an implementation
static com.novell.soa.script.mozilla.javascript.Scriptable createScope(com.novell.soa.script.mozilla.javascript.Context jsContext)
          Create a rhino scope to work with
static ExpressionValue ECMAScriptToExpressionValue(Object value)
          Convert a value returned from ECMAScript to an ExpressionValue to return back to XPATH
static Object evaluate(ExpressionContext eContext, String script, String uri, int line, ClassLoader classLoader)
          Evaluate a string as ECMAScript
static Object evaluate(ExpressionContext eContext, URL externalScript, String encoding, ClassLoader classLoader)
          Evaluate a resource defined by a URI as ECMAScript
static Object evaluateCommandLineScripts(List scripts, ClassLoader classLoader)
          Evaluate scripts passed in on the command line
static Object expressionValueToECMAScript(ExpressionValue expressionValue, com.novell.soa.script.mozilla.javascript.Scriptable scope)
          Wrap or convert an ExpressionValue for use in ECMAScript
static com.novell.soa.script.mozilla.javascript.Scriptable getScope(ExpressionContext eContext, com.novell.soa.script.mozilla.javascript.Context jsContext)
          Get (or create) a scope to work with from the ExpressionContext
 ExpressionValue invoke(Object[] args)
          Invoke the function using the passed list of arguments.
static void parse(StylesheetParser stylesheetParser, Element element, URL baseURI, ClassLoader classLoader)
          Parses the specified ecmascript:script element and returns the result as a ECMAScriptParser object.
 
Methods inherited from class com.novell.xsl.extensions.ECMAScriptFunction
create, isECMAScriptAvailable
 
Methods inherited from class com.novell.xml.xpath.Function
getInstance, getSignature, isConstant, registerForReset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ECMASCRIPT_EXTENSION_FUNCTION_NAMESPACE

public static final String ECMASCRIPT_EXTENSION_FUNCTION_NAMESPACE
The start of the URI used to signify extension functions and non-built in extension elements: "http://www.novell.com/nxsl/ecmascript"

See Also:
Constant Field Values

ECMASCRIPT_SCOPE_PROPERTY

public static final String ECMASCRIPT_SCOPE_PROPERTY
The name of the property in the ExpressionContext that holds the ECMAScript execution environment

See Also:
Constant Field Values

undefinedReturnType

protected static final Class undefinedReturnType

nativeReturnType

protected static final Class nativeReturnType

classLoader

protected ClassLoader classLoader
Constructor Detail

ECMAScriptFunctionImpl

public ECMAScriptFunctionImpl(ExpandedQName name,
                              ClassLoader classLoader)
Construct a placeholder for the function library for the desired java class member(s).

Parameters:
name - The name of the function
classLoader - class loader to use (null for default)
Method Detail

invoke

public ExpressionValue invoke(Object[] args)
                       throws XPathEvaluationException
Invoke the function using the passed list of arguments.

Overrides:
invoke in class ECMAScriptFunction
Parameters:
args - List of arguments.
Returns:
An object containing the result of the function invocation.
Throws:
XPathEvaluationException

available

public boolean available(ExpressionContext eContext)
Checks whether or not the function that this object represents actual has an implementation

Overrides:
available in class ECMAScriptFunction
Parameters:
eContext - the ExpressionContext to get the scope from or put the new scope into
Returns:
true if the function has an implementation

expressionValueToECMAScript

public static Object expressionValueToECMAScript(ExpressionValue expressionValue,
                                                 com.novell.soa.script.mozilla.javascript.Scriptable scope)
                                          throws XPathConversionException
Wrap or convert an ExpressionValue for use in ECMAScript

Parameters:
expressionValue - The value passed in from XPATH as an argument
Returns:
the value converted or wrapped for use in ECMAScript
Throws:
XPathConversionException

ECMAScriptToExpressionValue

public static ExpressionValue ECMAScriptToExpressionValue(Object value)
Convert a value returned from ECMAScript to an ExpressionValue to return back to XPATH

Parameters:
value - The value returned from ECMAScript
Returns:
the ExpressionValue version of the value

parse

public static void parse(StylesheetParser stylesheetParser,
                         Element element,
                         URL baseURI,
                         ClassLoader classLoader)
                  throws XSLTParserException
Parses the specified ecmascript:script element and returns the result as a ECMAScriptParser object.

Parameters:
stylesheetParser - The StylesheetParser for which the element is to be parsed.
element - the element to be parsed
classLoader - class loader to use (null for default)
Throws:
XSLTParserException - if a fatal error occurs during parsing

createScope

public static com.novell.soa.script.mozilla.javascript.Scriptable createScope(com.novell.soa.script.mozilla.javascript.Context jsContext)
Create a rhino scope to work with

Parameters:
jsContext - Rhino Context to use to create the scope
Returns:
the scope

getScope

public static com.novell.soa.script.mozilla.javascript.Scriptable getScope(ExpressionContext eContext,
                                                                           com.novell.soa.script.mozilla.javascript.Context jsContext)
Get (or create) a scope to work with from the ExpressionContext

Parameters:
eContext - the ExpressionContext to get the scope from or put the new scope into
jsContext - the Rhino context to use to create the scope
Returns:
the scope

evaluate

public static Object evaluate(ExpressionContext eContext,
                              String script,
                              String uri,
                              int line,
                              ClassLoader classLoader)
Evaluate a string as ECMAScript

Parameters:
eContext - the ExpressionContext to get the scope from or put the new scope into
script - The script
uri - The URI of the script
line - The line number within the URI where the script started
classLoader - class loader to use (null for default)
Returns:
The result of evaluating the script

evaluate

public static Object evaluate(ExpressionContext eContext,
                              URL externalScript,
                              String encoding,
                              ClassLoader classLoader)
                       throws IOException
Evaluate a resource defined by a URI as ECMAScript

Parameters:
eContext - the ExpressionContext to get the scope from or put the new scope into
externalScript - URI of the external script
encoding - the character encoding of the external script or null to use the default encoding
classLoader - class loader to use (null for default)
Returns:
The result of evaluating the script
Throws:
IOException

evaluateCommandLineScripts

public static Object evaluateCommandLineScripts(List scripts,
                                                ClassLoader classLoader)
                                         throws XSLException,
                                                IOException
Evaluate scripts passed in on the command line

Parameters:
scripts - a list of Strings containing URI of scripts to evaluate
classLoader - class loader to use (null for default)
Returns:
A scope object containing the objects created by the script
Throws:
XSLException
IOException