mrglavas 2004/12/19 20:33:07 Modified: java/src/org/apache/xerces/impl/xs/opti SchemaDOMParser.java Log: Fixing an NPE and a bug with detecting non-schema attributes related to the new generate-synthetic-annotations feature. On an empty element we need to check that we're not currently processing an annotation. Revision Changes Path 1.15 +17 -10 xml-xerces/java/src/org/apache/xerces/impl/xs/opti/SchemaDOMParser.java Index: SchemaDOMParser.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/opti/SchemaDOMParser.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- SchemaDOMParser.java 17 Dec 2004 13:52:34 -0000 1.14 +++ SchemaDOMParser.java 20 Dec 2004 04:33:07 -0000 1.15 @@ -25,7 +25,6 @@ import org.apache.xerces.impl.xs.XSMessageFormatter; import org.apache.xerces.util.XMLAttributesImpl; import org.apache.xerces.util.XMLChar; -import org.apache.xerces.util.XMLSymbols; import org.apache.xerces.xni.Augmentations; import org.apache.xerces.xni.NamespaceContext; import org.apache.xerces.xni.QName; @@ -225,16 +224,18 @@ if (fAnnotationDepth == -1) { if (element.uri == SchemaSymbols.URI_SCHEMAFORSCHEMA && element.localpart == SchemaSymbols.ELT_ANNOTATION) { - if(fGenerateSyntheticAnnotation) { - if(fSawAnnotation.size() > 0) fSawAnnotation.pop(); + if (fGenerateSyntheticAnnotation) { + if (fSawAnnotation.size() > 0) { + fSawAnnotation.pop(); + } fSawAnnotation.push(Boolean.TRUE); } fAnnotationDepth = fDepth; schemaDOM.startAnnotation(element, attributes, fNamespaceContext); } - else if(fGenerateSyntheticAnnotation) { + else if (fGenerateSyntheticAnnotation) { fSawAnnotation.push(Boolean.FALSE); - fHasNonSchemaAttributes.push(hasNonSchemaAttributes(attributes) ? Boolean.TRUE : Boolean.FALSE); + fHasNonSchemaAttributes.push(hasNonSchemaAttributes(element, attributes) ? Boolean.TRUE : Boolean.FALSE); } } else if(fDepth == fAnnotationDepth+1) { fInnerAnnotationDepth = fDepth; @@ -265,7 +266,8 @@ public void emptyElement(QName element, XMLAttributes attributes, Augmentations augs) throws XNIException { - if(fGenerateSyntheticAnnotation && element.uri == SchemaSymbols.URI_SCHEMAFORSCHEMA && hasNonSchemaAttributes(attributes)) { + if (fGenerateSyntheticAnnotation && fAnnotationDepth == -1 && + element.uri == SchemaSymbols.URI_SCHEMAFORSCHEMA && hasNonSchemaAttributes(element, attributes)) { schemaDOM.startElement(element, attributes, fLocator.getLineNumber(), @@ -374,11 +376,16 @@ * @param attributes * @return */ - private boolean hasNonSchemaAttributes(XMLAttributes attributes) { - for(int i = 0;i < attributes.getLength(); i++) { + private boolean hasNonSchemaAttributes(QName element, XMLAttributes attributes) { + final int length = attributes.getLength(); + for (int i = 0; i < length; ++i) { String uri = attributes.getURI(i); - if(uri != null && uri != SchemaSymbols.URI_SCHEMAFORSCHEMA && uri != SchemaSymbols.URI_XSI && uri != XMLSymbols.PREFIX_XMLNS && uri != XMLSymbols.PREFIX_XMLNS) + if (uri != null && uri != SchemaSymbols.URI_SCHEMAFORSCHEMA && + uri != NamespaceContext.XMLNS_URI && + !(uri == NamespaceContext.XML_URI && + attributes.getQName(i) == SchemaSymbols.ATT_XML_LANG && element.localpart == SchemaSymbols.ELT_SCHEMA)) { return true; + } } return false; }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]