Hi, Please find attached patch for SchemaGrammar.
Description: When SchemaGrammar is constructed using the constructor SchemaGrammar(SymbolTable symbolTable, boolean fullSet), it does not initialize all the global SymbolHash data structures. As a result, you get unexpected results. Consider the schema... <schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:foo="foo" targetNamespace="foo" elementFormDefault="qualified"> <element name="root"> <complexType> <sequence> <element ref="root" /> </sequence> </complexType> </element> </schema> In this case, the declaration <element ref="root" />, tries to look for root in grammar SG_SchemaNS, using SchemaGrammar.getGlobal...Decl(). What do you expect?. It should return null, obviously (its not foo:root). But, the global SymbolHash itself is null. So, null.getGlobal...Decl()?? We have two solutions here: 1. Initialize all global SymbolHash in this constructor. This will unnecessarily waste memory as we are sure we are not adding anthing but, TypeDecls to grammar for URI http://www.w3.org/2001/XMLSchema. 2. Put some IF while getting global entry. I prefer the second solution, thus the attached patch. Cheers, Rahul. Sun Microsystems, Inc.
SchemaGrammar.java
Description: SchemaGrammar.java
Index: SchemaGrammar.java
===================================================================
RCS file:
/home/cvspublic/xml-xerces/java/src/org/apache/xerces/impl/v2/SchemaGrammar.java,v
retrieving revision 1.25
diff -u -w -r1.25 SchemaGrammar.java
--- SchemaGrammar.java 2001/10/11 15:13:33 1.25
+++ SchemaGrammar.java 2001/10/14 09:53:17
@@ -70,6 +70,7 @@
*
* @author Sandy Gao, IBM
* @author Elena Litani, IBM
+ * @author Rahul Srivastava, Sun Microsystems Inc.
*
* @version $Id: SchemaGrammar.java,v 1.25 2001/10/11 15:13:33 elena Exp $
*/
@@ -290,108 +291,155 @@
* register one global attribute
*/
public final void addGlobalAttributeDecl(XSAttributeDecl decl) {
+ if ((decl != null) && (decl.fName != null)) {
fGlobalAttrDecls.put(decl.fName, decl);
}
+ //REVISIT: reportSchemaError("Trying to add a global declaration, either null
+or without name");
+ }
+
/**
* register one global attribute group
*/
public final void addGlobalAttributeGroupDecl(XSAttributeGroupDecl decl) {
+ if ((decl != null) && (decl.fName != null)) {
fGlobalAttrGrpDecls.put(decl.fName, decl);
}
+ //REVISIT: reportSchemaError("Trying to add a global declaration, either null
+or without name");
+ }
+
/**
* register one global element
*/
public final void addGlobalElementDecl(XSElementDecl decl) {
+ if ((decl != null) && (decl.fName != null)) {
fGlobalElemDecls.put(decl.fName, decl);
}
+ //REVISIT: reportSchemaError("Trying to add a global declaration, either null
+or without name");
+ }
+
/**
* register one global group
*/
public final void addGlobalGroupDecl(XSGroupDecl decl) {
+ if ((decl != null) && (decl.fName != null)) {
fGlobalGroupDecls.put(decl.fName, decl);
}
+ //REVISIT: reportSchemaError("Trying to add a global declaration, either null
+or without name");
+ }
+
/**
* register one global notation
*/
public final void addGlobalNotationDecl(XSNotationDecl decl) {
+ if ((decl != null) && (decl.fName != null)) {
fGlobalNotationDecls.put(decl.fName, decl);
}
+ //REVISIT: reportSchemaError("Trying to add a global declaration, either null
+or without name");
+ }
+
/**
* register one global type
*/
public final void addGlobalTypeDecl(XSTypeDecl decl) {
- if (decl == null) {
- System.err.println("decl");
- System.exit(0);
- }
- else if (decl.getXSTypeName() == null) {
- System.err.println("decl.whatever");
- System.exit(0);
+ if ((decl != null) && (decl.getXSTypeName() != null)) {
+ fGlobalTypeDecls.put(decl.getXSTypeName(), decl);
}
- fGlobalTypeDecls.put(decl.getXSTypeName(), decl);
+ //REVISIT: reportSchemaError("Trying to add a global declaration, either null
+or without name");
}
/**
* register one identity constraint
*/
public final void addIDConstraintDecl(XSElementDecl elmDecl, IdentityConstraint
decl) {
+ if ((decl != null) && (decl.getIdentityConstraintName() != null) && (elmDecl
+!= null)) {
elmDecl.addIDConstaint(decl);
fGlobalIDConstraintDecls.put(decl.getIdentityConstraintName(), decl);
}
+ //REVISIT: reportSchemaError("Trying to add a global declaration, either null
+or without name");
+ }
+
/**
* get one global attribute
*/
public final XSAttributeDecl getGlobalAttributeDecl(String declName) {
+ if (fGlobalAttrDecls != null) {
return(XSAttributeDecl)fGlobalAttrDecls.get(declName);
}
+ return null;
+ }
+
/**
* get one global attribute group
*/
public final XSAttributeGroupDecl getGlobalAttributeGroupDecl(String declName) {
+ if (fGlobalAttrGrpDecls != null) {
return(XSAttributeGroupDecl)fGlobalAttrGrpDecls.get(declName);
}
+ return null;
+ }
+
/**
* get one global element
*/
public final XSElementDecl getGlobalElementDecl(String declName) {
+ if (fGlobalElemDecls != null) {
return(XSElementDecl)fGlobalElemDecls.get(declName);
}
+ return null;
+ }
+
/**
* get one global group
*/
public final XSGroupDecl getGlobalGroupDecl(String declName) {
+ if (fGlobalGroupDecls != null) {
return(XSGroupDecl)fGlobalGroupDecls.get(declName);
}
+ return null;
+ }
+
/**
* get one global notation
*/
public final XSNotationDecl getNotationDecl(String declName) {
+ if (fGlobalNotationDecls != null) {
return(XSNotationDecl)fGlobalNotationDecls.get(declName);
}
+ return null;
+ }
+
/**
* get one global type
*/
public final XSTypeDecl getGlobalTypeDecl(String declName) {
+ if (fGlobalTypeDecls != null) {
return(XSTypeDecl)fGlobalTypeDecls.get(declName);
}
+ return null;
+ }
+
/**
* get one identity constraint
*/
public final IdentityConstraint getIDConstraintDecl(String declName) {
+ if (fGlobalIDConstraintDecls != null) {
return(IdentityConstraint)fGlobalIDConstraintDecls.get(declName);
+ }
+
+ return null;
}
// array to store complex type decls
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
