/** * 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); } 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()); }
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)
/** * 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); } }