You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by sa...@apache.org on 2001/10/22 18:58:15 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/impl/v2/new_datatypes XSSimpleTypeDecl.java
sandygao 01/10/22 09:58:15
Modified: java/src/org/apache/xerces/impl/v2 SchemaSymbols.java
SchemaValidator.java XSAttributeChecker.java
XSDHandler.java XSDSimpleTypeTraverser.java
XSDocumentInfo.java XSGrammarResolver.java
java/src/org/apache/xerces/impl/v2/new_datatypes
XSSimpleTypeDecl.java
Log:
A revisit of empty string "" vs. null.
Make sure that we use "" for prefixes, and null for uris.
And EMPTY_STRING is now declared in SchemaSymbols.
SchemaHandler has its own EMPTY_STRING, which is added into the current symbol table. This is used solely for empty prefix.
Revision Changes Path
1.19 +4 -2 xml-xerces/java/src/org/apache/xerces/impl/v2/SchemaSymbols.java
Index: SchemaSymbols.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/SchemaSymbols.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- SchemaSymbols.java 2001/10/17 20:31:55 1.18
+++ SchemaSymbols.java 2001/10/22 16:58:14 1.19
@@ -63,10 +63,12 @@
* Collection of symbols used to parse a Schema Grammar.
*
* @author jeffrey rodriguez
- * @version $Id: SchemaSymbols.java,v 1.18 2001/10/17 20:31:55 elena Exp $
+ * @version $Id: SchemaSymbols.java,v 1.19 2001/10/22 16:58:14 sandygao Exp $
*/
public final class SchemaSymbols {
+ public static final String EMPTY_STRING = "";
+
// strings that's not added to the schema symbol table, because they
// are not symbols in the schema document.
// the validator can choose to add them by itself.
@@ -75,7 +77,7 @@
// symbol table that comes with the parser
// xmlns attributes
- public static final String O_XMLNS = "xmlns";
+ public static final String O_XMLNS = "xmlns";
// xsi attributes: in validator
public static final String URI_XSI = "http://www.w3.org/2001/XMLSchema-instance";
public static final String OXSI_SCHEMALOCATION = "schemaLocation";
1.37 +3 -3 xml-xerces/java/src/org/apache/xerces/impl/v2/SchemaValidator.java
Index: SchemaValidator.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/SchemaValidator.java,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- SchemaValidator.java 2001/10/22 13:35:28 1.36
+++ SchemaValidator.java 2001/10/22 16:58:14 1.37
@@ -115,7 +115,7 @@
* @author Andy Clark, IBM
* @author Jeffrey Rodriguez IBM
*
- * @version $Id: SchemaValidator.java,v 1.36 2001/10/22 13:35:28 sandygao Exp $
+ * @version $Id: SchemaValidator.java,v 1.37 2001/10/22 16:58:14 sandygao Exp $
*/
public class SchemaValidator
implements XMLComponent, XMLDocumentFilter,
@@ -1073,8 +1073,8 @@
}
}
if (nsLocation != null) {
- if (fGrammarResolver.getGrammar(fSchemaHandler.EMPTY_STRING) == null)
- fSchemaHandler.parseSchema(fSchemaHandler.EMPTY_STRING, nsLocation);
+ if (fGrammarResolver.getGrammar(null) == null)
+ fSchemaHandler.parseSchema(null, nsLocation);
}
// get the element decl for this element
1.32 +2 -2 xml-xerces/java/src/org/apache/xerces/impl/v2/XSAttributeChecker.java
Index: XSAttributeChecker.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/XSAttributeChecker.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- XSAttributeChecker.java 2001/10/19 18:22:00 1.31
+++ XSAttributeChecker.java 2001/10/22 16:58:15 1.32
@@ -89,7 +89,7 @@
* - use symbol table instead of many hashtables
*
* @author Sandy Gao, IBM
- * @version $Id: XSAttributeChecker.java,v 1.31 2001/10/19 18:22:00 sandygao Exp $
+ * @version $Id: XSAttributeChecker.java,v 1.32 2001/10/22 16:58:15 sandygao Exp $
*/
public class XSAttributeChecker {
@@ -1332,7 +1332,7 @@
wildcard.fType = XSWildcardDecl.WILDCARD_OTHER;
wildcard.fNamespaceList = new String[2];
wildcard.fNamespaceList[0] = schemaDoc.fTargetNamespace;
- wildcard.fNamespaceList[1] = fSchemaHandler.EMPTY_STRING;
+ wildcard.fNamespaceList[1] = null;
} else {
// list
wildcard = new XSWildcardDecl();
1.49 +33 -22 xml-xerces/java/src/org/apache/xerces/impl/v2/XSDHandler.java
Index: XSDHandler.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/XSDHandler.java,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -r1.48 -r1.49
--- XSDHandler.java 2001/10/19 18:22:00 1.48
+++ XSDHandler.java 2001/10/22 16:58:15 1.49
@@ -97,7 +97,7 @@
* schema, other grammars may be constructed as a side-effect.
*
* @author Neil Graham, IBM
- * @version $Id: XSDHandler.java,v 1.48 2001/10/19 18:22:00 sandygao Exp $
+ * @version $Id: XSDHandler.java,v 1.49 2001/10/22 16:58:15 sandygao Exp $
*/
class XSDHandler {
@@ -118,6 +118,11 @@
// as unlikely as possible to cause collisions.
public final static String REDEF_IDENTIFIER = "_fn3dktizrknc9pi";
+ // please note the difference between SchemaHandler.EMPTY_STRING and
+ // SchemaSymbols.EMPTY_STRING:
+ // the one in SchemaHandler is only for namespace binding purpose, it's
+ // used as a legal prefix, and it's added to the current symbol table;
+ // while the one in SchemaSymbols is for general purpose: just empty.
public String EMPTY_STRING;
//
@@ -284,10 +289,7 @@
return null;
}
// handle empty string URI as null
- if (schemaNamespace.length() == 0) {
- schemaNamespace = null;
- }
- else {
+ if (schemaNamespace != null) {
schemaNamespace = fSymbolTable.addSymbol(schemaNamespace);
}
fRoot = constructTrees(schemaRoot, schemaNamespace);
@@ -302,20 +304,14 @@
// third phase: call traversers
traverseSchemas();
-
- // fourth: handle substitution group declarations
- // we defer substitution group handling for circular substitution
- // REVISIT: wait until we are sure that such circular referencence
- // is allowed.
- //fElementTraverser.resolveSubstitutionGroup();
- // fifth phase: handle local element decls
+ // fourth phase: handle local element decls
traverseLocalElements();
- // sixth phase: handle Keyrefs
+ // fifth phase: handle Keyrefs
resolveKeyRefs();
- // seventh phase: handle derivation constraint checking
+ // sixth phase: handle derivation constraint checking
// and UPA, and validate attribute of non-schema namespaces
// REVISIT: skip this for now. we reall don't want to do it.
//fAttributeChecker.checkNonSchemaAttributes(fGrammarResolver);
@@ -394,6 +390,9 @@
Object[] includeAttrs = fAttributeChecker.checkAttributes(child, true, currSchemaInfo);
schemaHint = (String)includeAttrs[XSAttributeChecker.ATTIDX_SCHEMALOCATION];
fAttributeChecker.returnAttrArray(includeAttrs, currSchemaInfo);
+ // schemaLocation is required on <include> and <redefine>
+ if (schemaHint == null)
+ reportGenericSchemaError("schemaLocation attribute must appear in <include> and <redefine>");
newSchemaRoot = getSchema(null, schemaHint);
schemaNamespace = currSchemaInfo.fTargetNamespace;
}
@@ -417,8 +416,10 @@
// rename the right things later!
fRedefine2XSDMap.put(child, newSchemaInfo);
}
- dependencies.addElement(newSchemaInfo);
- newSchemaRoot = null;
+ if (newSchemaRoot != null) {
+ dependencies.addElement(newSchemaInfo);
+ newSchemaRoot = null;
+ }
}
fDependencyMap.put(currSchemaInfo, dependencies);
return currSchemaInfo;
@@ -873,13 +874,21 @@
Document schemaDoc = null;
try {
schemaSource = fEntityResolver.resolveEntity(schemaNamespace, schemaHint, null);
- if (schemaSource != null) {
+ // REVISIT: when the system id of the input source is null, it's
+ // impossible to find the schema document. so we skip in
+ // this case. otherwise we'll receive some NPE or
+ // file not found errors. but schemaHint=="" is perfectly
+ // legal for import.
+ // this checking should be done in EntityManager (our
+ // default entity resolver). but it's not clear to me
+ // whether the same applies for DTD.
+ if (schemaSource != null && schemaSource.getSystemId() != null) {
StringBuffer schemaIdBuf = new StringBuffer();;
if(schemaSource.getPublicId() != null)
schemaIdBuf.append(schemaSource.getPublicId());
if(schemaSource.getSystemId() != null)
schemaIdBuf.append(schemaSource.getSystemId());
- if(schemaIdBuf.equals(EMPTY_STRING))
+ if(schemaIdBuf.length() == 0)
schemaIdBuf.append(schemaSource.getBaseSystemId());
String schemaId =
fSymbolTable.addSymbol(schemaIdBuf.toString());
@@ -895,10 +904,12 @@
return schemaDoc;
}
- }
- catch (IOException ex) {
+ } catch (java.io.FileNotFoundException ex) {
+ // REVISIT: how to report an error for missing files
+ reportGenericSchemaError("file not found: " + schemaHint);
+ } catch (IOException ex) {
// REVISIT: report an error!
- ex.printStackTrace();
+ reportGenericSchemaError("error reading schema document: " + schemaHint);
}
schemaDoc = null;
@@ -934,7 +945,7 @@
fErrorReporter = errorReporter;
fSymbolTable = symbolTable;
- EMPTY_STRING = fSymbolTable.addSymbol("");
+ EMPTY_STRING = fSymbolTable.addSymbol(SchemaSymbols.EMPTY_STRING);
try {
fSchemaParser.setProperty(SchemaValidator.ERROR_REPORTER, fErrorReporter);
1.25 +3 -3 xml-xerces/java/src/org/apache/xerces/impl/v2/XSDSimpleTypeTraverser.java
Index: XSDSimpleTypeTraverser.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/XSDSimpleTypeTraverser.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- XSDSimpleTypeTraverser.java 2001/10/19 20:25:27 1.24
+++ XSDSimpleTypeTraverser.java 2001/10/22 16:58:15 1.25
@@ -108,7 +108,7 @@
* </union>
*
* @author Elena Litani, IBM
- * @version $Id: XSDSimpleTypeTraverser.java,v 1.24 2001/10/19 20:25:27 elena Exp $
+ * @version $Id: XSDSimpleTypeTraverser.java,v 1.25 2001/10/22 16:58:15 sandygao Exp $
*/
class XSDSimpleTypeTraverser extends XSDAbstractTraverser {
@@ -414,7 +414,7 @@
// reset fListName, meaning that we are done with
// traversing <list> and its itemType resolves to atomic value
if (fListName.equals(qualifiedName)) {
- fListName = fSchemaHandler.EMPTY_STRING;
+ fListName = SchemaSymbols.EMPTY_STRING;
}
}
if (restriction && content != null) {
@@ -445,7 +445,7 @@
private void reportCosListOfAtomic () {
reportGenericSchemaError("cos-list-of-atomic: The itemType must have a {variety} of atomic or union (in which case all the {member type definitions} must be atomic)");
- fListName=fSchemaHandler.EMPTY_STRING;
+ fListName=SchemaSymbols.EMPTY_STRING;
}
//@param: elm - top element
1.18 +1 -2 xml-xerces/java/src/org/apache/xerces/impl/v2/XSDocumentInfo.java
Index: XSDocumentInfo.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/XSDocumentInfo.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- XSDocumentInfo.java 2001/10/17 23:07:14 1.17
+++ XSDocumentInfo.java 2001/10/22 16:58:15 1.18
@@ -74,12 +74,11 @@
* affect the contents of that schema document alone.
*
* @author Neil Graham, IBM
- * @version $Id: XSDocumentInfo.java,v 1.17 2001/10/17 23:07:14 sandygao Exp $
+ * @version $Id: XSDocumentInfo.java,v 1.18 2001/10/22 16:58:15 sandygao Exp $
*/
class XSDocumentInfo {
- private static String EMPTY_STRING = "";
// Data
protected SchemaNamespaceSupport fNamespaceSupport;
protected SchemaNamespaceSupport fNamespaceSupportRoot;
1.8 +13 -9 xml-xerces/java/src/org/apache/xerces/impl/v2/XSGrammarResolver.java
Index: XSGrammarResolver.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/XSGrammarResolver.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- XSGrammarResolver.java 2001/09/28 18:11:43 1.7
+++ XSGrammarResolver.java 2001/10/22 16:58:15 1.8
@@ -62,19 +62,17 @@
/**
* A class used to hold the internal schema grammar set for the current instance
* @author Sandy Gao, IBM
- * @version $Id: XSGrammarResolver.java,v 1.7 2001/09/28 18:11:43 neilg Exp $
+ * @version $Id: XSGrammarResolver.java,v 1.8 2001/10/22 16:58:15 sandygao Exp $
*/
class XSGrammarResolver {
- // Constants
- private static String EMPTY_STRING = "";
-
// Data
/**
* Hashtable that maps between Namespace and a Grammar
*/
private Hashtable fGrammarRegistry = new Hashtable();
+ private SchemaGrammar fNoNSGrammar = null;
/**
* Get the schema grammar for the specified namespace
@@ -83,8 +81,8 @@
* @return SchemaGrammar associated with the namespace
*/
public SchemaGrammar getGrammar(String namespace) {
- if(namespace == null)
- return(SchemaGrammar)fGrammarRegistry.get(EMPTY_STRING);
+ if (namespace == null)
+ return fNoNSGrammar;
return (SchemaGrammar)fGrammarRegistry.get(namespace);
}
@@ -94,8 +92,8 @@
* @param grammar the grammar to put in the registry
*/
public void putGrammar(SchemaGrammar grammar) {
- if(grammar.getTargetNamespace() == null)
- fGrammarRegistry.put(EMPTY_STRING, grammar);
+ if (grammar.getTargetNamespace() == null)
+ fNoNSGrammar = grammar;
else
fGrammarRegistry.put(grammar.getTargetNamespace(), grammar);
}
@@ -110,7 +108,10 @@
* @param grammar the grammar to put in the registry
*/
public void putGrammar(String namespace, SchemaGrammar grammar) {
- fGrammarRegistry.put(namespace, grammar);
+ if (namespace == null)
+ fNoNSGrammar = grammar;
+ else
+ fGrammarRegistry.put(namespace, grammar);
}
/**
@@ -120,6 +121,8 @@
* @return boolean true if contains
*/
public boolean contains(String namespace) {
+ if (namespace == null)
+ return (fNoNSGrammar != null);
return fGrammarRegistry.containsKey(namespace);
}
@@ -128,6 +131,7 @@
* REVISIT: update to use another XMLGrammarResolver
*/
public void reset() {
+ fNoNSGrammar = null;
fGrammarRegistry.clear();
}
1.3 +10 -11 xml-xerces/java/src/org/apache/xerces/impl/v2/new_datatypes/XSSimpleTypeDecl.java
Index: XSSimpleTypeDecl.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/new_datatypes/XSSimpleTypeDecl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- XSSimpleTypeDecl.java 2001/10/03 18:27:07 1.2
+++ XSSimpleTypeDecl.java 2001/10/22 16:58:15 1.3
@@ -60,6 +60,7 @@
import org.apache.xerces.impl.v2.XSTypeDecl;
import org.apache.xerces.impl.v2.datatypes.InvalidDatatypeValueException;
import org.apache.xerces.impl.v2.datatypes.DatatypeMessageProvider;
+import org.apache.xerces.impl.v2.SchemaSymbols;
import org.apache.xerces.impl.v2.msg.XMLMessages;
import org.apache.xerces.util.XMLChar;
import org.apache.xerces.util.XIntPool;
@@ -75,7 +76,7 @@
/**
- * @version $Id: XSSimpleTypeDecl.java,v 1.2 2001/10/03 18:27:07 neilg Exp $
+ * @version $Id: XSSimpleTypeDecl.java,v 1.3 2001/10/22 16:58:15 sandygao Exp $
*/
public class XSSimpleTypeDecl implements XSTypeDecl {
@@ -402,9 +403,7 @@
fEnumeration[i] = getCompiledValue(enumVals[i]);
} catch (InvalidDatatypeValueException ide) {
reportError("Value of enumeration '" + enumVals[i] + "' must be from the value space of base");
- fEnumeration[i] = "";
- //REVISIT: uncomment it.
- //fEnumeration[i] = XSDHandler.EMPTY_STRING;
+ fEnumeration[i] = SchemaSymbols.EMPTY_STRING;
}
}
fFacetsDefined |= DEFINED_ENUMERATION;
@@ -1071,7 +1070,7 @@
int length = fDVs[fValidateDV].getDataLength(ob);
- // maxLength
+ // maxLength
if ( (fFacetsDefined & DEFINED_MAXLENGTH) != 0 ) {
if ( length > fMaxLength ) {
reportError("Value '"+content+
@@ -1080,7 +1079,7 @@
}
}
- //minLength
+ //minLength
if ( (fFacetsDefined & DEFINED_MINLENGTH) != 0 ) {
if ( length < fMinLength ) {
reportError("Value '"+content+
@@ -1089,7 +1088,7 @@
}
}
- //length
+ //length
if ( (fFacetsDefined & DEFINED_LENGTH) != 0 ) {
if ( length != fLength ) {
reportError("Value '"+content+
@@ -1098,7 +1097,7 @@
}
}
- //enumeration
+ //enumeration
if ( ((fFacetsDefined & DEFINED_ENUMERATION) != 0 )&&
(fEnumeration != null) ) {
@@ -1119,7 +1118,7 @@
- //fractionDigits
+ //fractionDigits
if ((fFacetsDefined & DEFINED_FRACTIONDIGITS) != 0) {
int scale = fDVs[fValidateDV].getFractionDigits(ob);
if (scale > fFractionDigits) {
@@ -1133,7 +1132,7 @@
}
}
- //totalDigits
+ //totalDigits
if ((fFacetsDefined & DEFINED_TOTALDIGITS)!=0) {
int totalDigits = fDVs[fValidateDV].getTotalDigits(ob);
if (totalDigits > fTotalDigits) {
@@ -1151,7 +1150,7 @@
// REVISIT this part for error reporting
- boolean minOk = true;
+ boolean minOk = true;
boolean maxOk = true;
String upperBound="";
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org