Hi Sanjaya,
Sanjaya Liyanage <[email protected]> wrote on 03/29/2010 11:17:19 AM:
> Hi Michael,
> Thank you very much for encouraging me and for your suggestions.I
> began to go through the scanExpr method in XPath.Scanner inner class.I
> think I not only have to deal with the XPath.Scanner but also have to
> create a constructor for XPath.Tokens inner class in order to allow
> new symbols to be existed in xerces XPath.
Right. You may need to make additional changes to the base classes to
support an extension.
> I go through the XPath
> class but couldn't find a method called createScanner which you asked
> me to override in my child class.In parseExpresssion method the
> Scanner constructor and the scanExpr methods are called.Is the
> createScanner() method similar to scanExpr method or is it something
> else. Please give me an explanation about the createScanner method and
> make me correct if I'm following in a wrong way.
Within parseExpression() there is some code which creates the
XPath.Scanner:
XPath.Scanner scanner = new XPath.Scanner(fSymbolTable) {
protected void addToken(XPath.Tokens tokens, int token).
throws XPathException {
if (
token == XPath.Tokens.EXPRTOKEN_ATSIGN ||
token == XPath.Tokens.EXPRTOKEN_NAMETEST_QNAME ||
token == XPath.Tokens.EXPRTOKEN_OPERATOR_SLASH ||
token == XPath.Tokens.EXPRTOKEN_PERIOD ||
token == XPath.Tokens.EXPRTOKEN_NAMETEST_ANY ||
token == XPath.Tokens.EXPRTOKEN_NAMETEST_NAMESPACE ||
token == XPath.Tokens.EXPRTOKEN_OPERATOR_DOUBLE_SLASH
||
token == XPath.Tokens.EXPRTOKEN_OPERATOR_UNION ||
token == XPath.Tokens.EXPRTOKEN_AXISNAME_CHILD ||
token == XPath.Tokens.EXPRTOKEN_AXISNAME_ATTRIBUTE ||
token == XPath.Tokens.EXPRTOKEN_DOUBLE_COLON
//
) {
super.addToken(tokens, token);
return;
}
throw new XPathException("c-general-xpath");
}
};
I was suggesting that this be factored out into another method. For
example:
protected XPath.Scanner createScanner() {
return new XPath.Scanner(fSymbolTable) {
protected void addToken(XPath.Tokens tokens, int token)
throws XPathException {
if (
token == XPath.Tokens.EXPRTOKEN_ATSIGN ||
token == XPath.Tokens.EXPRTOKEN_NAMETEST_QNAME ||
token == XPath.Tokens.EXPRTOKEN_OPERATOR_SLASH ||
token == XPath.Tokens.EXPRTOKEN_PERIOD ||
token == XPath.Tokens.EXPRTOKEN_NAMETEST_ANY ||
token == XPath.Tokens.EXPRTOKEN_NAMETEST_NAMESPACE ||
token == XPath.Tokens.EXPRTOKEN_OPERATOR_DOUBLE_SLASH
||
token == XPath.Tokens.EXPRTOKEN_OPERATOR_UNION ||
token == XPath.Tokens.EXPRTOKEN_AXISNAME_CHILD ||
token == XPath.Tokens.EXPRTOKEN_AXISNAME_ATTRIBUTE ||
token == XPath.Tokens.EXPRTOKEN_DOUBLE_COLON
//
) {
super.addToken(tokens, token);
return;
}
throw new XPathException("c-general-xpath");
}
};
}
and call that new method from parseExpression():
XPath.Scanner scanner = createScanner();
Then you can replace the XPath.Scanner with your own extension by
overriding createScanner() in a subclass.
> Thank you.
> Sanjaya Liyanage.
Thanks.
Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: [email protected]
E-mail: [email protected]