You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by kn...@apache.org on 2009/06/15 20:54:12 UTC
svn commit: r784915 - in /xerces/java/trunk/src/org/apache/xerces: dom/
impl/ impl/xs/ impl/xs/traversers/ parsers/
Author: knoaman
Date: Mon Jun 15 18:54:11 2009
New Revision: 784915
URL: http://svn.apache.org/viewvc?rev=784915&view=rev
Log:
[Internal] Tolerate duplicate global declarations (in different schema documents)
Modified:
xerces/java/trunk/src/org/apache/xerces/dom/DOMConfigurationImpl.java
xerces/java/trunk/src/org/apache/xerces/impl/Constants.java
xerces/java/trunk/src/org/apache/xerces/impl/xs/XMLSchemaLoader.java
xerces/java/trunk/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java
xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDAttributeGroupTraverser.java
xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDAttributeTraverser.java
xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDComplexTypeTraverser.java
xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDElementTraverser.java
xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDGroupTraverser.java
xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java
xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDKeyrefTraverser.java
xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDNotationTraverser.java
xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDSimpleTypeTraverser.java
xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDUniqueOrKeyTraverser.java
xerces/java/trunk/src/org/apache/xerces/parsers/DOMParserImpl.java
xerces/java/trunk/src/org/apache/xerces/parsers/StandardParserConfiguration.java
xerces/java/trunk/src/org/apache/xerces/parsers/XML11Configuration.java
Modified: xerces/java/trunk/src/org/apache/xerces/dom/DOMConfigurationImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/dom/DOMConfigurationImpl.java?rev=784915&r1=784914&r2=784915&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/dom/DOMConfigurationImpl.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/dom/DOMConfigurationImpl.java Mon Jun 15 18:54:11 2009
@@ -133,6 +133,8 @@
protected static final String NAMESPACE_GROWTH =
Constants.XERCES_FEATURE_PREFIX + Constants.NAMESPACE_GROWTH_FEATURE;
+ protected static final String TOLERATE_DUPLICATES =
+ Constants.XERCES_FEATURE_PREFIX + Constants.TOLERATE_DUPLICATES_FEATURE;
// property identifiers
/** Property identifier: entity manager. */
@@ -305,7 +307,8 @@
BALANCE_SYNTAX_TREES,
WARN_ON_DUPLICATE_ATTDEF,
PARSER_SETTINGS,
- NAMESPACE_GROWTH
+ NAMESPACE_GROWTH,
+ TOLERATE_DUPLICATES
};
addRecognizedFeatures(recognizedFeatures);
@@ -327,6 +330,7 @@
setFeature(WARN_ON_DUPLICATE_ATTDEF, false);
setFeature(PARSER_SETTINGS, true);
setFeature(NAMESPACE_GROWTH, false);
+ setFeature(TOLERATE_DUPLICATES, false);
// add default recognized properties
final String[] recognizedProperties = {
Modified: xerces/java/trunk/src/org/apache/xerces/impl/Constants.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/Constants.java?rev=784915&r1=784914&r2=784915&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/Constants.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/Constants.java Mon Jun 15 18:54:11 2009
@@ -279,6 +279,9 @@
/** Namespace growth feature ("namespace-growth"). */
public static final String NAMESPACE_GROWTH_FEATURE = "namespace-growth";
+
+ /** Tolerate duplicates feature ("internal/tolerate-duplicates"). */
+ public static final String TOLERATE_DUPLICATES_FEATURE = "internal/tolerate-duplicates";
/** XInclude processing feature ("xinclude"). */
public static final String XINCLUDE_FEATURE = "xinclude";
@@ -287,7 +290,7 @@
public static final String XINCLUDE_FIXUP_BASE_URIS_FEATURE = "xinclude/fixup-base-uris";
/** XInclude fixup language feature ("xinclude/fixup-language"). */
- public static final String XINCLUDE_FIXUP_LANGUAGE_FEATURE = "xinclude/fixup-language";
+ public static final String XINCLUDE_FIXUP_LANGUAGE_FEATURE = "xinclude/fixup-language";
/**
* Feature to ignore xsi:type attributes on elements during validation,
@@ -518,6 +521,7 @@
IDC_CHECKING_FEATURE,
UNPARSED_ENTITY_CHECKING_FEATURE,
NAMESPACE_GROWTH_FEATURE,
+ TOLERATE_DUPLICATES_FEATURE,
};
/** Xerces properties. */
Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/XMLSchemaLoader.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xs/XMLSchemaLoader.java?rev=784915&r1=784914&r2=784915&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/XMLSchemaLoader.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/XMLSchemaLoader.java Mon Jun 15 18:54:11 2009
@@ -132,12 +132,16 @@
Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_AUGMENT_PSVI;
protected static final String PARSER_SETTINGS =
- Constants.XERCES_FEATURE_PREFIX + Constants.PARSER_SETTINGS;
+ Constants.XERCES_FEATURE_PREFIX + Constants.PARSER_SETTINGS;
/** Feature identifier: namespace growth */
protected static final String NAMESPACE_GROWTH =
Constants.XERCES_FEATURE_PREFIX + Constants.NAMESPACE_GROWTH_FEATURE;
+ /** Feature identifier: tolerate duplicates */
+ protected static final String TOLERATE_DUPLICATES =
+ Constants.XERCES_FEATURE_PREFIX + Constants.TOLERATE_DUPLICATES_FEATURE;
+
// recognized features:
private static final String[] RECOGNIZED_FEATURES = {
SCHEMA_FULL_CHECKING,
@@ -149,7 +153,8 @@
GENERATE_SYNTHETIC_ANNOTATIONS,
VALIDATE_ANNOTATIONS,
HONOUR_ALL_SCHEMALOCATIONS,
- NAMESPACE_GROWTH
+ NAMESPACE_GROWTH,
+ TOLERATE_DUPLICATES
};
// property identifiers
@@ -1147,7 +1152,8 @@
name.equals(STANDARD_URI_CONFORMANT_FEATURE) ||
name.equals(GENERATE_SYNTHETIC_ANNOTATIONS) ||
name.equals(HONOUR_ALL_SCHEMALOCATIONS) ||
- name.equals(NAMESPACE_GROWTH)) {
+ name.equals(NAMESPACE_GROWTH) ||
+ name.equals(TOLERATE_DUPLICATES)) {
return true;
}
@@ -1224,6 +1230,7 @@
v.add(GENERATE_SYNTHETIC_ANNOTATIONS);
v.add(HONOUR_ALL_SCHEMALOCATIONS);
v.add(NAMESPACE_GROWTH);
+ v.add(TOLERATE_DUPLICATES);
fRecognizedParameters = new DOMStringListImpl(v);
}
return fRecognizedParameters;
Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java?rev=784915&r1=784914&r2=784915&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java Mon Jun 15 18:54:11 2009
@@ -180,6 +180,10 @@
protected static final String NAMESPACE_GROWTH =
Constants.XERCES_FEATURE_PREFIX + Constants.NAMESPACE_GROWTH_FEATURE;
+ /** Feature identifier: tolerate duplicates */
+ protected static final String TOLERATE_DUPLICATES =
+ Constants.XERCES_FEATURE_PREFIX + Constants.TOLERATE_DUPLICATES_FEATURE;
+
/** Feature identifier: whether to ignore xsi:type attributes until a global element declaration is encountered */
protected static final String IGNORE_XSI_TYPE =
Constants.XERCES_FEATURE_PREFIX + Constants.IGNORE_XSI_TYPE_FEATURE;
@@ -265,6 +269,7 @@
IDENTITY_CONSTRAINT_CHECKING,
UNPARSED_ENTITY_CHECKING,
NAMESPACE_GROWTH,
+ TOLERATE_DUPLICATES
};
@@ -295,6 +300,7 @@
null,
null,
null,
+ null
};
/** Recognized properties. */
@@ -325,7 +331,7 @@
static final XSAttributeDecl XSI_TYPE = SchemaGrammar.SG_XSI.getGlobalAttributeDecl(SchemaSymbols.XSI_TYPE);
static final XSAttributeDecl XSI_NIL = SchemaGrammar.SG_XSI.getGlobalAttributeDecl(SchemaSymbols.XSI_NIL);
static final XSAttributeDecl XSI_SCHEMALOCATION = SchemaGrammar.SG_XSI.getGlobalAttributeDecl(SchemaSymbols.XSI_SCHEMALOCATION);
- static final XSAttributeDecl XSI_NONAMESPACESCHEMALOCATION = SchemaGrammar.SG_XSI.getGlobalAttributeDecl(SchemaSymbols.XSI_NONAMESPACESCHEMALOCATION);
+ static final XSAttributeDecl XSI_NONAMESPACESCHEMALOCATION = SchemaGrammar.SG_XSI.getGlobalAttributeDecl(SchemaSymbols.XSI_NONAMESPACESCHEMALOCATION);
//
private static final Hashtable EMPTY_TABLE = new Hashtable();
Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDAttributeGroupTraverser.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDAttributeGroupTraverser.java?rev=784915&r1=784914&r2=784915&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDAttributeGroupTraverser.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDAttributeGroupTraverser.java Mon Jun 15 18:54:11 2009
@@ -179,17 +179,19 @@
attrGrp.fAnnotations = annotations;
// make an entry in global declarations.
- if (!fSchemaHandler.fNamespaceGrowth) {
+ if (grammar.getGlobalAttributeGroupDecl(attrGrp.fName) == null) {
grammar.addGlobalAttributeGroupDecl(attrGrp);
}
- else {
- if (grammar.getGlobalAttributeGroupDecl(attrGrp.fName) == null) {
- grammar.addGlobalAttributeGroupDecl(attrGrp);
- }
+ if (fSchemaHandler.fTolerateDuplicates) {
final String loc = fSchemaHandler.schemaDocument2SystemId(schemaDoc);
- if (grammar.getGlobalAttributeGroupDecl(attrGrp.fName, loc) == null) {
+ final XSAttributeGroupDecl attrGrp2 = grammar.getGlobalAttributeGroupDecl(attrGrp.fName, loc);
+ if (attrGrp2 == null) {
grammar.addGlobalAttributeGroupDecl(attrGrp, loc);
}
+ else {
+ attrGrp = attrGrp2;
+ }
+ fSchemaHandler.addGlobalAttributeGroupDecl(attrGrp);
}
fAttrChecker.returnAttrArray(attrValues, schemaDoc);
Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDAttributeTraverser.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDAttributeTraverser.java?rev=784915&r1=784914&r2=784915&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDAttributeTraverser.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDAttributeTraverser.java Mon Jun 15 18:54:11 2009
@@ -341,7 +341,7 @@
}
attribute.setValues(nameAtt, tnsAtt, attrType, constraintType, scope,
attDefault, enclCT, annotations);
-
+
// Step 3: check against schema for schemas
// required attributes
@@ -436,28 +436,28 @@
// Attribute without a name. Return null.
if (nameAtt.equals(NO_NAME))
return null;
-
+
// Step 2: register attribute decl to the grammar
if (isGlobal) {
- if (!fSchemaHandler.fNamespaceGrowth) {
+ if (grammar.getGlobalAttributeDecl(nameAtt) == null) {
grammar.addGlobalAttributeDecl(attribute);
}
- else {
- if (grammar.getGlobalAttributeDecl(nameAtt) == null) {
- grammar.addGlobalAttributeDecl(attribute);
- }
+ if (fSchemaHandler.fTolerateDuplicates) {
final String loc = fSchemaHandler.schemaDocument2SystemId(schemaDoc);
- if (loc != null) {
- if (grammar.getGlobalAttributeDecl(nameAtt, loc) == null) {
- grammar.addGlobalAttributeDecl(attribute, loc);
- }
+ final XSAttributeDecl attribute2 = grammar.getGlobalAttributeDecl(nameAtt, loc);
+ if (attribute2 == null) {
+ grammar.addGlobalAttributeDecl(attribute, loc);
}
+ else {
+ attribute = attribute2;
+ }
+ fSchemaHandler.addGlobalAttributeDecl(attribute);
}
}
-
+
return attribute;
}
-
+
// throws an error if the constraint value is invalid for the given type
void checkDefaultValid(XSAttributeDecl attribute) throws InvalidDatatypeValueException {
// validate the original lexical rep, and set the actual value
Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDComplexTypeTraverser.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDComplexTypeTraverser.java?rev=784915&r1=784914&r2=784915&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDComplexTypeTraverser.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDComplexTypeTraverser.java Mon Jun 15 18:54:11 2009
@@ -197,17 +197,21 @@
reportSchemaError("s4s-att-must-appear", new Object[]{SchemaSymbols.ELT_COMPLEXTYPE, SchemaSymbols.ATT_NAME}, complexTypeNode);
type = null;
} else {
- if (!fSchemaHandler.fNamespaceGrowth) {
+ if (grammar.getGlobalTypeDecl(type.getName()) == null) {
grammar.addGlobalComplexTypeDecl(type);
}
- else {
+ if (fSchemaHandler.fTolerateDuplicates) {
final String loc = fSchemaHandler.schemaDocument2SystemId(schemaDoc);
- if (grammar.getGlobalTypeDecl(type.getName()) == null) {
- grammar.addGlobalComplexTypeDecl(type);
- }
- if (grammar.getGlobalTypeDecl(type.getName(), loc) == null) {
+ final XSTypeDefinition type2 = grammar.getGlobalTypeDecl(type.getName(), loc);
+ if (type2 == null) {
grammar.addGlobalComplexTypeDecl(type, loc);
}
+ else {
+ if (type instanceof XSComplexTypeDecl) {
+ type = (XSComplexTypeDecl) type2;
+ }
+ }
+ fSchemaHandler.addGlobalTypeDecl(type);
}
}
Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDElementTraverser.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDElementTraverser.java?rev=784915&r1=784914&r2=784915&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDElementTraverser.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDElementTraverser.java Mon Jun 15 18:54:11 2009
@@ -412,7 +412,7 @@
fSchemaHandler.checkForDuplicateNames(
(schemaDoc.fTargetNamespace == null) ? ","+DOMUtil.getAttrValue(child, SchemaSymbols.ATT_NAME)
: schemaDoc.fTargetNamespace+","+ DOMUtil.getAttrValue(child, SchemaSymbols.ATT_NAME),
- fSchemaHandler.getIDRegistry(), fSchemaHandler.getIDRegistry_sub(),
+ fSchemaHandler.ATTRIBUTE_TYPE, fSchemaHandler.getIDRegistry(), fSchemaHandler.getIDRegistry_sub(),
child, schemaDoc);
}
} else if (childName.equals(SchemaSymbols.ELT_KEYREF)) {
@@ -504,17 +504,19 @@
// Step 5: register the element decl to the grammar
if (isGlobal) {
- if (!fSchemaHandler.fNamespaceGrowth) {
+ if (grammar.getGlobalElementDecl(element.fName) == null) {
grammar.addGlobalElementDecl(element);
}
- else {
- if (grammar.getGlobalElementDecl(element.fName) == null) {
- grammar.addGlobalElementDecl(element);
- }
+ if (fSchemaHandler.fTolerateDuplicates) {
final String loc = fSchemaHandler.schemaDocument2SystemId(schemaDoc);
- if (grammar.getGlobalElementDecl(element.fName, loc) == null) {
+ final XSElementDecl element2 = grammar.getGlobalElementDecl(element.fName, loc);
+ if (element2 == null) {
grammar.addGlobalElementDecl(element, loc);
}
+ else {
+ element = element2;
+ }
+ fSchemaHandler.addGlobalElementDecl(element);
}
}
Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDGroupTraverser.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDGroupTraverser.java?rev=784915&r1=784914&r2=784915&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDGroupTraverser.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDGroupTraverser.java Mon Jun 15 18:54:11 2009
@@ -220,34 +220,35 @@
} else {
annotations = XSObjectListImpl.EMPTY_LIST;
}
- group.fAnnotations = annotations;
+ group.fAnnotations = annotations;
// Add group declaration to grammar
- if (!fSchemaHandler.fNamespaceGrowth) {
+ if (grammar.getGlobalGroupDecl(group.fName) == null) {
grammar.addGlobalGroupDecl(group);
}
- else {
- if (grammar.getGlobalGroupDecl(group.fName) == null) {
- grammar.addGlobalGroupDecl(group);
- }
+ if (fSchemaHandler.fTolerateDuplicates) {
final String loc = fSchemaHandler.schemaDocument2SystemId(schemaDoc);
- if (grammar.getGlobalGroupDecl(group.fName, loc) == null) {
+ final XSGroupDecl group2 = grammar.getGlobalGroupDecl(group.fName, loc);
+ if (group2 == null) {
grammar.addGlobalGroupDecl(group, loc);
}
+ else {
+ group = group2;
+ }
+ fSchemaHandler.addGlobalGroupDecl(group);
}
-
}
else {
// name attribute is not there, don't return this group.
group = null;
}
- if(group != null) {
+ if (group != null) {
// store groups redefined by restriction in the grammar so
// that we can get at them at full-schema-checking time.
Object redefinedGrp = fSchemaHandler.getGrpOrAttrGrpRedefinedByRestriction(XSDHandler.GROUP_TYPE,
new QName(XMLSymbols.EMPTY_STRING, strNameAttr, strNameAttr, schemaDoc.fTargetNamespace),
schemaDoc, elmNode);
- if(redefinedGrp != null) {
+ if (redefinedGrp != null) {
// store in grammar
grammar.addRedefinedGroupDecl(group, (XSGroupDecl)redefinedGrp,
fSchemaHandler.element2Locator(elmNode));
Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java?rev=784915&r1=784914&r2=784915&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java Mon Jun 15 18:54:11 2009
@@ -37,6 +37,8 @@
import org.apache.xerces.impl.xs.SchemaSymbols;
import org.apache.xerces.impl.xs.XMLSchemaException;
import org.apache.xerces.impl.xs.XMLSchemaLoader;
+import org.apache.xerces.impl.xs.XSAttributeDecl;
+import org.apache.xerces.impl.xs.XSAttributeGroupDecl;
import org.apache.xerces.impl.xs.XSComplexTypeDecl;
import org.apache.xerces.impl.xs.XSDDescription;
import org.apache.xerces.impl.xs.XSDeclarationPool;
@@ -45,7 +47,9 @@
import org.apache.xerces.impl.xs.XSGroupDecl;
import org.apache.xerces.impl.xs.XSMessageFormatter;
import org.apache.xerces.impl.xs.XSModelGroupImpl;
+import org.apache.xerces.impl.xs.XSNotationDecl;
import org.apache.xerces.impl.xs.XSParticleDecl;
+import org.apache.xerces.impl.xs.identity.IdentityConstraint;
import org.apache.xerces.impl.xs.opti.ElementImpl;
import org.apache.xerces.impl.xs.opti.SchemaDOMParser;
import org.apache.xerces.impl.xs.opti.SchemaParsingConfig;
@@ -59,6 +63,7 @@
import org.apache.xerces.util.SAXInputSource;
import org.apache.xerces.util.StAXInputSource;
import org.apache.xerces.util.StAXLocationWrapper;
+import org.apache.xerces.util.SymbolHash;
import org.apache.xerces.util.SymbolTable;
import org.apache.xerces.util.XMLSymbols;
import org.apache.xerces.util.URI.MalformedURIException;
@@ -77,6 +82,7 @@
import org.apache.xerces.xni.parser.XMLParseException;
import org.apache.xerces.xs.XSObject;
import org.apache.xerces.xs.XSParticle;
+import org.apache.xerces.xs.XSTypeDefinition;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -143,6 +149,10 @@
/** Feature identifier: namespace growth */
protected static final String NAMESPACE_GROWTH =
Constants.XERCES_FEATURE_PREFIX + Constants.NAMESPACE_GROWTH_FEATURE;
+
+ /** Feature identifier: tolerate duplicates */
+ protected static final String TOLERATE_DUPLICATES =
+ Constants.XERCES_FEATURE_PREFIX + Constants.TOLERATE_DUPLICATES_FEATURE;
/** Feature identifier: namespace prefixes. */
private static final String NAMESPACE_PREFIXES =
@@ -266,7 +276,7 @@
// Records which nodes are hidden when the input is a DOMInputSource.
Hashtable fHiddenNodes = null;
-
+
// convenience methods
private String null2EmptyString(String ns) {
return ns == null ? XMLSymbols.EMPTY_STRING : ns;
@@ -331,6 +341,9 @@
//handle namespace growth feature
boolean fNamespaceGrowth = false;
+
+ // handle tolerate duplicates feature
+ boolean fTolerateDuplicates = false;
// the XMLErrorReporter
private XMLErrorReporter fErrorReporter;
@@ -400,6 +413,15 @@
private XSDocumentInfo [] fKeyrefsMapXSDocumentInfo = new XSDocumentInfo[INIT_KEYREF_STACK];
private XSElementDecl [] fKeyrefElems = new XSElementDecl [INIT_KEYREF_STACK];
private String [][] fKeyrefNamespaceContext = new String[INIT_KEYREF_STACK][1];
+
+ // global decls: map from decl name to decl object
+ SymbolHash fGlobalAttrDecls = new SymbolHash();
+ SymbolHash fGlobalAttrGrpDecls = new SymbolHash();
+ SymbolHash fGlobalElemDecls = new SymbolHash();
+ SymbolHash fGlobalGroupDecls = new SymbolHash();
+ SymbolHash fGlobalNotationDecls = new SymbolHash();
+ SymbolHash fGlobalIDConstraintDecls = new SymbolHash();
+ SymbolHash fGlobalTypeDecls = new SymbolHash();
// Constructors
public XSDHandler(){
@@ -439,6 +461,7 @@
SchemaGrammar grammar = null;
String schemaNamespace = null;
short referType = desc.getContextType();
+
// if loading using JAXP schemaSource property, or using grammar caching loadGrammar
// the desc.targetNamespace is always null.
// Therefore we should not attempt to find out if
@@ -507,8 +530,8 @@
if (schemaRoot == null) {
// something went wrong right off the hop
return null;
- }
-
+ }
+
if (referType == XSDDescription.CONTEXT_PREPARSE) {
Element schemaElem = schemaRoot;
schemaNamespace = DOMUtil.getAttrValue(schemaElem, SchemaSymbols.ATT_TARGETNAMESPACE);
@@ -773,22 +796,22 @@
currSchemaInfo.addAllowedNS(currSchemaInfo.fTargetNamespace);
SchemaGrammar sg = null;
-
+
// we have a namespace collision
if (nsCollision) {
SchemaGrammar sg2 = fGrammarBucket.getGrammar(currSchemaInfo.fTargetNamespace);
- //if (sg2.isImmutable()) {
- // sg = new SchemaGrammar(sg2);
- // fGrammarBucket.putGrammar(sg);
+ if (sg2.isImmutable()) {
+ sg = new SchemaGrammar(sg2);
+ fGrammarBucket.putGrammar(sg);
// update all the grammars in the bucket to point to the new grammar.
- // updateImportListWith(sg);
- //}
- //else {
+ updateImportListWith(sg);
+ }
+ else {
sg = sg2;
- //}
-
+ }
+
// update import list of the new grammar
- //updateImportListFor(sg);
+ updateImportListFor(sg);
}
else if (referType == XSDDescription.CONTEXT_INCLUDE ||
referType == XSDDescription.CONTEXT_REDEFINE) {
@@ -1005,8 +1028,26 @@
fSchemaGrammarDescription.setBaseSystemId(doc2SystemId(schemaRoot));
fSchemaGrammarDescription.setLocationHints(new String[]{schemaHint});
fSchemaGrammarDescription.setTargetNamespace(callerTNS);
- newSchemaRoot = resolveSchema(fSchemaGrammarDescription, mustResolve, child, true);
- schemaNamespace = currSchemaInfo.fTargetNamespace;
+
+ boolean alreadyTraversed = false;
+ XMLInputSource schemaSource = resolveSchemaSource(fSchemaGrammarDescription, mustResolve, child, true);
+ if (fNamespaceGrowth && refType == XSDDescription.CONTEXT_INCLUDE) {
+ try {
+ final String schemaId = XMLEntityManager.expandSystemId(schemaSource.getSystemId(), schemaSource.getBaseSystemId(), false);
+ alreadyTraversed = sg.getDocumentLocations().contains(schemaId);
+ }
+ catch(MalformedURIException e) {
+
+ }
+ }
+
+ if (!alreadyTraversed) {
+ newSchemaRoot = resolveSchema(schemaSource, fSchemaGrammarDescription, mustResolve, child);
+ schemaNamespace = currSchemaInfo.fTargetNamespace;
+ }
+ else {
+ fLastSchemaWasDuplicate = true;
+ }
}
else {
// no more possibility of schema references in well-formed
@@ -1023,7 +1064,7 @@
else {
newSchemaInfo = constructTrees(newSchemaRoot, schemaHint, fSchemaGrammarDescription, importCollision);
}
-
+
if (localName.equals(SchemaSymbols.ELT_REDEFINE) &&
newSchemaInfo != null) {
// must record which schema we're redefining so that we can
@@ -1073,7 +1114,7 @@
for (int i=0; i<importedGrammars.size(); i++) {
SchemaGrammar isg1 = (SchemaGrammar) importedGrammars.elementAt(i);
SchemaGrammar isg2 = fGrammarBucket.getGrammar(isg1.getTargetNamespace());
- if (isg1 != isg2) {
+ if (isg2 != null && isg1 != isg2) {
importedGrammars.set(i, isg2);
}
}
@@ -1175,7 +1216,7 @@
currSchemaDoc.fTargetNamespace +","+lName;
String componentType = DOMUtil.getLocalName(redefineComp);
if (componentType.equals(SchemaSymbols.ELT_ATTRIBUTEGROUP)) {
- checkForDuplicateNames(qName, fUnparsedAttributeGroupRegistry, fUnparsedAttributeGroupRegistrySub, redefineComp, currSchemaDoc);
+ checkForDuplicateNames(qName, ATTRIBUTEGROUP_TYPE, fUnparsedAttributeGroupRegistry, fUnparsedAttributeGroupRegistrySub, redefineComp, currSchemaDoc);
// the check will have changed our name;
String targetLName = DOMUtil.getAttrValue(redefineComp, SchemaSymbols.ATT_NAME)+REDEF_IDENTIFIER;
// and all we need to do is error-check+rename our kkids:
@@ -1184,7 +1225,7 @@
}
else if ((componentType.equals(SchemaSymbols.ELT_COMPLEXTYPE)) ||
(componentType.equals(SchemaSymbols.ELT_SIMPLETYPE))) {
- checkForDuplicateNames(qName, fUnparsedTypeRegistry, fUnparsedTypeRegistrySub, redefineComp, currSchemaDoc);
+ checkForDuplicateNames(qName, TYPEDECL_TYPE, fUnparsedTypeRegistry, fUnparsedTypeRegistrySub, redefineComp, currSchemaDoc);
// the check will have changed our name;
String targetLName = DOMUtil.getAttrValue(redefineComp, SchemaSymbols.ATT_NAME) + REDEF_IDENTIFIER;
// and all we need to do is error-check+rename our kkids:
@@ -1198,7 +1239,7 @@
}
}
else if (componentType.equals(SchemaSymbols.ELT_GROUP)) {
- checkForDuplicateNames(qName, fUnparsedGroupRegistry, fUnparsedGroupRegistrySub, redefineComp, currSchemaDoc);
+ checkForDuplicateNames(qName, GROUP_TYPE, fUnparsedGroupRegistry, fUnparsedGroupRegistrySub, redefineComp, currSchemaDoc);
// the check will have changed our name;
String targetLName = DOMUtil.getAttrValue(redefineComp, SchemaSymbols.ATT_NAME)+REDEF_IDENTIFIER;
// and all we need to do is error-check+rename our kids:
@@ -1218,24 +1259,25 @@
","+lName:
currSchemaDoc.fTargetNamespace +","+lName;
String componentType = DOMUtil.getLocalName(globalComp);
+
if (componentType.equals(SchemaSymbols.ELT_ATTRIBUTE)) {
- checkForDuplicateNames(qName, fUnparsedAttributeRegistry, fUnparsedAttributeRegistrySub, globalComp, currSchemaDoc);
+ checkForDuplicateNames(qName, ATTRIBUTE_TYPE, fUnparsedAttributeRegistry, fUnparsedAttributeRegistrySub, globalComp, currSchemaDoc);
}
else if (componentType.equals(SchemaSymbols.ELT_ATTRIBUTEGROUP)) {
- checkForDuplicateNames(qName, fUnparsedAttributeGroupRegistry, fUnparsedAttributeGroupRegistrySub, globalComp, currSchemaDoc);
+ checkForDuplicateNames(qName, ATTRIBUTEGROUP_TYPE, fUnparsedAttributeGroupRegistry, fUnparsedAttributeGroupRegistrySub, globalComp, currSchemaDoc);
}
else if ((componentType.equals(SchemaSymbols.ELT_COMPLEXTYPE)) ||
(componentType.equals(SchemaSymbols.ELT_SIMPLETYPE))) {
- checkForDuplicateNames(qName, fUnparsedTypeRegistry, fUnparsedTypeRegistrySub, globalComp, currSchemaDoc);
+ checkForDuplicateNames(qName, TYPEDECL_TYPE, fUnparsedTypeRegistry, fUnparsedTypeRegistrySub, globalComp, currSchemaDoc);
}
else if (componentType.equals(SchemaSymbols.ELT_ELEMENT)) {
- checkForDuplicateNames(qName, fUnparsedElementRegistry, fUnparsedElementRegistrySub, globalComp, currSchemaDoc);
+ checkForDuplicateNames(qName, ELEMENT_TYPE, fUnparsedElementRegistry, fUnparsedElementRegistrySub, globalComp, currSchemaDoc);
}
else if (componentType.equals(SchemaSymbols.ELT_GROUP)) {
- checkForDuplicateNames(qName, fUnparsedGroupRegistry, fUnparsedGroupRegistrySub, globalComp, currSchemaDoc);
+ checkForDuplicateNames(qName, GROUP_TYPE, fUnparsedGroupRegistry, fUnparsedGroupRegistrySub, globalComp, currSchemaDoc);
}
else if (componentType.equals(SchemaSymbols.ELT_NOTATION)) {
- checkForDuplicateNames(qName, fUnparsedNotationRegistry, fUnparsedNotationRegistrySub, globalComp, currSchemaDoc);
+ checkForDuplicateNames(qName, NOTATION_TYPE, fUnparsedNotationRegistry, fUnparsedNotationRegistrySub, globalComp, currSchemaDoc);
}
}
} // end for
@@ -1416,7 +1458,112 @@
"Internal-Error",
"st-props-correct.2", //or ct-props-correct.3
};
-
+
+ // add a global attribute decl from a current schema load (only if no existing decl is found)
+ void addGlobalAttributeDecl(XSAttributeDecl decl) {
+ final String namespace = decl.getNamespace();
+ final String declKey = (namespace == null || namespace.length() == 0)
+ ? "," + decl.getName() : namespace + "," + decl.getName();
+
+ if (fGlobalAttrDecls.get(declKey) == null) {
+ fGlobalAttrDecls.put(declKey, decl);
+ }
+ }
+
+ // add a global attribute group decl from a current schema load (only if no existing decl is found)
+ void addGlobalAttributeGroupDecl(XSAttributeGroupDecl decl) {
+ final String namespace = decl.getNamespace();
+ final String declKey = (namespace == null || namespace.length() == 0)
+ ? "," + decl.getName() : namespace + "," + decl.getName();
+
+ if (fGlobalAttrGrpDecls.get(declKey) == null) {
+ fGlobalAttrGrpDecls.put(declKey, decl);
+ }
+ }
+
+ // add a global element decl from a current schema load (only if no existing decl is found)
+ void addGlobalElementDecl(XSElementDecl decl) {
+ final String namespace = decl.getNamespace();
+ final String declKey = (namespace == null || namespace.length() == 0)
+ ? "," + decl.getName() : namespace + "," + decl.getName();
+
+ if (fGlobalElemDecls.get(declKey) == null) {
+ fGlobalElemDecls.put(declKey, decl);
+ }
+ }
+
+ // add a global group decl from a current schema load (only if no existing decl is found)
+ void addGlobalGroupDecl(XSGroupDecl decl) {
+ final String namespace = decl.getNamespace();
+ final String declKey = (namespace == null || namespace.length() == 0)
+ ? "," + decl.getName() : namespace + "," + decl.getName();
+
+ if (fGlobalGroupDecls.get(declKey) == null) {
+ fGlobalGroupDecls.put(declKey, decl);
+ }
+ }
+
+ // add a global notation decl from a current schema load (only if no existing decl is found)
+ void addGlobalNotationDecl(XSNotationDecl decl) {
+ final String namespace = decl.getNamespace();
+ final String declKey = (namespace == null || namespace.length() == 0)
+ ? "," + decl.getName() : namespace + "," + decl.getName();
+
+ if (fGlobalNotationDecls.get(declKey) == null) {
+ fGlobalNotationDecls.put(declKey, decl);
+ }
+ }
+
+ // add a global type decl from a current schema load (only if no existing decl is found)
+ void addGlobalTypeDecl(XSTypeDefinition decl) {
+ final String namespace = decl.getNamespace();
+ final String declKey = (namespace == null || namespace.length() == 0)
+ ? "," + decl.getName() : namespace + "," + decl.getName();
+
+ if (fGlobalTypeDecls.get(declKey) == null) {
+ fGlobalTypeDecls.put(declKey, decl);
+ }
+ }
+
+ // add a identity constraint decl from a current schema load (only if no existing decl is found)
+ void addIDConstraintDecl(IdentityConstraint decl) {
+ final String namespace = decl.getNamespace();
+ final String declKey = (namespace == null || namespace.length() == 0)
+ ? "," + decl.getIdentityConstraintName() : namespace + "," + decl.getIdentityConstraintName();
+
+ if (fGlobalIDConstraintDecls.get(declKey) == null) {
+ fGlobalIDConstraintDecls.put(declKey, decl);
+ }
+ }
+
+ private XSAttributeDecl getGlobalAttributeDecl(String declKey) {
+ return (XSAttributeDecl)fGlobalAttrDecls.get(declKey);
+ }
+
+ private XSAttributeGroupDecl getGlobalAttributeGroupDecl(String declKey) {
+ return (XSAttributeGroupDecl)fGlobalAttrGrpDecls.get(declKey);
+ }
+
+ private XSElementDecl getGlobalElementDecl(String declKey) {
+ return (XSElementDecl)fGlobalElemDecls.get(declKey);
+ }
+
+ private XSGroupDecl getGlobalGroupDecl(String declKey) {
+ return (XSGroupDecl)fGlobalGroupDecls.get(declKey);
+ }
+
+ private XSNotationDecl getGlobalNotationDecl(String declKey) {
+ return (XSNotationDecl)fGlobalNotationDecls.get(declKey);
+ }
+
+ private XSTypeDefinition getGlobalTypeDecl(String declKey) {
+ return (XSTypeDefinition)fGlobalTypeDecls.get(declKey);
+ }
+
+ private IdentityConstraint getIDConstraintDecl(String declKey) {
+ return (IdentityConstraint)fGlobalIDConstraintDecls.get(declKey);
+ }
+
// since it is forbidden for traversers to talk to each other
// directly (except wen a traverser encounters a local declaration),
// this provides a generic means for a traverser to call
@@ -1438,10 +1585,11 @@
int declType,
QName declToTraverse,
Element elmNode) {
-
+
if (DEBUG_NODE_POOL) {
System.out.println("TRAVERSE_GL: "+declToTraverse.toString());
}
+
// from the schema spec, all built-in types are present in all schemas,
// so if the requested component is a type, and could be found in the
// default schema grammar, we should return that type.
@@ -1455,7 +1603,7 @@
return retObj;
}
}
-
+
// now check whether this document can access the requsted namespace
if (!currSchema.isAllowedNS(declToTraverse.uri)) {
// cannot get to this schema from the one containing the requesting decl
@@ -1465,7 +1613,7 @@
}
return null;
}
-
+
// check whether there is grammar for the requested namespace
SchemaGrammar sGrammar = fGrammarBucket.getGrammar(declToTraverse.uri);
if (sGrammar == null) {
@@ -1476,29 +1624,27 @@
// if there is such grammar, check whether the requested component is in the grammar
Object retObj = getGlobalDeclFromGrammar(sGrammar, declType, declToTraverse.localpart);
+ String declKey = declToTraverse.uri == null? ","+declToTraverse.localpart:
+ declToTraverse.uri+","+declToTraverse.localpart;
// if the component is parsed, return it
- //if (!fNamespaceGrowth) {
+ if (!fTolerateDuplicates) {
if (retObj != null) {
return retObj;
}
- /*}
- // namespace growth is allowed, use schema location to get global component
- else if (null2EmptyString(declToTraverse.uri).equals(currSchema.fTargetNamespace)) {
- String schemaLoc = (String) fDoc2SystemId.get(currSchema.fSchemaElement);
- Object retObj2 = getGlobalDeclFromGrammar(sGrammar, declType, declToTraverse.localpart, schemaLoc);
+ }
+ else {
+ Object retObj2 = getGlobalDecl(declKey, declType);
if (retObj2 != null) {
return retObj2;
}
- }*/
+ }
XSDocumentInfo schemaWithDecl = null;
Element decl = null;
XSDocumentInfo declDoc = null;
// the component is not parsed, try to find a DOM element for it
- String declKey = declToTraverse.uri == null? ","+declToTraverse.localpart:
- declToTraverse.uri+","+declToTraverse.localpart;
switch (declType) {
case ATTRIBUTE_TYPE :
decl = (Element)fUnparsedAttributeRegistry.get(declKey);
@@ -1573,6 +1719,38 @@
return traverseGlobalDecl(declType, decl, schemaWithDecl, sGrammar);
} // getGlobalDecl(XSDocumentInfo, int, QName): Object
+ // If we are tolerating duplicate declarations and allowing namespace growth
+ // use the declaration from the current schema load (if it exists)
+ protected Object getGlobalDecl(String declKey, int declType) {
+ Object retObj = null;
+
+ switch (declType) {
+ case ATTRIBUTE_TYPE :
+ retObj = getGlobalAttributeDecl(declKey);
+ break;
+ case ATTRIBUTEGROUP_TYPE :
+ retObj = getGlobalAttributeGroupDecl(declKey);
+ break;
+ case ELEMENT_TYPE :
+ retObj = getGlobalElementDecl(declKey);
+ break;
+ case GROUP_TYPE :
+ retObj = getGlobalGroupDecl(declKey);
+ break;
+ case IDENTITYCONSTRAINT_TYPE :
+ retObj = getIDConstraintDecl(declKey);
+ break;
+ case NOTATION_TYPE :
+ retObj = getGlobalNotationDecl(declKey);
+ break;
+ case TYPEDECL_TYPE :
+ retObj = getGlobalTypeDecl(declKey);
+ break;
+ }
+
+ return retObj;
+ }
+
protected Object getGlobalDeclFromGrammar(SchemaGrammar sGrammar, int declType, String localpart) {
Object retObj = null;
@@ -1772,7 +1950,7 @@
if (keyrefName.length() != 0) {
String keyrefQName = schemaDoc.fTargetNamespace == null?
"," + keyrefName: schemaDoc.fTargetNamespace+","+keyrefName;
- checkForDuplicateNames(keyrefQName, fUnparsedIdentityConstraintRegistry, fUnparsedIdentityConstraintRegistrySub, keyrefToStore, schemaDoc);
+ checkForDuplicateNames(keyrefQName, IDENTITYCONSTRAINT_TYPE, fUnparsedIdentityConstraintRegistry, fUnparsedIdentityConstraintRegistrySub, keyrefToStore, schemaDoc);
}
// now set up all the registries we'll need...
@@ -1839,6 +2017,45 @@
} // StAXInputSource
return getSchemaDocument(desc.getTargetNamespace(), schemaSource, mustResolve, desc.getContextType(), referElement);
} // getSchema(String, String, String, boolean, short): Document
+
+ private Element resolveSchema(XMLInputSource schemaSource, XSDDescription desc,
+ boolean mustResolve, Element referElement) {
+
+ if (schemaSource instanceof DOMInputSource) {
+ return getSchemaDocument(desc.getTargetNamespace(), (DOMInputSource) schemaSource, mustResolve, desc.getContextType(), referElement);
+ } // DOMInputSource
+ else if (schemaSource instanceof SAXInputSource) {
+ return getSchemaDocument(desc.getTargetNamespace(), (SAXInputSource) schemaSource, mustResolve, desc.getContextType(), referElement);
+ } // SAXInputSource
+ else if (schemaSource instanceof StAXInputSource) {
+ return getSchemaDocument(desc.getTargetNamespace(), (StAXInputSource) schemaSource, mustResolve, desc.getContextType(), referElement);
+ } // StAXInputSource
+ return getSchemaDocument(desc.getTargetNamespace(), schemaSource, mustResolve, desc.getContextType(), referElement);
+ }
+
+ private XMLInputSource resolveSchemaSource(XSDDescription desc, boolean mustResolve,
+ Element referElement, boolean usePairs) {
+
+ XMLInputSource schemaSource = null;
+ try {
+ Hashtable pairs = usePairs ? fLocationPairs : EMPTY_TABLE;
+ schemaSource = XMLSchemaLoader.resolveDocument(desc, pairs, fEntityResolver);
+ }
+ catch (IOException ex) {
+ if (mustResolve) {
+ reportSchemaError("schema_reference.4",
+ new Object[]{desc.getLocationHints()[0]},
+ referElement);
+ }
+ else {
+ reportSchemaWarning("schema_reference.4",
+ new Object[]{desc.getLocationHints()[0]},
+ referElement);
+ }
+ }
+
+ return schemaSource;
+ }
/**
* getSchemaDocument method uses XMLInputSource to parse a schema document.
@@ -2220,7 +2437,7 @@
fHiddenNodes.clear();
fLastSchemaWasDuplicate = false;
}
-
+
// before traversing a schema's parse tree, need to reset all traversers and
// clear all registries
void prepareForTraverse() {
@@ -2288,6 +2505,14 @@
fRedefinedRestrictedAttributeGroupRegistry.clear();
fRedefinedRestrictedGroupRegistry.clear();
+
+ fGlobalAttrDecls.clear();
+ fGlobalAttrGrpDecls.clear();
+ fGlobalElemDecls.clear();
+ fGlobalGroupDecls.clear();
+ fGlobalNotationDecls.clear();
+ fGlobalIDConstraintDecls.clear();
+ fGlobalTypeDecls.clear();
}
public void setDeclPool (XSDeclarationPool declPool){
fDeclPool = declPool;
@@ -2347,6 +2572,12 @@
}
try {
+ fTolerateDuplicates = componentManager.getFeature(TOLERATE_DUPLICATES);
+ } catch (XMLConfigurationException e) {
+ fTolerateDuplicates = false;
+ }
+
+ try {
fSchemaParser.setFeature(
CONTINUE_AFTER_FATAL_ERROR,
fErrorReporter.getFeature(CONTINUE_AFTER_FATAL_ERROR));
@@ -2485,17 +2716,18 @@
* is a collision, it may be because we're redefining something we know about
* or because we've found the thing we're redefining.
*/
- void checkForDuplicateNames(String qName,
- Hashtable registry, Hashtable registry_sub, Element currComp,
- XSDocumentInfo currSchema) {
+ void checkForDuplicateNames(String qName, int declType,
+ Hashtable registry, Hashtable registry_sub, Element currComp,
+ XSDocumentInfo currSchema) {
Object objElem = null;
// REVISIT: when we add derivation checking, we'll have to make
// sure that ID constraint collisions don't necessarily result in error messages.
if ((objElem = registry.get(qName)) == null) {
- // just add it in!
- registry.put(qName, currComp);
- registry_sub.put(qName, currSchema);
-
+ // need to check whether we have a global declaration in the corresponding
+ // grammar
+ if (fNamespaceGrowth && !fTolerateDuplicates) {
+ checkForDuplicateNames(qName, declType, currComp);
+ }
}
else {
Element collidingElem = (Element)objElem;
@@ -2536,16 +2768,16 @@
}
// and take care of nested redefines by calling recursively:
if (currSchema.fTargetNamespace == null)
- checkForDuplicateNames(","+newName, registry, registry_sub, currComp, currSchema);
+ checkForDuplicateNames(","+newName, declType, registry, registry_sub, currComp, currSchema);
else
- checkForDuplicateNames(currSchema.fTargetNamespace+","+newName, registry, registry_sub, currComp, currSchema);
+ checkForDuplicateNames(currSchema.fTargetNamespace+","+newName, declType, registry, registry_sub, currComp, currSchema);
}
else { // we may be redefining the wrong schema
if (collidedWithRedefine) {
if (currSchema.fTargetNamespace == null)
- checkForDuplicateNames(","+newName, registry, registry_sub, currComp, currSchema);
+ checkForDuplicateNames(","+newName, declType, registry, registry_sub, currComp, currSchema);
else
- checkForDuplicateNames(currSchema.fTargetNamespace+","+newName, registry, registry_sub, currComp, currSchema);
+ checkForDuplicateNames(currSchema.fTargetNamespace+","+newName, declType, registry, registry_sub, currComp, currSchema);
}
else {
// error that redefined element in wrong schema
@@ -2554,11 +2786,33 @@
}
}
else {
- // we've just got a flat-out collision
- reportSchemaError("sch-props-correct.2", new Object []{qName}, currComp);
+ // we've just got a flat-out collision (we tolerate duplicate
+ // declarations, only if they are defined in different schema
+ // documents)
+ if (!fTolerateDuplicates || registry_sub.get(qName) == currSchema) {
+ reportSchemaError("sch-props-correct.2", new Object []{qName}, currComp);
+ }
}
}
+
+ // we always add it in (override previous info, if any)!
+ registry.put(qName, currComp);
+ registry_sub.put(qName, currSchema);
+
} // checkForDuplicateNames(String, Hashtable, Element, XSDocumentInfo):void
+
+ void checkForDuplicateNames(String qName, int declType, Element currComp) {
+ int namespaceEnd = qName.indexOf(',');
+ String namespace = qName.substring(0, namespaceEnd);
+ SchemaGrammar grammar = fGrammarBucket.getGrammar(emptyString2Null(namespace));
+
+ if (grammar != null) {
+ Object obj = getGlobalDeclFromGrammar(grammar, declType, qName.substring(namespaceEnd + 1));
+ if (obj != null) {
+ reportSchemaError("sch-props-correct.2", new Object []{qName}, currComp);
+ }
+ }
+ }
// the purpose of this method is to take the component of the
// specified type and rename references to itself so that they
Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDKeyrefTraverser.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDKeyrefTraverser.java?rev=784915&r1=784914&r2=784915&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDKeyrefTraverser.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDKeyrefTraverser.java Mon Jun 15 18:54:11 2009
@@ -93,17 +93,21 @@
} else {
// add key reference to element decl
// and stuff this in the grammar
- if (!fSchemaHandler.fNamespaceGrowth) {
+ if (grammar.getIDConstraintDecl(keyRef.getIdentityConstraintName()) == null) {
grammar.addIDConstraintDecl(element, keyRef);
}
- else {
+ if (fSchemaHandler.fTolerateDuplicates) {
final String loc = fSchemaHandler.schemaDocument2SystemId(schemaDoc);
- if (grammar.getIDConstraintDecl(keyRef.getIdentityConstraintName()) == null) {
- grammar.addIDConstraintDecl(element, keyRef);
- }
- if ((grammar.getIDConstraintDecl(keyRef.getIdentityConstraintName(), loc) == null)) {
+ final IdentityConstraint idc = grammar.getIDConstraintDecl(keyRef.getIdentityConstraintName(), loc);
+ if (idc == null) {
grammar.addIDConstraintDecl(element, keyRef, loc);
}
+ else {
+ if (idc instanceof KeyRef) {
+ keyRef = (KeyRef) idc;
+ }
+ }
+ fSchemaHandler.addIDConstraintDecl(keyRef);
}
}
}
Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDNotationTraverser.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDNotationTraverser.java?rev=784915&r1=784914&r2=784915&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDNotationTraverser.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDNotationTraverser.java Mon Jun 15 18:54:11 2009
@@ -106,17 +106,19 @@
reportSchemaError("s4s-elt-must-match.1", args, content);
}
- if (!fSchemaHandler.fNamespaceGrowth) {
+ if (grammar.getGlobalNotationDecl(notation.fName) == null) {
grammar.addGlobalNotationDecl(notation);
}
- else {
+ if (fSchemaHandler.fTolerateDuplicates) {
final String loc = fSchemaHandler.schemaDocument2SystemId(schemaDoc);
- if (grammar.getGlobalNotationDecl(notation.fName) == null) {
- grammar.addGlobalNotationDecl(notation);
- }
- if (grammar.getGlobalNotationDecl(notation.fName, loc) == null) {
+ final XSNotationDecl notation2 = grammar.getGlobalNotationDecl(notation.fName, loc);
+ if (notation2 == null) {
grammar.addGlobalNotationDecl(notation, loc);
}
+ else {
+ notation = notation2;
+ }
+ fSchemaHandler.addGlobalNotationDecl(notation);
}
fAttrChecker.returnAttrArray(attrValues, schemaDoc);
Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDSimpleTypeTraverser.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDSimpleTypeTraverser.java?rev=784915&r1=784914&r2=784915&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDSimpleTypeTraverser.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDSimpleTypeTraverser.java Mon Jun 15 18:54:11 2009
@@ -115,20 +115,24 @@
// don't add global components without name to the grammar
if (type != null) {
- if (!fSchemaHandler.fNamespaceGrowth) {
+ if (grammar.getGlobalTypeDecl(type.getName()) == null) {
grammar.addGlobalSimpleTypeDecl(type);
}
- else {
+ if (fSchemaHandler.fTolerateDuplicates) {
final String loc = fSchemaHandler.schemaDocument2SystemId(schemaDoc);
- if (grammar.getGlobalTypeDecl(type.getName()) == null) {
- grammar.addGlobalSimpleTypeDecl(type);
- }
- if (grammar.getGlobalTypeDecl(type.getName(), loc) == null) {
+ XSTypeDefinition type2 = grammar.getGlobalTypeDecl(type.getName(), loc);
+ if (type2 == null) {
grammar.addGlobalSimpleTypeDecl(type, loc);
}
+ else {
+ if (type2 instanceof XSSimpleType) {
+ type = (XSSimpleType) type2;
+ }
+ }
+ fSchemaHandler.addGlobalTypeDecl(type);
}
}
-
+
return type;
}
Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDUniqueOrKeyTraverser.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDUniqueOrKeyTraverser.java?rev=784915&r1=784914&r2=784915&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDUniqueOrKeyTraverser.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDUniqueOrKeyTraverser.java Mon Jun 15 18:54:11 2009
@@ -72,17 +72,21 @@
// add it to the schema, to avoid errors when processing the instance.
if (traverseIdentityConstraint(uniqueOrKey, uElem, schemaDoc, attrValues)) {
// and stuff this in the grammar
- if (!fSchemaHandler.fNamespaceGrowth) {
+ if (grammar.getIDConstraintDecl(uniqueOrKey.getIdentityConstraintName()) == null) {
grammar.addIDConstraintDecl(element, uniqueOrKey);
}
- else {
+ if (fSchemaHandler.fTolerateDuplicates) {
final String loc = fSchemaHandler.schemaDocument2SystemId(schemaDoc);
- if (grammar.getIDConstraintDecl(uniqueOrKey.getIdentityConstraintName()) == null) {
- grammar.addIDConstraintDecl(element, uniqueOrKey);
- }
- if (grammar.getIDConstraintDecl(uniqueOrKey.getIdentityConstraintName(), loc) == null) {
+ final IdentityConstraint idc = grammar.getIDConstraintDecl(uniqueOrKey.getIdentityConstraintName(), loc);
+ if (idc == null) {
grammar.addIDConstraintDecl(element, uniqueOrKey, loc);
}
+ else {
+ if (idc instanceof UniqueOrKey) {
+ uniqueOrKey = (UniqueOrKey) uniqueOrKey;
+ }
+ }
+ fSchemaHandler.addIDConstraintDecl(uniqueOrKey);
}
}
Modified: xerces/java/trunk/src/org/apache/xerces/parsers/DOMParserImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/parsers/DOMParserImpl.java?rev=784915&r1=784914&r2=784915&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/parsers/DOMParserImpl.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/parsers/DOMParserImpl.java Mon Jun 15 18:54:11 2009
@@ -118,6 +118,10 @@
protected static final String NAMESPACE_GROWTH =
Constants.XERCES_FEATURE_PREFIX + Constants.NAMESPACE_GROWTH_FEATURE;
+ /** Feature identifier: tolerate duplicates */
+ protected static final String TOLERATE_DUPLICATES =
+ Constants.XERCES_FEATURE_PREFIX + Constants.TOLERATE_DUPLICATES_FEATURE;
+
// internal properties
protected static final String SYMBOL_TABLE =
Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY;
@@ -458,6 +462,9 @@
else if (name.equals(NAMESPACE_GROWTH)) {
normalizedName = NAMESPACE_GROWTH;
}
+ else if (name.equals(TOLERATE_DUPLICATES)) {
+ normalizedName = TOLERATE_DUPLICATES;
+ }
else {
normalizedName = name.toLowerCase(Locale.ENGLISH);
}
@@ -596,6 +603,9 @@
else if (name.equals(NAMESPACE_GROWTH)) {
normalizedName = NAMESPACE_GROWTH;
}
+ else if (name.equals(TOLERATE_DUPLICATES)) {
+ normalizedName = TOLERATE_DUPLICATES;
+ }
fConfiguration.getFeature(normalizedName);
throw newTypeMismatchError(name);
@@ -729,6 +739,9 @@
else if (name.equals(NAMESPACE_GROWTH)) {
normalizedName = NAMESPACE_GROWTH;
}
+ else if (name.equals(TOLERATE_DUPLICATES)) {
+ normalizedName = TOLERATE_DUPLICATES;
+ }
else {
normalizedName = name.toLowerCase(Locale.ENGLISH);
}
@@ -793,7 +806,10 @@
}
else if (name.equalsIgnoreCase(NAMESPACE_GROWTH)) {
normalizedName = NAMESPACE_GROWTH;
- }
+ }
+ else if (name.equalsIgnoreCase(TOLERATE_DUPLICATES)) {
+ normalizedName = TOLERATE_DUPLICATES;
+ }
else {
normalizedName = name.toLowerCase(Locale.ENGLISH);
}
Modified: xerces/java/trunk/src/org/apache/xerces/parsers/StandardParserConfiguration.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/parsers/StandardParserConfiguration.java?rev=784915&r1=784914&r2=784915&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/parsers/StandardParserConfiguration.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/parsers/StandardParserConfiguration.java Mon Jun 15 18:54:11 2009
@@ -108,6 +108,10 @@
protected static final String NAMESPACE_GROWTH =
Constants.XERCES_FEATURE_PREFIX + Constants.NAMESPACE_GROWTH_FEATURE;
+ /** Feature identifier: tolerate duplicates */
+ protected static final String TOLERATE_DUPLICATES =
+ Constants.XERCES_FEATURE_PREFIX + Constants.TOLERATE_DUPLICATES_FEATURE;
+
/** Feature identifier: whether to ignore xsi:type attributes until a global element declaration is encountered */
protected static final String IGNORE_XSI_TYPE =
Constants.XERCES_FEATURE_PREFIX + Constants.IGNORE_XSI_TYPE_FEATURE;
@@ -215,6 +219,7 @@
VALIDATE_ANNOTATIONS,
HONOUR_ALL_SCHEMALOCATIONS,
NAMESPACE_GROWTH,
+ TOLERATE_DUPLICATES,
// NOTE: These shouldn't really be here but since the XML Schema
// validator is constructed dynamically, its recognized
// features might not have been set and it would cause a
@@ -236,7 +241,8 @@
setFeature(VALIDATE_ANNOTATIONS, false);
setFeature(HONOUR_ALL_SCHEMALOCATIONS, false);
setFeature(NAMESPACE_GROWTH, false);
-
+ setFeature(TOLERATE_DUPLICATES, false);
+
setFeature(IGNORE_XSI_TYPE, false);
setFeature(ID_IDREF_CHECKING, true);
setFeature(IDENTITY_CONSTRAINT_CHECKING, true);
Modified: xerces/java/trunk/src/org/apache/xerces/parsers/XML11Configuration.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/parsers/XML11Configuration.java?rev=784915&r1=784914&r2=784915&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/parsers/XML11Configuration.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/parsers/XML11Configuration.java Mon Jun 15 18:54:11 2009
@@ -149,11 +149,15 @@
/** Feature identifier: namespace growth */
protected static final String NAMESPACE_GROWTH =
Constants.XERCES_FEATURE_PREFIX + Constants.NAMESPACE_GROWTH_FEATURE;
+
+ /** Feature identifier: tolerate duplicates */
+ protected static final String TOLERATE_DUPLICATES =
+ Constants.XERCES_FEATURE_PREFIX + Constants.TOLERATE_DUPLICATES_FEATURE;
/** Feature identifier: use grammar pool only */
protected static final String USE_GRAMMAR_POOL_ONLY =
Constants.XERCES_FEATURE_PREFIX + Constants.USE_GRAMMAR_POOL_ONLY_FEATURE;
-
+
// feature identifiers
/** Feature identifier: validation. */
@@ -483,7 +487,8 @@
NAMESPACES,
NORMALIZE_DATA, SCHEMA_ELEMENT_DEFAULT, SCHEMA_AUGMENT_PSVI,
GENERATE_SYNTHETIC_ANNOTATIONS, VALIDATE_ANNOTATIONS,
- HONOUR_ALL_SCHEMALOCATIONS, NAMESPACE_GROWTH, IGNORE_XSI_TYPE,
+ HONOUR_ALL_SCHEMALOCATIONS, NAMESPACE_GROWTH,
+ TOLERATE_DUPLICATES, IGNORE_XSI_TYPE,
ID_IDREF_CHECKING, IDENTITY_CONSTRAINT_CHECKING,
UNPARSED_ENTITY_CHECKING, USE_GRAMMAR_POOL_ONLY,
// NOTE: These shouldn't really be here but since the XML Schema
@@ -511,6 +516,7 @@
fFeatures.put(VALIDATE_ANNOTATIONS, Boolean.FALSE);
fFeatures.put(HONOUR_ALL_SCHEMALOCATIONS, Boolean.FALSE);
fFeatures.put(NAMESPACE_GROWTH, Boolean.FALSE);
+ fFeatures.put(TOLERATE_DUPLICATES, Boolean.FALSE);
fFeatures.put(IGNORE_XSI_TYPE, Boolean.FALSE);
fFeatures.put(ID_IDREF_CHECKING, Boolean.TRUE);
fFeatures.put(IDENTITY_CONSTRAINT_CHECKING, Boolean.TRUE);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org