コード例 #1
0
  /**
   * 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);
        schemaDOM.endElement();
      } else if (fAnnotationDepth == fDepth) {
        fAnnotationDepth = -1;
        schemaDOM.endAnnotation(element, fCurrentAnnotationElement);
        schemaDOM.endElement();
      } else { // inside a child of annotation
        schemaDOM.endAnnotationElement(element);
      }
    } 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--;
  }
コード例 #2
0
  /**
   * 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);
    }

    ElementImpl newElem =
        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.endAnnotation(element, newElem);
      }
    } else {
      schemaDOM.endAnnotationElement(element);
    }
  }