示例#1
0
  /**
   * Run the query in pull mode.
   *
   * <p>
   *
   * <p>For maximum effect this method should be used when lazyConstructionMode has been set in the
   * Configuration.
   *
   * <p>
   *
   * <p><b>Note: this method usually has very similar performance to the {@link
   * #run(DynamicQueryContext,javax.xml.transform.Result,java.util.Properties)} method (which does
   * the same thing), but sometimes it is significantly slower. Therefore, the run() method is
   * preferred.</b>
   *
   * @param dynamicEnv the dynamic context for query evaluation
   * @param destination the destination of the query results
   * @param outputProperties the serialization parameters
   * @see Configuration#setLazyConstructionMode(boolean)
   */
  public void pull(DynamicQueryContext dynamicEnv, Result destination, Properties outputProperties)
      throws XPathException {
    if (isUpdating) {
      throw new XPathException("Cannot call pull() on an updating query");
    }
    Configuration config = dynamicEnv.getConfiguration();
    try {
      Controller controller = newController();
      // initializeController(dynamicEnv, controller);
      EventIterator iter = iterateEvents(controller, dynamicEnv);
      // iter = new Decomposer(iter, config);

      Properties actualProperties = validateOutputProperties(controller, outputProperties);
      SerializerFactory sf = config.getSerializerFactory();
      PipelineConfiguration pipe = config.makePipelineConfiguration();
      pipe.setSerializing(true);
      Receiver receiver = sf.getReceiver(destination, pipe, actualProperties);

      receiver = new NamespaceReducer(receiver);
      if ("yes".equals(actualProperties.getProperty(SaxonOutputKeys.WRAP))) {
        receiver = new SequenceWrapper(receiver);
        // receiver = new TracingFilter(receiver);
      } else {
        receiver = new TreeReceiver(receiver);
      }
      EventIteratorToReceiver.copy(iter, (SequenceReceiver) receiver);
    } catch (XPathException err) {
      config.reportFatalError(err);
      throw err;
    }
  }