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 State(UnmarshallingContext context) throws SAXException {
      result = dom.createUnmarshaller(context);

      handler.setResult(result);

      // emulate the start of documents
      try {
        handler.setDocumentLocator(context.getLocator());
        handler.startDocument();
        declarePrefixes(context, context.getAllDeclaredPrefixes());
      } catch (SAXException e) {
        context.handleError(e);
        throw e;
      }
    }