neilg 2003/06/17 20:08:54 Modified: java/src/org/apache/xerces/impl/msg XMLSchemaMessages.properties java/src/org/apache/xerces/impl/xs/traversers XSDHandler.java XSDocumentInfo.java XSAttributeChecker.java Log: Fix 2 related bugs: (1) The contents of <include> and <import> elements were not inspected; (2) attributes of <schema> and <redefine> elements were not passed to the annotation traverser. Revision Changes Path 1.67 +3 -1 xml-xerces/java/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties Index: XMLSchemaMessages.properties =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties,v retrieving revision 1.66 retrieving revision 1.67 diff -u -r1.66 -r1.67 --- XMLSchemaMessages.properties 30 Apr 2003 20:24:49 -0000 1.66 +++ XMLSchemaMessages.properties 18 Jun 2003 03:08:54 -0000 1.67 @@ -132,11 +132,13 @@ src-element.4 = src-element.4: error. src-expredef = src-expredef: error. src-identity-constraint.1 = src-identity-constraint.1: a ''<selector>'' or a ''<field>'' element can contain at most one ''<annotation>'' in its content; identity constraint ''{0}'' violates this constraint. + src-import = src-import: An <import> element cannot contain a child of type ''{0}''. src-import.0 = src-import.0: Failed to read imported schema document ''{0}''. src-import.1.1 = src-import.1.1: The namespace attribute ''{0}'' of an <import> element information item must not be the same as the targetNamespace of the schema it exists in. src-import.2 = src-import.2: The root element of document ''{0}'' is not <xsd:schema>. src-import.3.1 = src-import.3.1: The namespace attribute ''{0}'' of an <import> element information item must be identical to the targetNamespace attribute ''{1}'' of the imported document. src-import.3.2 = src-import.3.2: There is no namespace attribute on the <import> element information item, so the imported document must have no targetNamespace attribute. + src-include = src-include: An <include> element cannot contain a child of type ''{0}''. src-include.0 = src-include.0: Failed to read included schema document ''{0}''. src-include.1 = src-include.1: The root element of document ''{0}'' is not <xsd:schema>. src-include.2.1 = src-include.2.1: the targetNamespace of the schema ''{1}'' must be identical to that of the including schema ''{0}''. 1.68 +58 -15 xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java Index: XSDHandler.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java,v retrieving revision 1.67 retrieving revision 1.68 diff -u -r1.67 -r1.68 --- XSDHandler.java 13 Jun 2003 22:34:16 -0000 1.67 +++ XSDHandler.java 18 Jun 2003 03:08:54 -0000 1.68 @@ -511,6 +511,7 @@ XSDocumentInfo currSchemaInfo = null; try { + // note that attributes are freed at end of traverseSchemas() currSchemaInfo = new XSDocumentInfo(schemaRoot, fAttributeChecker, fSymbolTable); } catch (XMLSchemaException se) { reportSchemaError(ELE_ERROR_CODES[referType], @@ -618,16 +619,30 @@ refType = XSDDescription.CONTEXT_IMPORT; // have to handle some validation here too! // call XSAttributeChecker to fill in attrs - Object[] includeAttrs = fAttributeChecker.checkAttributes(child, true, currSchemaInfo); - schemaHint = (String)includeAttrs[XSAttributeChecker.ATTIDX_SCHEMALOCATION]; - schemaNamespace = (String)includeAttrs[XSAttributeChecker.ATTIDX_NAMESPACE]; + Object[] importAttrs = fAttributeChecker.checkAttributes(child, true, currSchemaInfo); + schemaHint = (String)importAttrs[XSAttributeChecker.ATTIDX_SCHEMALOCATION]; + schemaNamespace = (String)importAttrs[XSAttributeChecker.ATTIDX_NAMESPACE]; if (schemaNamespace != null) schemaNamespace = fSymbolTable.addSymbol(schemaNamespace); // a document can't import another document with the same namespace if (schemaNamespace == currSchemaInfo.fTargetNamespace) { reportSchemaError("src-import.1.1", new Object [] {schemaNamespace}, child); } - fAttributeChecker.returnAttrArray(includeAttrs, currSchemaInfo); + + // check contents and process optional annotations + Element importChild = DOMUtil.getFirstChildElement(child); + if(importChild != null ) { + String importComponentType = DOMUtil.getLocalName(importChild); + if (importComponentType.equals(SchemaSymbols.ELT_ANNOTATION)) { + fElementTraverser.traverseAnnotationDecl(importChild, importAttrs, true, currSchemaInfo); + } else { + reportSchemaError("src-import", new Object [] {importComponentType}, importChild); + } + if(DOMUtil.getNextSiblingElement(importChild) != null) { + reportSchemaError("src-import", new Object [] {importComponentType}, importChild); + } + } + fAttributeChecker.returnAttrArray(importAttrs, currSchemaInfo); // if this namespace has been imported by this document, // ignore the <import> statement @@ -678,6 +693,35 @@ if (localName.equals(SchemaSymbols.ELT_REDEFINE)) { fRedefine2NSSupport.put(child, new SchemaNamespaceSupport(currSchemaInfo.fNamespaceSupport)); } + + // check annotations. Must do this here to avoid having to + // re-parse attributes later + if(localName.equals(SchemaSymbols.ELT_INCLUDE)) { + Element includeChild = DOMUtil.getFirstChildElement(child); + if(includeChild != null ) { + String includeComponentType = DOMUtil.getLocalName(includeChild); + if (includeComponentType.equals(SchemaSymbols.ELT_ANNOTATION)) { + fElementTraverser.traverseAnnotationDecl(includeChild, includeAttrs, true, currSchemaInfo); + } else { + reportSchemaError("src-include", new Object [] {includeComponentType}, includeChild); + } + if(DOMUtil.getNextSiblingElement(includeChild) != null) { + reportSchemaError("src-include", new Object [] {includeComponentType}, includeChild); + } + } + } + else { + for (Element redefinedChild = DOMUtil.getFirstChildElement(child); + redefinedChild != null; + redefinedChild = DOMUtil.getNextSiblingElement(redefinedChild)) { + String redefinedComponentType = DOMUtil.getLocalName(redefinedChild); + if (redefinedComponentType.equals(SchemaSymbols.ELT_ANNOTATION)) { + fElementTraverser.traverseAnnotationDecl(redefinedChild, includeAttrs, true, currSchemaInfo); + DOMUtil.setHidden(redefinedChild); + } + // catch all other content errors later + } + } fAttributeChecker.returnAttrArray(includeAttrs, currSchemaInfo); // schemaLocation is required on <include> and <redefine> if (schemaHint == null) { @@ -892,14 +936,14 @@ schemasToProcess.push(fRoot); while (!schemasToProcess.empty()) { XSDocumentInfo currSchemaDoc = - (XSDocumentInfo)schemasToProcess.pop(); + (XSDocumentInfo)schemasToProcess.pop(); Document currDoc = currSchemaDoc.fSchemaDoc; SchemaGrammar currSG = fGrammarBucket.getGrammar(currSchemaDoc.fTargetNamespace); if (DOMUtil.isHidden(currDoc)) { // must have processed this already! continue; } - Element currRoot = DOMUtil.getRoot(currDoc); + Element currRoot = DOMUtil.getRoot(currDoc); // traverse this schema's global decls for (Element globalComp = @@ -930,11 +974,11 @@ else if (redefinedComponentType.equals(SchemaSymbols.ELT_SIMPLETYPE)) { fSimpleTypeTraverser.traverseGlobal(redefinedComp, currSchemaDoc, currSG); } - else if (redefinedComponentType.equals(SchemaSymbols.ELT_ANNOTATION)) { - // REVISIT: according to 3.13.2 the PSVI needs the parent's attributes; - // thus this should be done in buildGlobalNameRegistries not here... - fElementTraverser.traverseAnnotationDecl(redefinedComp, null, true, currSchemaDoc); - } + // annotations will have been processed already; this is now + // unnecessary + //else if (redefinedComponentType.equals(SchemaSymbols.ELT_ANNOTATION)) { + // fElementTraverser.traverseAnnotationDecl(redefinedComp, null, true, currSchemaDoc); + //} else { reportSchemaError("src-redefine", new Object [] {componentType}, redefinedComp); } @@ -963,9 +1007,7 @@ fSimpleTypeTraverser.traverseGlobal(globalComp, currSchemaDoc, currSG); } else if (componentType.equals(SchemaSymbols.ELT_ANNOTATION)) { - // REVISIT: according to 3.13.2 the PSVI needs the parent's attributes; - // thus this should be done in buildGlobalNameRegistries not here... - fElementTraverser.traverseAnnotationDecl(globalComp, null, true, currSchemaDoc); + fElementTraverser.traverseAnnotationDecl(globalComp, currSchemaDoc.getSchemaAttrs(), true, currSchemaDoc); } else { reportSchemaError("sch-props-correct.1", new Object [] {DOMUtil.getLocalName(globalComp)}, globalComp); @@ -973,6 +1015,7 @@ } // end for // now we're done with this one! + currSchemaDoc.returnSchemaAttrs(); DOMUtil.setHidden(currDoc); // now add the schemas this guy depends on Vector currSchemaDepends = (Vector)fDependencyMap.get(currSchemaDoc); 1.16 +35 -10 xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDocumentInfo.java Index: XSDocumentInfo.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDocumentInfo.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- XSDocumentInfo.java 8 May 2003 20:11:57 -0000 1.15 +++ XSDocumentInfo.java 18 Jun 2003 03:08:54 -0000 1.16 @@ -2,7 +2,7 @@ * The Apache Software License, Version 1.1 * * - * Copyright (c) 1999-2002 The Apache Software Foundation. All rights + * Copyright (c) 1999-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -112,6 +112,16 @@ SymbolTable fSymbolTable = null; + // attribute checker to which we'll return the attributes + // once we've been told that we're done with them + protected XSAttributeChecker fAttrChecker; + + // array of objects on the schema's root element. This is null + // once returnSchemaAttrs has been called. + protected Object [] fSchemaAttrs; + + // note that the caller must ensure to call returnSchemaAttrs() + // to avoid memory leaks! XSDocumentInfo (Document schemaDoc, XSAttributeChecker attrChecker, SymbolTable symbolTable) throws XMLSchemaException { fSchemaDoc = schemaDoc; @@ -120,26 +130,27 @@ fIsChameleonSchema = false; fSymbolTable = symbolTable; + fAttrChecker = attrChecker; if(schemaDoc != null) { Element root = DOMUtil.getRoot(schemaDoc); - Object[] schemaAttrs = attrChecker.checkAttributes(root, true, this); + fSchemaAttrs = attrChecker.checkAttributes(root, true, this); // schemaAttrs == null means it's not an <xsd:schema> element // throw an exception, but we don't know the document systemId, // so we leave that to the caller. - if (schemaAttrs == null) { + if (fSchemaAttrs == null) { throw new XMLSchemaException(null, null); } fAreLocalAttributesQualified = - ((XInt)schemaAttrs[XSAttributeChecker.ATTIDX_AFORMDEFAULT]).intValue() == SchemaSymbols.FORM_QUALIFIED; + ((XInt)fSchemaAttrs[XSAttributeChecker.ATTIDX_AFORMDEFAULT]).intValue() == SchemaSymbols.FORM_QUALIFIED; fAreLocalElementsQualified = - ((XInt)schemaAttrs[XSAttributeChecker.ATTIDX_EFORMDEFAULT]).intValue() == SchemaSymbols.FORM_QUALIFIED; + ((XInt)fSchemaAttrs[XSAttributeChecker.ATTIDX_EFORMDEFAULT]).intValue() == SchemaSymbols.FORM_QUALIFIED; fBlockDefault = - ((XInt)schemaAttrs[XSAttributeChecker.ATTIDX_BLOCKDEFAULT]).shortValue(); + ((XInt)fSchemaAttrs[XSAttributeChecker.ATTIDX_BLOCKDEFAULT]).shortValue(); fFinalDefault = - ((XInt)schemaAttrs[XSAttributeChecker.ATTIDX_FINALDEFAULT]).shortValue(); + ((XInt)fSchemaAttrs[XSAttributeChecker.ATTIDX_FINALDEFAULT]).shortValue(); fTargetNamespace = - (String)schemaAttrs[XSAttributeChecker.ATTIDX_TARGETNAMESPACE]; + (String)fSchemaAttrs[XSAttributeChecker.ATTIDX_TARGETNAMESPACE]; if (fTargetNamespace != null) fTargetNamespace = symbolTable.addSymbol(fTargetNamespace); @@ -150,7 +161,9 @@ fValidationContext.setSymbolTable(symbolTable); // pass null as the schema document, so that the namespace // context is not popped. - attrChecker.returnAttrArray(schemaAttrs, null); + + // don't return the attribute array yet! + //attrChecker.returnAttrArray(schemaAttrs, null); } } @@ -196,6 +209,18 @@ return false; fReportedTNS.addElement(uri); return true; + } + + // return the attributes on the schema element itself: + Object [] getSchemaAttrs () { + return fSchemaAttrs; + } + + // deallocate the storage set aside for the schema element's + // attributes + void returnSchemaAttrs () { + fAttrChecker.returnAttrArray (fSchemaAttrs, null); + fSchemaAttrs = null; } } // XSDocumentInfo 1.24 +34 -18 xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSAttributeChecker.java Index: XSAttributeChecker.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSAttributeChecker.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- XSAttributeChecker.java 8 May 2003 20:11:57 -0000 1.23 +++ XSAttributeChecker.java 18 Jun 2003 03:08:54 -0000 1.24 @@ -2,7 +2,7 @@ * The Apache Software License, Version 1.1 * * - * Copyright (c) 2001, 2002 The Apache Software Foundation. All rights + * Copyright (c) 2001-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -136,7 +136,8 @@ public static final int ATTIDX_NAME = ATTIDX_COUNT++; public static final int ATTIDX_NAMESPACE = ATTIDX_COUNT++; public static final int ATTIDX_NAMESPACE_LIST = ATTIDX_COUNT++; - public static final int ATTIDX_NILLABLE = ATTIDX_COUNT++; + public static final int ATTIDX_NILLABLE = ATTIDX_COUNT++; + public static final int ATTIDX_NONSCHEMA = ATTIDX_COUNT++; public static final int ATTIDX_PROCESSCONTENTS = ATTIDX_COUNT++; public static final int ATTIDX_PUBLIC = ATTIDX_COUNT++; public static final int ATTIDX_REF = ATTIDX_COUNT++; @@ -1108,9 +1109,14 @@ String attrVal = DOMUtil.getValue(sattr); // skip anything starts with x/X m/M l/L - // simply put their values in the return hashtable + // add this to the list of "non-schema" attributes if (attrName.toLowerCase(Locale.ENGLISH).startsWith("xml")) { - //attrValues.put(attrName, attrVal); + if(attrValues[ATTIDX_NONSCHEMA] == null) { + // these are usually small + attrValues[ATTIDX_NONSCHEMA] = new Vector(4,2); + } + ((Vector)attrValues[ATTIDX_NONSCHEMA]).addElement(attrName); + ((Vector)attrValues[ATTIDX_NONSCHEMA]).addElement(attrVal); //otherValues.put(attrName, attrVal); continue; } @@ -1126,23 +1132,30 @@ reportSchemaError ("s4s-att-not-allowed", new Object[] {elName, attrName}, element); } else { + if(attrValues[ATTIDX_NONSCHEMA] == null) { + // these are usually small + attrValues[ATTIDX_NONSCHEMA] = new Vector(4,2); + } + ((Vector)attrValues[ATTIDX_NONSCHEMA]).addElement(attrName); + ((Vector)attrValues[ATTIDX_NONSCHEMA]).addElement(attrVal); // for attributes from other namespace // store them in a list, and TRY to validate them after // schema traversal (because it's "lax") //otherValues.put(attrName, attrVal); - String attrRName = attrURI + "," + attrName; - Vector values = (Vector)fNonSchemaAttrs.get(attrRName); - if (values == null) { - values = new Vector(); - values.addElement(attrName); - values.addElement(elName); - values.addElement(attrVal); - fNonSchemaAttrs.put(attrRName, values); - } - else { - values.addElement(elName); - values.addElement(attrVal); - } + // REVISIT: actually use this some day... + // String attrRName = attrURI + "," + attrName; + // Vector values = (Vector)fNonSchemaAttrs.get(attrRName); + // if (values == null) { + // values = new Vector(); + // values.addElement(attrName); + // values.addElement(elName); + // values.addElement(attrVal); + // fNonSchemaAttrs.put(attrRName, values); + // } + // else { + // values.addElement(elName); + // values.addElement(attrVal); + // } } continue; } @@ -1707,6 +1720,9 @@ // mark this array as returned attrArray[ATTIDX_ISRETURNED] = Boolean.TRUE; + // better clear nonschema vector + if(attrArray[ATTIDX_NONSCHEMA] != null) + ((Vector)attrArray[ATTIDX_NONSCHEMA]).clear(); // and put it into the pool fArrayPool[--fPoolPos] = attrArray; }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]