private void endElement() {
    // discard will be false if the matching start token was for a static element, and will be
    // true otherwise (component, block, parameter).

    boolean discard = discardEndTagStack.pop();

    if (!discard) addToBody(END_ELEMENT);

    Runnable command = endElementCommandStack.pop();

    // Used to return environment to prior state.

    command.run();
  }
  /**
   * As currently implemented, this should be invoked just once and then the PageLoaderProcessor
   * instance should be discarded.
   */
  public Page loadPage(String logicalPageName, String pageClassName, Locale locale) {
    // Ensure that loadPage() may only be invoked once.

    lock.lock();

    this.locale = locale;

    // Todo: Need a resources object for Pages, not just ComponentPageElement ... too many
    // parameters here.

    page =
        new PageImpl(
            logicalPageName,
            this.locale,
            linkFactory,
            persistentFieldManager,
            componentClassResolver);

    loadRootComponent(pageClassName);

    workComponentQueue();

    // Take care of any finalization logic that's been deferred out.

    for (Runnable r : finalization) {
      r.run();
    }

    // The page is *loaded* before it is attached to the request.
    // This is to help ensure that no client-specific information leaks
    // into the page.

    page.loaded();

    return page;
  }