// javadoc inherited
  protected void setUp() throws Exception {
    super.setUp();

    // create the adapter process that will be added by the rule
    adapterProcess = new MockAdapterProcess();

    // create the rule
    rule = new AddAdapterRule();

    // get hold of the default pipeline factory
    XMLPipelineFactory factory = XMLPipelineFactory.getDefaultInstance();

    // factory a pipeline configuration
    XMLPipelineConfiguration pipelineConfiguration = factory.createPipelineConfiguration();

    // factor a DynamicProcessConfiguration
    DynamicProcessConfiguration dynamicConfig = factory.createDynamicProcessConfiguration();

    // register the DynamicProcessConfiguration with the pipeline
    // configuration
    pipelineConfiguration.storeConfiguration(DynamicProcessConfiguration.class, dynamicConfig);

    // create a XMLPipelineContext
    EnvironmentInteraction interaction = null;
    XMLPipelineContext context = factory.createPipelineContext(pipelineConfiguration, interaction);

    // create a pipeline
    XMLPipeline pipeline = factory.createDynamicPipeline(context);

    // create a dynamic process
    dynamicProcess = factory.createDynamicProcess(new SimpleDynamicProcessConfiguration());

    // finally, register the pipeline with the dynamic process
    dynamicProcess.setPipeline(pipeline);
  }
  /**
   * Tests the {@link AbstractAddAdapterRule#startElement} method
   *
   * @throws Exception if an error occurs
   */
  public void testStartElement() throws Exception {
    // create an expanded name
    ExpandedName eName = new ImmutableExpandedName("testNamespace", "testLocalName");
    Attributes atts = new AttributesImpl();

    XMLPipeline pipeline = dynamicProcess.getPipeline();

    NamespacePrefixTracker tracker = pipeline.getPipelineContext().getNamespacePrefixTracker();

    // register the prefix with the tracker
    tracker.startPrefixMapping("p", "testNamespace");

    // invoke startElement on the rule
    Object returned = rule.startElement(dynamicProcess, eName, atts);

    // ensure the process was added to the pipeline
    assertSame(
        "Adapter Process was not added to the pipeline", adapterProcess, pipeline.getHeadProcess());

    // ensure the object return was the addapter process
    assertSame(
        "startElement should return the adapter process that was " + "added to the pipeline",
        adapterProcess,
        returned);

    // ensure the adapters processes setElementDetails method was invoked
    adapterProcess.assertSetElementDetailsInvoked(
        "testNamespace", "testLocalName", "p:testLocalName");

    // ensure the processAttributes method was invoked ok
    adapterProcess.assertProcessAttributesInvoked(atts);
  }
  /**
   * Tests the {@link AbstractAddAdapterRule#endElement} method
   *
   * @throws Exception if an error occurs
   */
  public void testEndElement() throws Exception {
    // retrieve the pipeline
    XMLPipeline pipeline = dynamicProcess.getPipeline();
    // add a process to the head of the pipeline
    pipeline.addHeadProcess(adapterProcess);

    ExpandedName eName = new ImmutableExpandedName("testNamespace", "testLocalName");

    // call end element on the rule
    rule.endElement(dynamicProcess, eName, adapterProcess);

    // ensure that the process was removed from the pipeline
    assertNotSame(
        "endElement did not remove the adapter process from " + "the pipeline",
        adapterProcess,
        pipeline.getHeadProcess());
  }
  /**
   * Tests that the {@link AbstractAddAdapterRule#endElement} method throws an exception if you
   * attempt to remove a process that is not at the head of the pipeline
   *
   * @throws Exception if an error occurs
   */
  public void testEndElementWithWrongProcess() throws Exception {
    // retrieve the pipeline
    XMLPipeline pipeline = dynamicProcess.getPipeline();
    // add the process to the head of the pipeline
    pipeline.addHeadProcess(adapterProcess);

    // create an expanded name
    ExpandedName eName = new ImmutableExpandedName("testNamespace", "testLocalName");

    try {
      // call end element on the rule
      rule.endElement(dynamicProcess, eName, new MockAdapterProcess());
      fail(
          "endElement did not throw an exception when attempting to "
              + "remove a process that was not at the head of the pipeline");
    } catch (XMLPipelineException e) {
    }
  }
  // Javadoc inherited.
  public Object startElement(
      DynamicProcess dynamicProcess, ExpandedName element, Attributes attributes)
      throws SAXException {

    TemplateModel model = getModel(dynamicProcess);

    String evaluationMode = attributes.getValue("evaluationMode");
    EvaluationMode mode;
    if (evaluationMode == null) {
      mode = EvaluationMode.IMMEDIATE;
    } else {
      mode = EvaluationMode.literal(evaluationMode);
      if (mode == null) {
        throw forwardFatalError(dynamicProcess, "Unknown evaluation mode '" + evaluationMode + "'");
      }
    }

    if (mode != EvaluationMode.IMMEDIATE) {
      dynamicProcess.passThroughElementContents();
    }

    model.startValueDefinition(this.element, mode);
    return model;
  }