You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by am...@apache.org on 2002/06/25 15:31:06 UTC
cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/compiler FunctionAvailableCall.java
amiro 2002/06/25 06:31:05
Modified: java/src/org/apache/xalan/xsltc/compiler
FunctionAvailableCall.java
Log:
fix check for extension functions
Revision Changes Path
1.7 +51 -61 xml-xalan/java/src/org/apache/xalan/xsltc/compiler/FunctionAvailableCall.java
Index: FunctionAvailableCall.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/FunctionAvailableCall.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- FunctionAvailableCall.java 24 Apr 2002 17:03:15 -0000 1.6
+++ FunctionAvailableCall.java 25 Jun 2002 13:31:05 -0000 1.7
@@ -73,39 +73,34 @@
final class FunctionAvailableCall extends FunctionCall {
- private boolean _isFunctionAvailable = false;
private Expression _arg;
- private String _namespaceOfFunct =null;
- private String _nameOfFunct =null;
-
+ private String _nameOfFunct = null;
+ private String _namespaceOfFunct = null;
+ private boolean _isFunctionAvailable = false;
/**
* Constructs a FunctionAvailableCall FunctionCall. Takes the
- * function name qname, for example, 'function-available', and a list
- * of arguments where the arguments must be instances of
- * LiteralExpression. The test for availability considers
- * internal xsl functions such as 'floor' as well as external
- * Java functions, such as 'java.lang.Math.sin'. The case of
- * external functions is handled here, the case of internal
- * functions is handled in getResult.
+ * function name qname, for example, 'function-available', and
+ * a list of arguments where the arguments must be instances of
+ * LiteralExpression.
*/
public FunctionAvailableCall(QName fname, Vector arguments) {
super(fname, arguments);
_arg = (Expression)arguments.elementAt(0);
_type = null;
+
if (_arg instanceof LiteralExpr) {
- LiteralExpr arg = (LiteralExpr)_arg;
+ LiteralExpr arg = (LiteralExpr) _arg;
_namespaceOfFunct = arg.getNamespace();
_nameOfFunct = arg.getValue();
- if ((_namespaceOfFunct != null) &&
- (!_namespaceOfFunct.equals(Constants.EMPTYSTRING)))
+
+ if (_namespaceOfFunct != null &&
+ (_namespaceOfFunct.startsWith(JAVA_EXT_XSLTC) ||
+ _namespaceOfFunct.startsWith(JAVA_EXT_XALAN)))
{
- // the function is external, such as a java function
_isFunctionAvailable = hasMethods();
}
- // the case of internal function is handled in getResult.
}
- // case where _arg is not instanceof LiteralExpr can not be handled.
}
/**
@@ -113,13 +108,11 @@
* returns the type of function-available to be boolean.
*/
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
- // may be already set
- if ( _type != null ) {
+ if (_type != null) {
return _type;
}
if (_arg instanceof LiteralExpr) {
- _type = Type.Boolean;
- return Type.Boolean;
+ return _type = Type.Boolean;
}
ErrorMsg err = new ErrorMsg(ErrorMsg.NEED_LITERAL_ERR,
"function-available", this);
@@ -186,65 +179,62 @@
* the specified method is found in the specifed class.
*/
private boolean hasMethods() {
-
LiteralExpr arg = (LiteralExpr)_arg;
final String externalFunctName = getExternalFunctionName();
+
if (externalFunctName == null) {
return false;
}
+
final String className = getClassName(externalFunctName);
- if (_namespaceOfFunct.startsWith(JAVA_EXT_XSLTC) ||
- _namespaceOfFunct.startsWith(JAVA_EXT_XALAN)) {
- try {
- TransletLoader loader = new TransletLoader();
- final Class clazz = loader.loadClass(className);
-
- if (clazz == null) {
- final ErrorMsg msg =
- new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR, className);
- getParser().reportError(Constants.ERROR, msg);
- }
- else {
- final String methodName = getMethodName(externalFunctName);
- final Method[] methods = clazz.getDeclaredMethods();
-
- for (int i = 0; i < methods.length; i++) {
- final int mods = methods[i].getModifiers();
-
- if (Modifier.isPublic(mods)
- && Modifier.isStatic(mods)
- && methods[i].getName().equals(methodName))
- {
- return true;
- }
- }
- }
- }
- catch (ClassNotFoundException e) {
- final ErrorMsg msg =
- new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR, className);
- getParser().reportError(Constants.ERROR, msg);
- }
- }
+ try {
+ TransletLoader loader = new TransletLoader();
+ final Class clazz = loader.loadClass(className);
+
+ if (clazz == null) {
+ final ErrorMsg msg =
+ new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR, className);
+ getParser().reportError(Constants.ERROR, msg);
+ }
+ else {
+ final String methodName = getMethodName(externalFunctName);
+ final Method[] methods = clazz.getDeclaredMethods();
+
+ for (int i = 0; i < methods.length; i++) {
+ final int mods = methods[i].getModifiers();
+
+ if (Modifier.isPublic(mods)
+ && Modifier.isStatic(mods)
+ && methods[i].getName().equals(methodName))
+ {
+ return true;
+ }
+ }
+ }
+ }
+ catch (ClassNotFoundException e) {
+ final ErrorMsg msg =
+ new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR, className);
+ getParser().reportError(Constants.ERROR, msg);
+ }
return false;
}
/**
- * reports on whether the function specified in the argument to
+ * Reports on whether the function specified in the argument to
* xslt function 'function-available' was found.
*/
public boolean getResult() {
- if ((_namespaceOfFunct == null) ||
- (_namespaceOfFunct.equals(Constants.EMPTYSTRING)))
+ if (_namespaceOfFunct == null ||
+ _namespaceOfFunct.equals(EMPTYSTRING) ||
+ _namespaceOfFunct.equals(TRANSLET_URI))
{
- // no namespace, so the function is an internal xslt function.
final Parser parser = getParser();
_isFunctionAvailable = parser.functionSupported(_nameOfFunct);
}
return _isFunctionAvailable;
}
-
/**
* Calls to 'function-available' are resolved at compile time since
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org