You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by sb...@apache.org on 2002/06/10 22:47:44 UTC
cvs commit: xml-xalan/java/src/org/apache/xpath/res XPATHErrorResources.properties
sboag 2002/06/10 13:47:44
Modified: java/src/org/apache/xalan/templates FuncDocument.java
FuncFormatNumb.java
java/src/org/apache/xpath/functions FuncConcat.java
FuncExtFunction.java FuncSubstring.java
Function.java Function2Args.java Function3Args.java
FunctionDef1Arg.java FunctionMultiArgs.java
FunctionOneArg.java
java/src/org/apache/xpath/res XPATHErrorResources.properties
Log:
Patch submitted by Henry_Zongaro@us.ibm.com:
To summarize what I did, the Function class and its subclasses have two
methods that check the number of arguments: setArg and
checkNumberArgs. The former checks whether too many arguments are
specified, and the latter checks for too few (or too many, redundantly).
In the case where there are optional arguments (as in substring), the class
for the function (FuncSubstring, in this case) derives from a class that has a
fixed number of arguments (Func3Arguments, in this case). If too few
arguments are specified, the FuncSubstring.checkNumberArgs method
reports that the function only allows 2 or 3 arguments; if too many arguments
are specified, the Function3Arguments.setArg method reports that the
function only allows 3 arguments.
To fix the problem, I added reportWrongNumberArgs() methods to the
Function class and to its subclasses, as appropriate, and I added code to
call that from checkNumberArgs and setArg - that way, the correct number
of arguments is always reported in the error messages.
Alternatively, I could have changed the setArg method in all the classes that
have optional arguments to report correctly the number of arguments, but I
didn't like the idea of having it redundantly perform the same check that the
setArg method of its base class was going to perform just to get a better
message out. A third possibility would be to have setArg call the
checkNumberArgs method when it detects too many arguments are
specified; that would guarantee that setArg would report the same message,
and avoid introducing a new method, as long as checkNumberArgs always
checks for both too few and for too many arguments. A fourth possibility
would be to report two different errors: the minimum number of arguments
required in checkNumberArgs and the maximum permitted in setArg.
I also noticed that the message produced for FuncSubstring when too few
arguments are specified actually indicates that 0 or 1 arguments are required,
so I fixed the XPATHErrorResources.properties file.
I don't see the NPE that Dave Marston mentions in Bugzilla, so I assume
that's been fixed.
Revision Changes Path
1.27 +10 -0 xml-xalan/java/src/org/apache/xalan/templates/FuncDocument.java
Index: FuncDocument.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/templates/FuncDocument.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- FuncDocument.java 22 Mar 2002 01:04:40 -0000 1.26
+++ FuncDocument.java 10 Jun 2002 20:47:44 -0000 1.27
@@ -480,6 +480,16 @@
public void checkNumberArgs(int argNum) throws WrongNumberArgsException
{
if ((argNum < 1) || (argNum > 2))
+ reportWrongNumberArgs();
+ }
+
+ /**
+ * Constructs and throws a WrongNumberArgException with the appropriate
+ * message for this function object.
+ *
+ * @throws WrongNumberArgsException
+ */
+ protected void reportWrongNumberArgs() throws WrongNumberArgsException {
throw new WrongNumberArgsException(XSLMessages.createMessage(XSLTErrorResources.ER_ONE_OR_TWO, null)); //"1 or 2");
}
1.17 +10 -0 xml-xalan/java/src/org/apache/xalan/templates/FuncFormatNumb.java
Index: FuncFormatNumb.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/templates/FuncFormatNumb.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- FuncFormatNumb.java 8 Aug 2001 04:59:07 -0000 1.16
+++ FuncFormatNumb.java 10 Jun 2002 20:47:44 -0000 1.17
@@ -215,6 +215,16 @@
public void checkNumberArgs(int argNum) throws WrongNumberArgsException
{
if ((argNum > 3) || (argNum < 2))
+ reportWrongNumberArgs();
+ }
+
+ /**
+ * Constructs and throws a WrongNumberArgException with the appropriate
+ * message for this function object.
+ *
+ * @throws WrongNumberArgsException
+ */
+ protected void reportWrongNumberArgs() throws WrongNumberArgsException {
throw new WrongNumberArgsException(XSLMessages.createMessage(XSLTErrorResources.ER_TWO_OR_THREE, null)); //"2 or 3");
}
}
1.7 +10 -0 xml-xalan/java/src/org/apache/xpath/functions/FuncConcat.java
Index: FuncConcat.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/functions/FuncConcat.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- FuncConcat.java 7 Jun 2002 17:13:55 -0000 1.6
+++ FuncConcat.java 10 Jun 2002 20:47:44 -0000 1.7
@@ -113,6 +113,16 @@
public void checkNumberArgs(int argNum) throws WrongNumberArgsException
{
if (argNum < 2)
+ reportWrongNumberArgs();
+ }
+
+ /**
+ * Constructs and throws a WrongNumberArgException with the appropriate
+ * message for this function object.
+ *
+ * @throws WrongNumberArgsException
+ */
+ protected void reportWrongNumberArgs() throws WrongNumberArgsException {
throw new WrongNumberArgsException(XSLMessages.createXPATHMessage("gtone", null));
}
}
1.16 +17 -0 xml-xalan/java/src/org/apache/xpath/functions/FuncExtFunction.java
Index: FuncExtFunction.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/functions/FuncExtFunction.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- FuncExtFunction.java 10 Jun 2002 19:24:42 -0000 1.15
+++ FuncExtFunction.java 10 Jun 2002 20:47:44 -0000 1.16
@@ -72,6 +72,8 @@
import org.apache.xml.dtm.*;
import org.apache.xpath.axes.*;
+import org.apache.xpath.res.XPATHErrorResources;
+import org.apache.xalan.res.XSLMessages;
/**
* <meta name="usage" content="advanced"/>
@@ -231,4 +233,19 @@
* @throws WrongNumberArgsException
*/
public void checkNumberArgs(int argNum) throws WrongNumberArgsException{}
+
+ /**
+ * Constructs and throws a WrongNumberArgException with the appropriate
+ * message for this function object. This class supports an arbitrary
+ * number of arguments, so this method must never be called.
+ *
+ * @throws WrongNumberArgsException
+ */
+ protected void reportWrongNumberArgs() throws WrongNumberArgsException {
+ String fMsg = XSLMessages.createXPATHMessage(
+ XPATHErrorResources.ER_INCORRECT_PROGRAMMER_ASSERTION,
+ new Object[]{ "Programmer's assertion: the method FunctionMultiArgs.reportWrongNumberArgs() should never be called." });
+
+ throw new RuntimeException(fMsg);
+ }
}
1.8 +10 -0 xml-xalan/java/src/org/apache/xpath/functions/FuncSubstring.java
Index: FuncSubstring.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/functions/FuncSubstring.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- FuncSubstring.java 28 Jul 2001 00:26:00 -0000 1.7
+++ FuncSubstring.java 10 Jun 2002 20:47:44 -0000 1.8
@@ -149,6 +149,16 @@
public void checkNumberArgs(int argNum) throws WrongNumberArgsException
{
if (argNum < 2)
+ reportWrongNumberArgs();
+ }
+
+ /**
+ * Constructs and throws a WrongNumberArgException with the appropriate
+ * message for this function object.
+ *
+ * @throws WrongNumberArgsException
+ */
+ protected void reportWrongNumberArgs() throws WrongNumberArgsException {
throw new WrongNumberArgsException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_TWO_OR_THREE, null)); //"2 or 3");
}
}
1.9 +13 -1 xml-xalan/java/src/org/apache/xpath/functions/Function.java
Index: Function.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/functions/Function.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Function.java 7 Jun 2002 17:13:55 -0000 1.8
+++ Function.java 10 Jun 2002 20:47:44 -0000 1.9
@@ -93,7 +93,8 @@
public void setArg(Expression arg, int argNum)
throws WrongNumberArgsException
{
- throw new WrongNumberArgsException(XSLMessages.createXPATHMessage("zero", null));
+ // throw new WrongNumberArgsException(XSLMessages.createXPATHMessage("zero", null));
+ reportWrongNumberArgs();
}
/**
@@ -109,6 +110,17 @@
public void checkNumberArgs(int argNum) throws WrongNumberArgsException
{
if (argNum != 0)
+ reportWrongNumberArgs();
+ }
+
+ /**
+ * Constructs and throws a WrongNumberArgException with the appropriate
+ * message for this function object. This method is meant to be overloaded
+ * by derived classes so that the message will be as specific as possible.
+ *
+ * @throws WrongNumberArgsException
+ */
+ protected void reportWrongNumberArgs() throws WrongNumberArgsException {
throw new WrongNumberArgsException(XSLMessages.createXPATHMessage("zero", null));
}
1.9 +11 -1 xml-xalan/java/src/org/apache/xpath/functions/Function2Args.java
Index: Function2Args.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/functions/Function2Args.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Function2Args.java 7 Jun 2002 17:13:55 -0000 1.8
+++ Function2Args.java 10 Jun 2002 20:47:44 -0000 1.9
@@ -125,7 +125,7 @@
arg.exprSetParent(this);
}
else
- throw new WrongNumberArgsException(XSLMessages.createXPATHMessage("two", null));
+ reportWrongNumberArgs();
}
/**
@@ -139,6 +139,16 @@
public void checkNumberArgs(int argNum) throws WrongNumberArgsException
{
if (argNum != 2)
+ reportWrongNumberArgs();
+ }
+
+ /**
+ * Constructs and throws a WrongNumberArgException with the appropriate
+ * message for this function object.
+ *
+ * @throws WrongNumberArgsException
+ */
+ protected void reportWrongNumberArgs() throws WrongNumberArgsException {
throw new WrongNumberArgsException(XSLMessages.createXPATHMessage("two", null));
}
1.10 +11 -1 xml-xalan/java/src/org/apache/xpath/functions/Function3Args.java
Index: Function3Args.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/functions/Function3Args.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- Function3Args.java 7 Jun 2002 17:13:55 -0000 1.9
+++ Function3Args.java 10 Jun 2002 20:47:44 -0000 1.10
@@ -123,7 +123,7 @@
arg.exprSetParent(this);
}
else
- throw new WrongNumberArgsException(XSLMessages.createXPATHMessage("three", null));
+ reportWrongNumberArgs();
}
/**
@@ -137,6 +137,16 @@
public void checkNumberArgs(int argNum) throws WrongNumberArgsException
{
if (argNum != 3)
+ reportWrongNumberArgs();
+ }
+
+ /**
+ * Constructs and throws a WrongNumberArgException with the appropriate
+ * message for this function object.
+ *
+ * @throws WrongNumberArgsException
+ */
+ protected void reportWrongNumberArgs() throws WrongNumberArgsException {
throw new WrongNumberArgsException(XSLMessages.createXPATHMessage("three", null));
}
1.8 +10 -0 xml-xalan/java/src/org/apache/xpath/functions/FunctionDef1Arg.java
Index: FunctionDef1Arg.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/functions/FunctionDef1Arg.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- FunctionDef1Arg.java 28 Jul 2001 00:26:00 -0000 1.7
+++ FunctionDef1Arg.java 10 Jun 2002 20:47:44 -0000 1.8
@@ -182,6 +182,16 @@
public void checkNumberArgs(int argNum) throws WrongNumberArgsException
{
if (argNum > 1)
+ reportWrongNumberArgs();
+ }
+
+ /**
+ * Constructs and throws a WrongNumberArgException with the appropriate
+ * message for this function object.
+ *
+ * @throws WrongNumberArgsException
+ */
+ protected void reportWrongNumberArgs() throws WrongNumberArgsException {
throw new WrongNumberArgsException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_ZERO_OR_ONE, null)); //"0 or 1");
}
1.9 +17 -0 xml-xalan/java/src/org/apache/xpath/functions/FunctionMultiArgs.java
Index: FunctionMultiArgs.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/functions/FunctionMultiArgs.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- FunctionMultiArgs.java 22 Mar 2002 01:04:44 -0000 1.8
+++ FunctionMultiArgs.java 10 Jun 2002 20:47:44 -0000 1.9
@@ -62,6 +62,8 @@
import org.apache.xpath.ExpressionOwner;
import org.apache.xpath.XPathVisitor;
import org.apache.xpath.functions.Function3Args.Arg2Owner;
+import org.apache.xpath.res.XPATHErrorResources;
+import org.apache.xalan.res.XSLMessages;
/**
* <meta name="usage" content="advanced"/>
@@ -144,6 +146,21 @@
* @throws WrongNumberArgsException
*/
public void checkNumberArgs(int argNum) throws WrongNumberArgsException{}
+
+ /**
+ * Constructs and throws a WrongNumberArgException with the appropriate
+ * message for this function object. This class supports an arbitrary
+ * number of arguments, so this method must never be called.
+ *
+ * @throws WrongNumberArgsException
+ */
+ protected void reportWrongNumberArgs() throws WrongNumberArgsException {
+ String fMsg = XSLMessages.createXPATHMessage(
+ XPATHErrorResources.ER_INCORRECT_PROGRAMMER_ASSERTION,
+ new Object[]{ "Programmer's assertion: the method FunctionMultiArgs.reportWrongNumberArgs() should never be called." });
+
+ throw new RuntimeException(fMsg);
+ }
/**
* Tell if this expression or it's subexpressions can traverse outside
1.9 +11 -1 xml-xalan/java/src/org/apache/xpath/functions/FunctionOneArg.java
Index: FunctionOneArg.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/functions/FunctionOneArg.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- FunctionOneArg.java 7 Jun 2002 17:13:55 -0000 1.8
+++ FunctionOneArg.java 10 Jun 2002 20:47:44 -0000 1.9
@@ -104,7 +104,7 @@
arg.exprSetParent(this);
}
else
- throw new WrongNumberArgsException(XSLMessages.createXPATHMessage("one", null));
+ reportWrongNumberArgs();
}
/**
@@ -118,6 +118,16 @@
public void checkNumberArgs(int argNum) throws WrongNumberArgsException
{
if (argNum != 1)
+ reportWrongNumberArgs();
+ }
+
+ /**
+ * Constructs and throws a WrongNumberArgException with the appropriate
+ * message for this function object.
+ *
+ * @throws WrongNumberArgsException
+ */
+ protected void reportWrongNumberArgs() throws WrongNumberArgsException {
throw new WrongNumberArgsException(XSLMessages.createXPATHMessage("one", null));
}
1.3 +1 -1 xml-xalan/java/src/org/apache/xpath/res/XPATHErrorResources.properties
Index: XPATHErrorResources.properties
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/res/XPATHErrorResources.properties,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- XPATHErrorResources.properties 7 Jun 2002 17:13:55 -0000 1.2
+++ XPATHErrorResources.properties 10 Jun 2002 20:47:44 -0000 1.3
@@ -173,7 +173,7 @@
# ER_FASTSTRINGBUFFER_CANNOT_BE_NULL
ER0083=The FastStringBuffer argument can not be null
# ER_TWO_OR_THREE
-ER0084=0 or 1
+ER0084=2 or 3
# ER_VARIABLE_ACCESSED_BEFORE_BIND
ER0085=Variable accessed before it is bound!
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org