/** * 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--; }
public void startDocument( XMLLocator locator, String encoding, NamespaceContext namespaceContext, Augmentations augs) throws XNIException { fErrorReporter = (XMLErrorReporter) config.getProperty(ERROR_REPORTER); fGenerateSyntheticAnnotation = config.getFeature(GENERATE_SYNTHETIC_ANNOTATION); fHasNonSchemaAttributes.clear(); fSawAnnotation.clear(); schemaDOM = new SchemaDOM(); fAnnotationDepth = -1; fInnerAnnotationDepth = -1; fDepth = -1; fLocator = locator; fNamespaceContext = namespaceContext; schemaDOM.setDocumentURI(locator.getExpandedSystemId()); } // startDocument(XMLLocator,String,NamespaceContext, Augmentations)
/** * The start of an 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 startElement(QName element, XMLAttributes attributes, Augmentations augs) throws XNIException { fDepth++; // while it is true that non-whitespace character data // may only occur in appInfo or documentation // elements, it's certainly legal for comments and PI's to // occur as children of annotation; we need // to account for these here. if (fAnnotationDepth == -1) { if (element.uri == SchemaSymbols.URI_SCHEMAFORSCHEMA && element.localpart == SchemaSymbols.ELT_ANNOTATION) { if (fGenerateSyntheticAnnotation) { if (fSawAnnotation.size() > 0) { fSawAnnotation.pop(); } fSawAnnotation.push(true); } fAnnotationDepth = fDepth; schemaDOM.startAnnotation(element, attributes, fNamespaceContext); fCurrentAnnotationElement = schemaDOM.startElement( element, attributes, fLocator.getLineNumber(), fLocator.getColumnNumber(), fLocator.getCharacterOffset()); return; } else if (element.uri == SchemaSymbols.URI_SCHEMAFORSCHEMA && fGenerateSyntheticAnnotation) { fSawAnnotation.push(false); fHasNonSchemaAttributes.push(hasNonSchemaAttributes(element, attributes)); } } else if (fDepth == fAnnotationDepth + 1) { fInnerAnnotationDepth = fDepth; schemaDOM.startAnnotationElement(element, attributes); } else { schemaDOM.startAnnotationElement(element, attributes); // avoid falling through; don't call startElement in this case return; } schemaDOM.startElement( element, attributes, fLocator.getLineNumber(), fLocator.getColumnNumber(), fLocator.getCharacterOffset()); }