You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by el...@apache.org on 2001/03/07 23:22:02 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/validators/schema SchemaGrammar.java TraverseSchema.java
elena 01/03/07 14:22:01
Modified: java/src/org/apache/xerces/validators/common
XMLValidator.java
java/src/org/apache/xerces/validators/schema
SchemaGrammar.java TraverseSchema.java
Log:
More changes to <notation> decl traversal and validation.
Namespaces have to be resolved in 2 cases:
1) when <enumeration> of notation is provided
2) just before validating content (in XMLValidator)
Revision Changes Path
1.126 +53 -3 xml-xerces/java/src/org/apache/xerces/validators/common/XMLValidator.java
Index: XMLValidator.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/common/XMLValidator.java,v
retrieving revision 1.125
retrieving revision 1.126
diff -u -r1.125 -r1.126
--- XMLValidator.java 2001/02/27 22:51:43 1.125
+++ XMLValidator.java 2001/03/07 22:21:49 1.126
@@ -117,11 +117,11 @@
import org.apache.xerces.validators.datatype.IDREFDatatypeValidator;
import org.apache.xerces.validators.datatype.IDDatatypeValidator;
import org.apache.xerces.validators.datatype.ENTITYDatatypeValidator;
-
+import org.apache.xerces.validators.datatype.NOTATIONDatatypeValidator;
/**
* This class is the super all-in-one validator used by the parser.
*
- * @version $Id: XMLValidator.java,v 1.125 2001/02/27 22:51:43 neilg Exp $
+ * @version $Id: XMLValidator.java,v 1.126 2001/03/07 22:21:49 elena Exp $
*/
public final class XMLValidator
implements DefaultEntityHandler.EventHandler,
@@ -2720,6 +2720,43 @@
}
+ /*
+ * for <notation> must resolve values "b:myNotation"
+ *
+ * @param value string value of element or attribute
+ * @return
+ * @exception Exception
+ */
+ private String bindNotationURI (String value) throws Exception{
+ int colonP = value.indexOf(":");
+ String prefix = "";
+ String localpart = value;
+ if (colonP > -1) {
+ prefix = value.substring(0,colonP);
+ localpart = value.substring(colonP+1);
+ }
+
+ String uri = "";
+ int uriIndex = StringPool.EMPTY_STRING;
+ if (fNamespacesScope != null) {
+ //if prefix.equals("") it would bing to xmlns URI
+ uriIndex = fNamespacesScope.getNamespaceForPrefix(fStringPool.addSymbol(prefix));
+ if (uriIndex > 0) {
+ return fStringPool.toString(uriIndex)+":"+localpart;
+ } else if (fGrammarNameSpaceIndex!=-1){
+ // REVISIT: try binding to current namespace
+ // trying to solve the case:
+ // <v01:root xmlns:xsi ="http://www.w3.org/2000/10/XMLSchema-instance"
+ // xmlns:my ="http://www.schemaTest.org/my"
+ // might not work in all cases (need clarification from schema?)
+ return fStringPool.toString( fGrammarNameSpaceIndex)+":"+localpart;
+ }
+
+
+ }
+ return value;
+ }
+
static class Resolver implements EntityResolver {
//
@@ -3308,6 +3345,10 @@
else { // normalize
int normalizedValue = fStringPool.addString(value);
attrList.setAttValue(index,normalizedValue );
+ if (attDV instanceof NOTATIONDatatypeValidator
+ && value !=null) {
+ value=bindNotationURI(value);
+ }
attDV.validate(value, null );
}
}
@@ -3372,6 +3413,10 @@
else { // normalize
int normalizedValue = fStringPool.addString(value);
attrList.setAttValue(index,normalizedValue );
+ if (fTempAttDecl.datatypeValidator instanceof NOTATIONDatatypeValidator
+ && value !=null) {
+ value=bindNotationURI(value);
+ }
fTempAttDecl.datatypeValidator.validate(value, null );
}
}
@@ -3848,7 +3893,12 @@
"but no datatypevalidator was found, element "+fTempElementDecl.name
+",locapart: "+fStringPool.toString(fTempElementDecl.name.localpart));
} else {
- fCurrentDV.validate(fDatatypeBuffer.toString(), null);
+ String value =fDatatypeBuffer.toString();
+ if (fCurrentDV instanceof NOTATIONDatatypeValidator
+ && value !=null) {
+ value=bindNotationURI(value);
+ }
+ fCurrentDV.validate(value, null);
}
} catch (InvalidDatatypeValueException idve) {
1.16 +2 -1 xml-xerces/java/src/org/apache/xerces/validators/schema/SchemaGrammar.java
Index: SchemaGrammar.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/schema/SchemaGrammar.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- SchemaGrammar.java 2001/02/01 09:58:39 1.15
+++ SchemaGrammar.java 2001/03/07 22:21:55 1.16
@@ -60,7 +60,7 @@
* @author Eric Ye
*
* @see
- * @version $Id: SchemaGrammar.java,v 1.15 2001/02/01 09:58:39 andyc Exp $
+ * @version $Id: SchemaGrammar.java,v 1.16 2001/03/07 22:21:55 elena Exp $
*/
package org.apache.xerces.validators.schema;
@@ -124,6 +124,7 @@
private DatatypeValidatorFactoryImpl fDatatypeRegistry = null;
Hashtable topLevelGroupDecls = new Hashtable();
+ Hashtable topLevelNotationDecls = new Hashtable();
Hashtable topLevelAttrDecls = new Hashtable();
Hashtable topLevelAttrGrpDecls = new Hashtable();
1.114 +168 -98 xml-xerces/java/src/org/apache/xerces/validators/schema/TraverseSchema.java
Index: TraverseSchema.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/schema/TraverseSchema.java,v
retrieving revision 1.113
retrieving revision 1.114
diff -u -r1.113 -r1.114
--- TraverseSchema.java 2001/03/06 20:25:57 1.113
+++ TraverseSchema.java 2001/03/07 22:21:57 1.114
@@ -125,7 +125,7 @@
*
* @see org.apache.xerces.validators.common.Grammar
*
- * @version $Id: TraverseSchema.java,v 1.113 2001/03/06 20:25:57 elena Exp $
+ * @version $Id: TraverseSchema.java,v 1.114 2001/03/07 22:21:57 elena Exp $
*/
public class TraverseSchema implements
NamespacesScope.NamespacesHandler{
@@ -141,21 +141,21 @@
};
//debuggin
- private static boolean DEBUGGING = false;
+ private static final boolean DEBUGGING = false;
/** Compile to true to debug identity constraints. */
- private static boolean DEBUG_IDENTITY_CONSTRAINTS = false;
+ private static final boolean DEBUG_IDENTITY_CONSTRAINTS = false;
/**
* Compile to true to debug datatype validator lookup for
* identity constraint support.
*/
- private static boolean DEBUG_IC_DATATYPES = false;
+ private static final boolean DEBUG_IC_DATATYPES = false;
- //CR Implementation
- private static boolean DEBUG_UNION = false;
- private static boolean CR_IMPL = true;
- //private data members
+ //CR Implementation
+ private static final boolean DEBUG_UNION = false;
+ private static final boolean CR_IMPL = true;
+ //private data members
private XMLErrorReporter fErrorReporter = null;
@@ -178,7 +178,7 @@
private Hashtable fGroupNameRegistry = new Hashtable();
// stores <notation> decl
- private static Hashtable fNotationRegistry = new Hashtable();
+ private Hashtable fNotationRegistry = new Hashtable();
private Vector fIncludeLocations = new Vector();
private Vector fImportLocations = new Vector();
@@ -500,7 +500,9 @@
fSchemaGrammar.topLevelAttrDecls.put(compName, child);
} else if ( name.equals(SchemaSymbols.ELT_GROUP) ) {
fSchemaGrammar.topLevelGroupDecls.put(compName, child);
- }
+ } else if ( name.equals(SchemaSymbols.ELT_NOTATION) ) {
+ fSchemaGrammar.topLevelNotationDecls.put(compName, child);
+ }
} // for each child node
}
@@ -1127,51 +1129,52 @@
return result;
} // changeRedefineGroup
- // This simple function looks for the first occurrence of an eltLocalname
- // schema information item and appropriately changes the value of
- // its name or type attribute from oldName to newName. We
- // must then traverse this newly-named entity, since our redefine element now depends on it.
- // Root contains the root of the schema being operated upon.
- private void fixRedefinedSchema(String eltLocalname, String oldName, String newName, Element schemaToRedefine) throws Exception {
+ // This simple function looks for the first occurrence of an eltLocalname
+ // schema information item and appropriately changes the value of
+ // its name or type attribute from oldName to newName. We
+ // must then traverse this newly-named entity, since our redefine element now depends on it.
+ // Root contains the root of the schema being operated upon.
+ private void fixRedefinedSchema(String eltLocalname, String oldName, String newName, Element schemaToRedefine) throws Exception {
- boolean foundIt = false;
- for (Element child = XUtil.getFirstChildElement(schemaToRedefine);
- child != null;
- child = XUtil.getNextSiblingElement(child)) {
+ boolean foundIt = false;
+ for (Element child = XUtil.getFirstChildElement(schemaToRedefine);
+ child != null;
+ child = XUtil.getNextSiblingElement(child)) {
String name = child.getLocalName();
if (name.equals(eltLocalname) ) {
- if (name.equals(SchemaSymbols.ELT_GROUP) ||
- name.equals(SchemaSymbols.ELT_ATTRIBUTEGROUP) ||
- name.equals(SchemaSymbols.ELT_SIMPLETYPE) ||
- name.equals(SchemaSymbols.ELT_COMPLEXTYPE)) {
- String infoItemName = child.getAttribute( SchemaSymbols.ATT_NAME );
- if(!infoItemName.equals(oldName))
- continue;
- else { // found it!
- foundIt = true;
- child.setAttribute( SchemaSymbols.ATT_NAME, newName );
- // note that we try and traverse these once again when
- // we include this schema; howevre, thanks to hashes and
- // such, this won't affect anything and won't be dramatically less efficient.
- if (name.equals(SchemaSymbols.ELT_GROUP))
- traverseGroupDecl(child);
- else if (name.equals(SchemaSymbols.ELT_ATTRIBUTEGROUP))
- traverseAttributeGroupDecl(child, null, null);
- else if (name.equals(SchemaSymbols.ELT_SIMPLETYPE))
- traverseSimpleTypeDecl(child);
- else if (name.equals(SchemaSymbols.ELT_COMPLEXTYPE))
- traverseComplexTypeDecl(child);
- break;
- }
- }
- }
- } //for
- if(!foundIt) {
+ if (name.equals(SchemaSymbols.ELT_GROUP) ||
+ name.equals(SchemaSymbols.ELT_ATTRIBUTEGROUP) ||
+ name.equals(SchemaSymbols.ELT_SIMPLETYPE) ||
+ name.equals(SchemaSymbols.ELT_COMPLEXTYPE)) {
+ String infoItemName = child.getAttribute( SchemaSymbols.ATT_NAME );
+ if(!infoItemName.equals(oldName))
+ continue;
+ else { // found it!
+ foundIt = true;
+ child.setAttribute( SchemaSymbols.ATT_NAME, newName );
+ // note that we try and traverse these once again when
+ // we include this schema; howevre, thanks to hashes and
+ // such, this won't affect anything and won't be dramatically less efficient.
+ if (name.equals(SchemaSymbols.ELT_GROUP))
+ traverseGroupDecl(child);
+ else if (name.equals(SchemaSymbols.ELT_ATTRIBUTEGROUP))
+ traverseAttributeGroupDecl(child, null, null);
+ else if (name.equals(SchemaSymbols.ELT_SIMPLETYPE))
+ traverseSimpleTypeDecl(child);
+ else if (name.equals(SchemaSymbols.ELT_COMPLEXTYPE))
+ traverseComplexTypeDecl(child);
+ break;
+ }
+ }
+ }
+ } //for
+ if(!foundIt) {
fRedefineSucceeded = false;
- // REVISIT: localize
- reportGenericSchemaError("could not find a declaration in the schema to be redefined corresponding to " + oldName);
+ // REVISIT: localize
+ reportGenericSchemaError("could not find a declaration in the schema to be redefined corresponding to " + oldName);
}
- } // end fixRedefinedSchema
+ } // end fixRedefinedSchema
+
private void traverseImport(Element importDecl) throws Exception {
String location = importDecl.getAttribute(SchemaSymbols.ATT_SCHEMALOCATION);
@@ -1347,12 +1350,19 @@
private int traverseSimpleTypeDecl( Element simpleTypeDecl ) throws Exception {
//REVISIT: remove all DEBUG_UNION.
- if (DEBUG_UNION) {
- System.out.println("----------->CR traverseSimpleType()");
- }
-
- //REVISIT: are we checking for attributes and other definitions that should not be there?
+
String nameProperty = simpleTypeDecl.getAttribute( SchemaSymbols.ATT_NAME );
+
+ String qualifiedName = nameProperty;
+ if (fTargetNSURIString.length () != 0) {
+ qualifiedName = fTargetNSURIString+","+nameProperty;
+ }
+ //check if we have already traversed the same simpleType decl
+ if (fDatatypeRegistry.getDatatypeValidator(qualifiedName)!=null) {
+ return fStringPool.addSymbol(qualifiedName);
+ }
+
+
boolean list = false;
boolean union = false;
boolean restriction = false;
@@ -1364,6 +1374,8 @@
else
newSimpleTypeName = fStringPool.addSymbol( nameProperty );
+
+
//annotation?,(list|restriction|union)
Element content = XUtil.getFirstChildElement(simpleTypeDecl);
content = checkContent(simpleTypeDecl, content, false);
@@ -1515,14 +1527,13 @@
dTValidators.addElement((DatatypeValidator)baseValidator);
}
}
-
if ( baseValidator == null || typeNameIndex == -1) {
reportSchemaError(SchemaMessageProvider.UnknownBaseDatatype,
new Object [] { simpleTypeDecl.getAttribute( SchemaSymbols.ATT_BASE ),
simpleTypeDecl.getAttribute(SchemaSymbols.ATT_NAME)});
return (-1);
}
- content = XUtil.getNextSiblingElement( content );
+ content = XUtil.getNextSiblingElement( content );
}
} // end - traverse Union
@@ -1552,26 +1563,24 @@
prefix = enumVal.substring(0,colonptr);
localpart = enumVal.substring(colonptr+1);
}
- int localpartIndex = fStringPool.addSymbol(localpart);
- String uriStr = resolvePrefixToURI(prefix);
- String fullName=uriStr + "," + localpart;
- localName = (String)fNotationRegistry.get(fullName);
- if(localName == null ){
- Element notationDecl = getTopLevelComponentByName(SchemaSymbols.ELT_NOTATION,localpart);
- if (notationDecl == null) {
- reportGenericSchemaError("Notation " + localpart + " not found in the Schema");
- }
- else {
- localName=traverseNotationDecl(notationDecl);
- }
+ String uriStr = (!prefix.equals(""))?resolvePrefixToURI(prefix):fTargetNSURIString;
+ qualifiedName=uriStr + ":" + localpart;
+ localName = (String)fNotationRegistry.get(qualifiedName);
+ if(localName == null){
+ localName = traverseNotationFromAnotherSchema( localpart, uriStr);
+ if (localName == null) {
+ reportGenericSchemaError("Notation '" + localpart +
+ "' not found in the grammar "+ uriStr);
+
+ }
}
- //REVISIT: make sure QNAME of notation gets validated correctly
- if (DEBUGGING) {
- System.out.println("[notation decl] fullName: = " + fullName +"; enum value: =" +enumVal);
- }
-
+ if (DEBUGGING) {
+ System.out.println("[notation decl] fullName: = " + qualifiedName);
+ System.out.println("[notation decl] enum value: =" +enumVal);
+ }
+ enumVal=qualifiedName;
}
- enumData.addElement(enumVal);
+ enumData.addElement(enumVal);
checkContent(simpleTypeDecl, XUtil.getFirstChildElement( content ), true);
}
else if (facet.equals(SchemaSymbols.ELT_ANNOTATION)) {
@@ -1624,27 +1633,28 @@
//REVISIT: should we return?
}
}
+
+ // create & register validator for "generated" type if it doesn't exist
- // create & register validator for "generated" type if it doesn't exist
- String nameOfType = fStringPool.toString( newSimpleTypeName);
+ qualifiedName = fStringPool.toString(newSimpleTypeName);
if (fTargetNSURIString.length () != 0) {
- nameOfType = fTargetNSURIString+","+nameOfType;
+ qualifiedName = fTargetNSURIString+","+qualifiedName;
}
try {
DatatypeValidator newValidator =
- fDatatypeRegistry.getDatatypeValidator( nameOfType );
+ fDatatypeRegistry.getDatatypeValidator( qualifiedName );
if( newValidator == null ) { // not previously registered
if (list) {
- fDatatypeRegistry.createDatatypeValidator( nameOfType, baseValidator,
+ fDatatypeRegistry.createDatatypeValidator( qualifiedName, baseValidator,
facetData,true);
}
else if (restriction) {
- fDatatypeRegistry.createDatatypeValidator( nameOfType, baseValidator,
+ fDatatypeRegistry.createDatatypeValidator( qualifiedName, baseValidator,
facetData,false);
}
else { //union
- fDatatypeRegistry.createDatatypeValidator( nameOfType, dTValidators);
+ fDatatypeRegistry.createDatatypeValidator( qualifiedName, dTValidators);
}
}
@@ -1652,7 +1662,7 @@
} catch (Exception e) {
reportSchemaError(SchemaMessageProvider.DatatypeError,new Object [] { e.getMessage() });
}
- return fStringPool.addSymbol(nameOfType);
+ return fStringPool.addSymbol(qualifiedName);
}
@@ -4929,13 +4939,20 @@
/**
- * Notation decl
- */
+ * Traverses notation declaration
+ * and saves it in a registry.
+ * Notations are stored in registry with the following
+ * key: "uri:localname"
+ *
+ * @param notation child <notation>
+ * @return local name of notation
+ * @exception Exception
+ */
private String traverseNotationDecl( Element notation ) throws Exception {
String name = notation.getAttribute(SchemaSymbols.ATT_NAME);
String qualifiedName =name;
if (fTargetNSURIString.length () != 0) {
- qualifiedName = fTargetNSURIString+","+name;
+ qualifiedName = fTargetNSURIString+":"+name;
}
if (fNotationRegistry.get(qualifiedName)!=null) {
return name;
@@ -4951,14 +4968,68 @@
reportGenericSchemaError("<notation> declaration does not have a name");
}
+
+ fNotationRegistry.put(qualifiedName, name);
+
+ //we don't really care if something inside <notation> is wrong..
+ checkContent( notation, XUtil.getFirstChildElement(notation), true );
- fNotationRegistry.put(qualifiedName, name);
//REVISIT: wait for DOM L3 APIs to pass info to application
//REVISIT: SAX2 does not support notations. API should be changed.
return name;
}
+
+ /**
+ * This methods will traverse notation from current schema,
+ * as well as from included or imported schemas
+ *
+ * @param notationName
+ * localName of notation
+ * @param uriStr uriStr for schema grammar
+ * @return return local name for Notation (if found), otherwise
+ * return empty string;
+ * @exception Exception
+ */
+ private String traverseNotationFromAnotherSchema( String notationName , String uriStr ) throws Exception {
+
+ SchemaGrammar aGrammar = (SchemaGrammar) fGrammarResolver.getGrammar(uriStr);
+ if (uriStr == null || aGrammar==null ||! (aGrammar instanceof SchemaGrammar) ) {
+ // REVISIT: Localize
+ reportGenericSchemaError("!!Schema not found in #traverseNotationDeclFromAnotherSchema, "+
+ "schema uri: " + uriStr
+ +", groupName: " + notationName);
+ return "";
+ }
+
+
+ String savedNSURIString = fTargetNSURIString;
+ fTargetNSURIString = fStringPool.toString(fStringPool.addSymbol(aGrammar.getTargetNamespaceURI()));
+ if (DEBUGGING) {
+ System.out.println("[traverseFromAnotherSchema]: " + fTargetNSURIString);
+ }
+
+ String qualifiedName = fTargetNSURIString + ":" + notationName;
+ String localName = (String)fNotationRegistry.get(qualifiedName);
+ if(localName != null ) // we've already traversed this notation
+ return localName;
+ //notation decl has not been traversed yet
+ Element notationDecl = (Element) aGrammar.topLevelNotationDecls.get((Object)notationName);
+ if (notationDecl == null) {
+ // REVISIT: Localize
+ reportGenericSchemaError( "no notation named \"" + notationName
+ + "\" was defined in schema : " + uriStr);
+ return "";
+ }
+
+ localName = traverseNotationDecl(notationDecl);
+ fTargetNSURIString = savedNSURIString;
+ return localName;
+
+ } // end of method traverseNotationFromAnotherSchema
+
+
/**
* Traverse Group Declaration.
*
@@ -5085,19 +5156,18 @@
fTargetNSURI = fStringPool.addSymbol(aGrammar.getTargetNamespaceURI());
fNamespacesScope = aGrammar.getNamespacesScope();
- Element child = checkContent( groupDecl, XUtil.getFirstChildElement(groupDecl), true );
+ Element child = checkContent( groupDecl, XUtil.getFirstChildElement(groupDecl), true );
- String qualifiedGroupName = fTargetNSURIString + "," + groupName;
- Object contentSpecHolder = fGroupNameRegistry.get(qualifiedGroupName);
- if(contentSpecHolder != null ) // we've already traversed this group
- return ((Integer)contentSpecHolder).intValue();
+ String qualifiedGroupName = fTargetNSURIString + "," + groupName;
+ Object contentSpecHolder = fGroupNameRegistry.get(qualifiedGroupName);
+ if(contentSpecHolder != null ) // we've already traversed this group
+ return ((Integer)contentSpecHolder).intValue();
// if we're here then we're traversing a top-level group that we've never seen before.
int index = -2;
boolean illegalChild = false;
- String childName =
- (child != null) ? child.getLocalName() : "";
+ String childName = (child != null) ? child.getLocalName() : "";
if (childName.equals(SchemaSymbols.ELT_ALL)) {
index = traverseAll(child);
}
@@ -5116,10 +5186,10 @@
index = expandContentModel( index, child);
}
- contentSpecHolder = new Integer(index);
- fGroupNameRegistry.put(qualifiedGroupName, contentSpecHolder);
- fNamespacesScope = saveNSMapping;
- fTargetNSURI = saveTargetNSUri;
+ contentSpecHolder = new Integer(index);
+ fGroupNameRegistry.put(qualifiedGroupName, contentSpecHolder);
+ fNamespacesScope = saveNSMapping;
+ fTargetNSURI = saveTargetNSUri;
return index;