public void startElement(String uri, String localName, String qName, Attributes atts)
      throws SAXException {
    if (fNeedPushNSContext) {
      fNamespaceContext.pushContext();
    }
    fNeedPushNSContext = true;

    // Fill element QName
    fillQName(fElementQName, uri, localName, qName);

    // Fill XMLAttributes
    if (atts instanceof Attributes2) {
      fillXMLAttributes2((Attributes2) atts);
    } else {
      fillXMLAttributes(atts);
    }

    try {
      fSchemaValidator.startElement(fElementQName, fAttributes, null);
    } catch (XMLParseException e) {
      throw Util.toSAXParseException(e);
    } catch (XNIException e) {
      throw Util.toSAXException(e);
    }
  }
 /** Calls reset on each of the components owned by this component manager. * */
 public void reset() throws XNIException {
   fNamespaceContext.reset();
   fValidationManager.reset();
   fEntityManager.reset(this);
   fErrorReporter.reset(this);
   fSchemaValidator.reset(this);
   // Mark configuration as fixed.
   fConfigUpdated = false;
 }
 public void startPrefixMapping(String prefix, String uri) throws SAXException {
   String prefixSymbol;
   String uriSymbol;
   if (!fStringsInternalized) {
     prefixSymbol = (prefix != null) ? fSymbolTable.addSymbol(prefix) : XMLSymbols.EMPTY_STRING;
     uriSymbol = (uri != null && uri.length() > 0) ? fSymbolTable.addSymbol(uri) : null;
   } else {
     prefixSymbol = (prefix != null) ? prefix : XMLSymbols.EMPTY_STRING;
     uriSymbol = (uri != null && uri.length() > 0) ? uri : null;
   }
   if (fNeedPushNSContext) {
     fNeedPushNSContext = false;
     fNamespaceContext.pushContext();
   }
   fNamespaceContext.declarePrefix(prefixSymbol, uriSymbol);
   if (fContentHandler != null) {
     fContentHandler.startPrefixMapping(prefix, uri);
   }
 }
 public void endElement(String uri, String localName, String qName) throws SAXException {
   fillQName(fElementQName, uri, localName, qName);
   try {
     fSchemaValidator.endElement(fElementQName, null);
   } catch (XMLParseException e) {
     throw Util.toSAXParseException(e);
   } catch (XNIException e) {
     throw Util.toSAXException(e);
   } finally {
     fNamespaceContext.popContext();
   }
 }
  /**
   * The end of an element.
   *
   * @param element The name of the element.
   * @param augs Additional information that may include infoset augmentations
   * @exception XNIException Thrown by handler to signal an error.
   */
  public void endElement(QName element, Augmentations augs) throws XNIException {

    // when we reach the endElement of xs:appinfo or xs:documentation,
    // change fInnerAnnotationDepth to -1
    if (fAnnotationDepth > -1) {
      if (fInnerAnnotationDepth == fDepth) {
        fInnerAnnotationDepth = -1;
        schemaDOM.endAnnotationElement(element, false);
        schemaDOM.endElement();
      } else if (fAnnotationDepth == fDepth) {
        fAnnotationDepth = -1;
        schemaDOM.endAnnotationElement(element, true);
        schemaDOM.endElement();
      } else { // inside a child of annotation
        schemaDOM.endAnnotationElement(element, false);
      }
    } else { // not in an annotation at all
      if (element.uri == SchemaSymbols.URI_SCHEMAFORSCHEMA && fGenerateSyntheticAnnotation) {
        boolean value = fHasNonSchemaAttributes.pop();
        boolean sawann = fSawAnnotation.pop();
        if (value && !sawann) {
          String schemaPrefix = fNamespaceContext.getPrefix(SchemaSymbols.URI_SCHEMAFORSCHEMA);
          QName annQName =
              new QName(
                  schemaPrefix,
                  SchemaSymbols.ELT_ANNOTATION,
                  schemaPrefix
                      + (schemaPrefix.length() == 0 ? "" : ":")
                      + SchemaSymbols.ELT_ANNOTATION,
                  SchemaSymbols.URI_SCHEMAFORSCHEMA);
          schemaDOM.startAnnotation(annQName, fEmptyAttr, fNamespaceContext);
          QName elemQName =
              new QName(
                  schemaPrefix,
                  SchemaSymbols.ELT_DOCUMENTATION,
                  schemaPrefix
                      + (schemaPrefix.length() == 0 ? "" : ":")
                      + SchemaSymbols.ELT_DOCUMENTATION,
                  SchemaSymbols.URI_SCHEMAFORSCHEMA);
          schemaDOM.startAnnotationElement(elemQName, fEmptyAttr);
          schemaDOM.characters(new XMLString("SYNTHETIC_ANNOTATION".toCharArray(), 0, 20));
          schemaDOM.endSyntheticAnnotationElement(elemQName, false);
          schemaDOM.endSyntheticAnnotationElement(annQName, true);
        }
      }
      schemaDOM.endElement();
    }
    fDepth--;
  }
  /**
   * An empty element.
   *
   * @param element The name of the element.
   * @param attributes The element attributes.
   * @param augs Additional information that may include infoset augmentations
   * @exception XNIException Thrown by handler to signal an error.
   */
  public void emptyElement(QName element, XMLAttributes attributes, Augmentations augs)
      throws XNIException {

    if (fGenerateSyntheticAnnotation
        && fAnnotationDepth == -1
        && element.uri == SchemaSymbols.URI_SCHEMAFORSCHEMA
        && element.localpart != SchemaSymbols.ELT_ANNOTATION
        && hasNonSchemaAttributes(element, attributes)) {

      schemaDOM.startElement(
          element,
          attributes,
          fLocator.getLineNumber(),
          fLocator.getColumnNumber(),
          fLocator.getCharacterOffset());

      attributes.removeAllAttributes();
      String schemaPrefix = fNamespaceContext.getPrefix(SchemaSymbols.URI_SCHEMAFORSCHEMA);
      QName annQName =
          new QName(
              schemaPrefix,
              SchemaSymbols.ELT_ANNOTATION,
              schemaPrefix + (schemaPrefix.length() == 0 ? "" : ":") + SchemaSymbols.ELT_ANNOTATION,
              SchemaSymbols.URI_SCHEMAFORSCHEMA);
      schemaDOM.startAnnotation(annQName, attributes, fNamespaceContext);
      QName elemQName =
          new QName(
              schemaPrefix,
              SchemaSymbols.ELT_DOCUMENTATION,
              schemaPrefix
                  + (schemaPrefix.length() == 0 ? "" : ":")
                  + SchemaSymbols.ELT_DOCUMENTATION,
              SchemaSymbols.URI_SCHEMAFORSCHEMA);
      schemaDOM.startAnnotationElement(elemQName, attributes);
      schemaDOM.characters(new XMLString("SYNTHETIC_ANNOTATION".toCharArray(), 0, 20));
      schemaDOM.endSyntheticAnnotationElement(elemQName, false);
      schemaDOM.endSyntheticAnnotationElement(annQName, true);

      schemaDOM.endElement();

      return;
    }
    // the order of events that occurs here is:
    //   schemaDOM.startAnnotation/startAnnotationElement (if applicable)
    //   schemaDOM.emptyElement  (basically the same as startElement then endElement)
    //   schemaDOM.endAnnotationElement (if applicable)
    // the order of events that would occur if this was <element></element>:
    //   schemaDOM.startAnnotation/startAnnotationElement (if applicable)
    //   schemaDOM.startElement
    //   schemaDOM.endAnnotationElement (if applicable)
    //   schemaDOM.endElementElement
    // Thus, we can see that the order of events isn't the same.  However, it doesn't
    // seem to matter.  -- PJM
    if (fAnnotationDepth == -1) {
      // this is messed up, but a case to consider:
      if (element.uri == SchemaSymbols.URI_SCHEMAFORSCHEMA
          && element.localpart == SchemaSymbols.ELT_ANNOTATION) {
        schemaDOM.startAnnotation(element, attributes, fNamespaceContext);
      }
    } else {
      schemaDOM.startAnnotationElement(element, attributes);
    }

    schemaDOM.emptyElement(
        element,
        attributes,
        fLocator.getLineNumber(),
        fLocator.getColumnNumber(),
        fLocator.getCharacterOffset());

    if (fAnnotationDepth == -1) {
      // this is messed up, but a case to consider:
      if (element.uri == SchemaSymbols.URI_SCHEMAFORSCHEMA
          && element.localpart == SchemaSymbols.ELT_ANNOTATION) {
        schemaDOM.endAnnotationElement(element, true);
      }
    } else {
      schemaDOM.endAnnotationElement(element, false);
    }
  }