From: Wolfgang M. M. <wol...@us...> - 2004-09-26 15:55:10
|
Update of /cvsroot/exist/eXist-1.0/src/org/exist/xquery/functions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16676/src/org/exist/xquery/functions Modified Files: FunNot.java Log Message: fn:not() throws exception on queries like /blah[not(blah)], where blah is a non-existent element. Index: FunNot.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xquery/functions/FunNot.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** FunNot.java 23 Sep 2004 12:41:19 -0000 1.7 --- FunNot.java 26 Sep 2004 15:55:00 -0000 1.8 *************** *** 79,84 **** // the remaining set if (Type.subTypeOf(arg.returnsType(), Type.NODE) && ! (arg.getDependencies() & Dependency.CONTEXT_ITEM) == 0 && ! contextSequence.getLength() > 0) { NodeSet result = new ExtArrayNodeSet(); if(contextSequence.getLength() > 0) --- 79,92 ---- // the remaining set if (Type.subTypeOf(arg.returnsType(), Type.NODE) && ! (arg.getDependencies() & Dependency.CONTEXT_ITEM) == 0) { ! if (contextSequence.getLength() == 0) { ! // special treatment if the context sequence is empty: ! // within a predicate, we just return the empty sequence ! // otherwise evaluate the argument and return a boolean result ! if (inPredicate) ! return Sequence.EMPTY_SEQUENCE; ! else ! return evalBoolean(contextSequence, contextItem, arg); ! } NodeSet result = new ExtArrayNodeSet(); if(contextSequence.getLength() > 0) *************** *** 99,108 **** // case 2: simply invert the boolean value } else { ! Sequence seq = ! arg.eval(contextSequence, contextItem); ! return seq.effectiveBooleanValue() ? BooleanValue.FALSE : BooleanValue.TRUE; } } public String pprint() { StringBuffer buf = new StringBuffer(); --- 107,127 ---- // case 2: simply invert the boolean value } else { ! return evalBoolean(contextSequence, contextItem, arg); } } + /** + * @param contextSequence + * @param contextItem + * @param arg + * @return + * @throws XPathException + */ + private Sequence evalBoolean(Sequence contextSequence, Item contextItem, Expression arg) throws XPathException { + Sequence seq = + arg.eval(contextSequence, contextItem); + return seq.effectiveBooleanValue() ? BooleanValue.FALSE : BooleanValue.TRUE; + } + public String pprint() { StringBuffer buf = new StringBuffer(); |