public void leaveElement(UnmarshallingContext.State state, TagName ea) throws SAXException {
    State s = (State) state.target;
    UnmarshallingContext context = state.getContext();

    try {
      s.handler.endElement(ea.uri, ea.local, ea.getQname());
      s.undeclarePrefixes(context.getNewlyDeclaredPrefixes());
    } catch (SAXException e) {
      context.handleError(e);
      throw e;
    }

    if ((--s.depth) == 0) {
      // emulate the end of the document
      try {
        s.undeclarePrefixes(context.getAllDeclaredPrefixes());
        s.handler.endDocument();
      } catch (SAXException e) {
        context.handleError(e);
        throw e;
      }

      // we are done
      state.target = s.getElement();
    }
  }
  public void startElement(UnmarshallingContext.State state, TagName ea) throws SAXException {
    UnmarshallingContext context = state.getContext();
    if (state.target == null) state.target = new State(context);

    State s = (State) state.target;
    try {
      s.declarePrefixes(context, context.getNewlyDeclaredPrefixes());
      s.handler.startElement(ea.uri, ea.local, ea.getQname(), ea.atts);
    } catch (SAXException e) {
      context.handleError(e);
      throw e;
    }
  }