/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: FunctionCall.java,v 1.2.4.1 2005/09/12 10:31:32 pvedula Exp $
*/
/**
* @author Jacek Ambroziak
* @author Santiago Pericas-Geertsen
* @author Morten Jorgensen
* @author Erwin Bolwidt <ejb@klomp.org>
* @author Todd Miller
*/
// Name of this function call
// Arguments to this function call (might not be any)
// Empty argument list, used for certain functions
// Valid namespaces for Java function-call extension
EXT_XSLTC + "/java";
// Namespace format constants
// Namespace format
/**
* Stores reference to object for non-static Java calls
*/
// Encapsulates all unsupported external function calls
private boolean unresolvedExternal;
// If FunctionCall is a external java constructor
private boolean _isExtConstructor = false;
// If the java method is static
private boolean _isStatic = false;
// Legal conversions between internal and Java types.
// Legal conversions between Java and internal types.
// The mappings between EXSLT extension namespaces and implementation classes
// Extension functions that are implemented in BasisLibrary
/**
* inner class to used in internal2Java mappings, contains
* the Java type and the distance between the internal type and
* the Java type.
*/
static class JavaType {
public int distance;
}
public int hashCode() {
}
}
}
/**
* Defines 2 conversion tables:
* 1. From internal types to Java types and
* 2. From Java types to internal types.
* These two tables are used when calling external (Java) functions.
*/
static {
try {
// -- Internal to Java --------------------------------------------
// Type.Boolean -> { boolean(0), Boolean(1), Object(2) }
// Type.Real -> { double(0), Double(1), float(2), long(3), int(4),
// short(5), byte(6), char(7), Object(8) }
// Type.Int must be the same as Type.Real
// Type.String -> { String(0), Object(1) }
// Type.NodeSet -> { NodeList(0), Node(1), Object(2), String(3) }
// Type.Node -> { Node(0), NodeList(1), Object(2), String(3) }
// Type.ResultTree -> { NodeList(0), Node(1), Object(2), String(3) }
// Possible conversions between Java and internal types
// Conversions from org.w3c.dom.Node/NodeList to internal NodeSet
// Initialize the extension namespace table
_extensionNamespaceTable.put(EXSLT_DATETIME, "com.sun.org.apache.xalan.internal.lib.ExsltDatetime");
// Initialize the extension function table
}
catch (ClassNotFoundException e) {
}
}
}
this(fname, EMPTY_ARG_LIST);
}
}
if (_arguments != null) {
final int n = _arguments.size();
for (int i = 0; i < n; i++) {
}
}
}
{
return className;
else {
}
}
}
else {
}
}
}
/**
* Type check a function call. Since different type conversions apply,
* type checking is different for standard and external (Java) functions.
*/
throws TypeCheckError
{
if (isExtension()) {
return typeCheckStandard(stable);
}
else if (isStandard()) {
return typeCheckStandard(stable);
}
// Handle extension functions (they all have a namespace)
else {
try {
if (pos > 0) {
_isStatic = true;
}
else {
}
}
else {
try {
}
catch (ClassNotFoundException e) {
}
}
else
}
if (extFunction != null) {
return typeCheckStandard(stable);
}
else
}
return typeCheckExternal(stable);
}
catch (TypeCheckError e) {
}
}
}
}
/**
* Type check a call to a standard function. Insert CastExprs when needed.
* If as a result of the insertion of a CastExpr a type check error is
* thrown, then catch it and re-throw it with a new "this".
*/
final int n = _arguments.size();
final MethodType ptype =
for (int i = 0; i < n; i++) {
try {
}
catch (TypeCheckError e) {
throw new TypeCheckError(this); // invalid conversion
}
}
}
}
throw new TypeCheckError(this);
}
if (constructors == null) {
// Constructor not found in this class
}
// Try all constructors
for (int j, i = 0; i < nConstructors; i++) {
// Check if all parameters to this constructor can be converted
final Constructor constructor =
int currConstrDistance = 0;
for (j = 0; j < nArgs; j++) {
// Convert from internal (translet) type to external (Java) type
extType = paramTypes[j];
}
else if (intType instanceof ObjectType) {
continue;
currConstrDistance += 1;
else {
break;
}
}
else {
// no mapping available
break;
}
}
_isExtConstructor = true;
}
}
return _type;
}
}
/**
* Type check a call to an external (Java) method.
* The method must be static an public, and a legal type conversion
* must exist for all its arguments and its return type.
* Every method of name <code>_fname</code> is inspected
* as a possible candidate.
*/
// check if function is a contructor 'new'
return typeCheckConstructor(stable);
}
// check if we are calling an instance method
else {
boolean hasThisArgument = false;
if (nArgs == 0)
_isStatic = true;
if (!_isStatic) {
hasThisArgument = true;
&& firstArgType instanceof ObjectType
hasThisArgument = true;
if (hasThisArgument) {
if (firstArgType instanceof ObjectType) {
}
else
}
}
/*
* Warn user if external function could not be resolved.
* Warning will _NOT_ be issued is the call is properly
* wrapped in an <xsl:if> or <xsl:when> element. For details
* see If.parserContents() and When.parserContents()
*/
}
unresolvedExternal = true;
}
}
// Method not found in this class
}
// Try all methods to identify the best fit
for (int j, i = 0; i < nMethods; i++) {
// Check if all paramteters to this method can be converted
int currMethodDistance = 0;
for (j = 0; j < nArgs; j++) {
// Convert from internal (translet) type to external (Java) type
extType = paramTypes[j];
}
else {
// no mapping available
//
// Allow a Reference type to match any external (Java) type at
// the moment. The real type checking is performed at runtime.
if (intType instanceof ReferenceType) {
currMethodDistance += 1;
}
else if (intType instanceof ObjectType) {
currMethodDistance += 0;
currMethodDistance += 1;
else {
break;
}
}
else {
break;
}
}
}
if (j == nArgs) {
// Check if the return type can be converted
}
// Use this method if all parameters & return type match
}
}
}
// It is an error if the chosen method is an instance menthod but we don't
// have a this argument.
}
getXSLTC().setMultiDocument(true);
}
return _type;
}
}
/**
* Type check the actual arguments of this function call.
*/
while (e.hasMoreElements()) {
}
return result;
}
}
return argument(0);
}
protected final int argumentCount() {
return _arguments.size();
}
}
/**
* Compile the function call and treat as an expression
* Update true/false-lists.
*/
{
if (_chosenMethodType != null)
}
}
/**
* Translate a function call. The compiled code will leave the function's
* return value on the JVM's stack.
*/
final int n = argumentCount();
int index;
// Translate calls to methods in the BasisLibrary
if (isStandard() || isExtension()) {
for (int i = 0; i < n; i++) {
}
// append "F" to the function's name
// Special precautions for some method calls
args = DOM_INTF_SIG;
}
}
}
// Invoke the method in the basis library
}
// Add call to BasisLibrary.unresolved_externalF() to generate
// run-time error message for unsupported external functions
else if (unresolvedExternal) {
"unresolved_externalF",
}
else if (_isExtConstructor) {
if (isSecureProcessing)
// Backwards branches are prohibited if an uninitialized object is
// on the stack by section 4.9.4 of the JVM Specification, 2nd Ed.
// We don't know whether this code might contain backwards branches
// so we mustn't create the new object until after we've created
// the suspect arguments to its constructor. Instead we calculate
// the values of the arguments to the constructor first, store them
// in temporary variables, create the object and reload the
// arguments from the temporaries to avoid the problem.
for (int i = 0; i < n; i++) {
// Convert the argument to its Java type
paramTemp[i] =
}
for (int i = 0; i < n; i++) {
}
}
"<init>",
// Convert the return type back to our internal type
}
// Invoke function calls that are handled in separate classes
else {
if (isSecureProcessing)
// Push "this" if it is an instance method
if (_thisArgument != null) {
}
for (int i = 0; i < n; i++) {
// Convert the argument to its Java type
}
}
}
else {
}
// Convert the return type back to our internal type
}
}
}
public boolean isStandard() {
}
public boolean isExtension() {
}
/**
* Returns a vector with all methods named <code>_fname</code>
* after stripping its namespace or <code>null</code>
* if no such methods exist.
*/
try {
}
}
// Is it public and same number of args ?
{
}
}
}
}
catch (ClassNotFoundException e) {
}
}
return result;
}
/**
* Returns a vector with all constructors named <code>_fname</code>
* after stripping its namespace or <code>null</code>
* if no such methods exist.
*/
try {
}
}
// Is it public, static and same number of args ?
{
}
}
}
}
catch (ClassNotFoundException e) {
}
return result;
}
/**
* Compute the JVM signature for the class.
*/
}
}
else if (clazz.isPrimitive()) {
return "I";
}
return "B";
}
return "J";
}
return "F";
}
return "D";
}
return "S";
}
return "C";
}
return "Z";
}
return "V";
}
else {
}
}
else {
}
}
/**
* Compute the JVM method descriptor for the method.
*/
}
.toString();
}
/**
* Compute the JVM constructor descriptor for the constructor.
*/
}
}
/**
* Return the signature of the current method
*/
for (int i = 0; i < nArgs; i++) {
}
}
/**
* 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.
*/
{
char dash = '-';
}
}
/**
* Translate code to call the BasisLibrary.unallowed_extensionF(String)
* method.
*/
"unallowed_extension_functionF",
}
}