Exemple #1
0
 /**
  * Execute the compiled Query, returning the first item in the result. This is useful where it is
  * known that the expression will only return a singleton value (for example, a single node, or a
  * boolean).
  *
  * @param env Provides the dynamic query evaluation context
  * @return The first item in the sequence returned by the expression. If the expression returns an
  *     empty sequence, this method returns null. Otherwise, it returns the first item in the
  *     result sequence, represented as a Java object using the same mapping as for the {@link
  *     XQueryExpression#evaluate evaluate} method
  */
 public Object evaluateSingle(DynamicQueryContext env) throws XPathException {
   if (isUpdating) {
     throw new XPathException("Cannot call evaluateSingle() on an updating query");
   }
   SequenceIterator iterator = iterator(env);
   Item item = iterator.next();
   if (item == null) {
     return null;
   }
   return Value.convertToJava(item);
 }
Exemple #2
0
 /**
  * Execute a the compiled Query, returning the results as a List.
  *
  * @param env Provides the dynamic query evaluation context
  * @return The results of the expression, as a List. The List represents the sequence of items
  *     returned by the expression. Each item in the list will either be an object representing a
  *     node, or an object representing an atomic value. For the types of Java object that may be
  *     returned, see the description of the {@link org.orbeon.saxon.xpath.XPathEvaluator#evaluate
  *     evaluate} method of class XPathProcessor
  */
 public List evaluate(DynamicQueryContext env) throws XPathException {
   if (isUpdating) {
     throw new XPathException("Cannot call evaluate() on an updating query");
   }
   SequenceIterator iterator = iterator(env);
   ArrayList list = new ArrayList(100);
   while (true) {
     Item item = iterator.next();
     if (item == null) {
       return list;
     }
     list.add(Value.convertToJava(item));
   }
 }