Author: mrglavas
Date: Sun Nov 16 21:36:50 2008
New Revision: 718173
URL: http://svn.apache.org/viewvc?rev=718173&view=rev
Log:
JIRA Issue #1338:
http://issues.apache.org/jira/browse/XERCESJ-1338
Implementation of the "root-element-declaration" property. It allows the user
to specify the element
declaration to use for validating the validation root (not necessarily the root
element of the document).
Its value must either be a javax.xml.namespace.QName or a
org.apache.xerces.xs.XSElementDeclaration.
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/Constants.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/parsers/StandardParserConfiguration.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/parsers/XML11Configuration.java
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/Constants.java
URL:
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/Constants.java?rev=718173&r1=718172&r2=718173&view=diff
==============================================================================
---
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/Constants.java
(original)
+++
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/Constants.java
Sun Nov 16 21:36:50 2008
@@ -422,6 +422,9 @@
/** Schema type of the root element in a document
("validation/schema/root-type-definition"). */
public static final String ROOT_TYPE_DEFINITION_PROPERTY =
"validation/schema/root-type-definition";
+
+ /** Schema element declaration for the root element in a document
("validation/schema/root-element-declaration"). */
+ public static final String ROOT_ELEMENT_DECLARATION_PROPERTY =
"validation/schema/root-element-declaration";
/** Datatype XML version property
("validation/schema/datatype-xml-version"). */
public static final String XML_SCHEMA_VERSION_PROPERTY
="validation/schema/version";
@@ -545,7 +548,8 @@
SECURITY_MANAGER_PROPERTY,
LOCALE_PROPERTY,
ROOT_TYPE_DEFINITION_PROPERTY,
- XML_SCHEMA_VERSION_PROPERTY
+ ROOT_ELEMENT_DECLARATION_PROPERTY,
+ XML_SCHEMA_VERSION_PROPERTY,
};
/** Empty enumeration. */
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java
URL:
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java?rev=718173&r1=718172&r2=718173&view=diff
==============================================================================
---
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java
(original)
+++
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java
Sun Nov 16 21:36:50 2008
@@ -237,6 +237,10 @@
/** Property identifier: root type definition. */
protected static final String ROOT_TYPE_DEF =
Constants.XERCES_PROPERTY_PREFIX +
Constants.ROOT_TYPE_DEFINITION_PROPERTY;
+
+ /** Property identifier: root element declaration. */
+ protected static final String ROOT_ELEMENT_DECL =
+ Constants.XERCES_PROPERTY_PREFIX +
Constants.ROOT_ELEMENT_DECLARATION_PROPERTY;
/** Property identifier: xml schema version. */
protected static final String XML_SCHEMA_VERSION =
@@ -307,12 +311,13 @@
JAXP_SCHEMA_SOURCE,
JAXP_SCHEMA_LANGUAGE,
ROOT_TYPE_DEF,
- XML_SCHEMA_VERSION
+ ROOT_ELEMENT_DECL,
+ XML_SCHEMA_VERSION,
};
/** Property defaults. */
private static final Object[] PROPERTY_DEFAULTS =
- { null, null, null, null, null, null, null, null, null, null };
+ { null, null, null, null, null, null, null, null, null, null, null, };
// this is the number of valuestores of each kind
// we expect an element to have. It's almost
@@ -583,6 +588,20 @@
fRootTypeQName = null;
}
}
+ else if (propertyId.equals(ROOT_ELEMENT_DECL)) {
+ if (value == null) {
+ fRootElementDeclQName = null;
+ fRootElementDeclaration = null;
+ }
+ else if (value instanceof javax.xml.namespace.QName) {
+ fRootElementDeclQName = (javax.xml.namespace.QName) value;
+ fRootElementDeclaration = null;
+ }
+ else {
+ fRootElementDeclaration = (XSElementDecl) value;
+ fRootElementDeclQName = null;
+ }
+ }
else if (propertyId.equals(XML_SCHEMA_VERSION)) {
// TODO: do we use fSchemaLoader.setProperty
fSchemaLoader.setSchemaVersion((String)value);
@@ -1243,9 +1262,14 @@
/** temporary qname */
private final QName fTempQName = new QName();
+ /** value of the "root-type-definition" property. */
private javax.xml.namespace.QName fRootTypeQName = null;
private XSTypeDefinition fRootTypeDefinition = null;
+ /** value of the "root-element-declaration" property. */
+ private javax.xml.namespace.QName fRootElementDeclQName = null;
+ private XSElementDecl fRootElementDeclaration = null;
+
private int fIgnoreXSITypeDepth;
private boolean fIDCChecking;
@@ -1461,6 +1485,26 @@
fRootTypeDefinition = null;
}
+ try {
+ final Object rootDecl =
componentManager.getProperty(ROOT_ELEMENT_DECL);
+ if (rootDecl == null) {
+ fRootElementDeclQName = null;
+ fRootElementDeclaration = null;
+ }
+ else if (rootDecl instanceof javax.xml.namespace.QName) {
+ fRootElementDeclQName = (javax.xml.namespace.QName) rootDecl;
+ fRootElementDeclaration = null;
+ }
+ else {
+ fRootElementDeclaration = (XSElementDecl) rootDecl;
+ fRootElementDeclQName = null;
+ }
+ }
+ catch (XMLConfigurationException e) {
+ fRootElementDeclQName = null;
+ fRootElementDeclaration = null;
+ }
+
boolean ignoreXSIType;
try {
ignoreXSIType = componentManager.getFeature(IGNORE_XSI_TYPE);
@@ -1956,32 +2000,20 @@
return augs;
}
- // 1.2.1.1 A type definition was stipulated by the processor
if (fElementDepth == 0) {
+ // 1.2.1.1 A type definition was stipulated by the processor
if (fRootTypeDefinition != null) {
fCurrentType = fRootTypeDefinition;
}
else if (fRootTypeQName != null) {
- String rootTypeNamespace = fRootTypeQName.getNamespaceURI();
- if (rootTypeNamespace != null &&
rootTypeNamespace.equals(XMLConstants.NULL_NS_URI)) {
- rootTypeNamespace = null;
- }
- if
(SchemaSymbols.URI_SCHEMAFORSCHEMA.equals(rootTypeNamespace)) {
- fCurrentType =
SchemaGrammar.SG_SchemaNS.getGlobalTypeDecl(fRootTypeQName.getLocalPart());
- }
- else {
- SchemaGrammar grammarForRootType = findSchemaGrammar(
- XSDDescription.CONTEXT_ELEMENT, rootTypeNamespace,
null, null, null);
- if (grammarForRootType != null) {
- fCurrentType =
grammarForRootType.getGlobalTypeDecl(fRootTypeQName.getLocalPart());
- }
- }
- if (fCurrentType == null) {
- String typeName =
(fRootTypeQName.getPrefix().equals(XMLConstants.DEFAULT_NS_PREFIX)) ?
- fRootTypeQName.getLocalPart() :
-
fRootTypeQName.getPrefix()+":"+fRootTypeQName.getLocalPart();
- reportSchemaError("cvc-type.1", new Object[]
{typeName});
- }
+ processRootTypeQName();
+ }
+ // 1.1.1.1 An element declaration was stipulated by the processor
+ else if (fRootElementDeclaration != null) {
+ fCurrentElemDecl = fRootElementDeclaration;
+ }
+ else if (fRootElementDeclQName != null) {
+ processRootElementDeclQName();
}
}
@@ -3379,6 +3411,47 @@
}
return actualValue;
} // elementLocallyValidComplexType
+
+ void processRootTypeQName() {
+ String rootTypeNamespace = fRootTypeQName.getNamespaceURI();
+ if (rootTypeNamespace != null &&
rootTypeNamespace.equals(XMLConstants.NULL_NS_URI)) {
+ rootTypeNamespace = null;
+ }
+ if (SchemaSymbols.URI_SCHEMAFORSCHEMA.equals(rootTypeNamespace)) {
+ fCurrentType =
SchemaGrammar.SG_SchemaNS.getGlobalTypeDecl(fRootTypeQName.getLocalPart());
+ }
+ else {
+ final SchemaGrammar grammarForRootType = findSchemaGrammar(
+ XSDDescription.CONTEXT_ELEMENT, rootTypeNamespace, null,
null, null);
+ if (grammarForRootType != null) {
+ fCurrentType =
grammarForRootType.getGlobalTypeDecl(fRootTypeQName.getLocalPart());
+ }
+ }
+ if (fCurrentType == null) {
+ String typeName =
(fRootTypeQName.getPrefix().equals(XMLConstants.DEFAULT_NS_PREFIX)) ?
+ fRootTypeQName.getLocalPart() :
+
fRootTypeQName.getPrefix()+":"+fRootTypeQName.getLocalPart();
+ reportSchemaError("cvc-type.1", new Object[] {typeName});
+ }
+ } // processRootTypeQName
+
+ void processRootElementDeclQName() {
+ String rootElementDeclNamespace =
fRootElementDeclQName.getNamespaceURI();
+ if (rootElementDeclNamespace != null &&
rootElementDeclNamespace.equals(XMLConstants.NULL_NS_URI)) {
+ rootElementDeclNamespace = null;
+ }
+ final SchemaGrammar grammarForRootElement = findSchemaGrammar(
+ XSDDescription.CONTEXT_ELEMENT, rootElementDeclNamespace,
null, null, null);
+ if (grammarForRootElement != null) {
+ fCurrentElemDecl =
grammarForRootElement.getGlobalElementDecl(fRootElementDeclQName.getLocalPart());
+ }
+ if (fCurrentElemDecl == null) {
+ String declName =
(fRootElementDeclQName.getPrefix().equals(XMLConstants.DEFAULT_NS_PREFIX)) ?
+ fRootElementDeclQName.getLocalPart() :
+
fRootElementDeclQName.getPrefix()+":"+fRootElementDeclQName.getLocalPart();
+ reportSchemaError("cvc-elt.1", new Object[] {declName});
+ }
+ } // processRootElementDeclQName
void reportSchemaError(String key, Object[] arguments) {
if (fDoValidation)
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/parsers/StandardParserConfiguration.java
URL:
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/parsers/StandardParserConfiguration.java?rev=718173&r1=718172&r2=718173&view=diff
==============================================================================
---
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/parsers/StandardParserConfiguration.java
(original)
+++
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/parsers/StandardParserConfiguration.java
Sun Nov 16 21:36:50 2008
@@ -141,6 +141,10 @@
/** Property identifier: root type definition. */
protected static final String ROOT_TYPE_DEF =
Constants.XERCES_PROPERTY_PREFIX +
Constants.ROOT_TYPE_DEFINITION_PROPERTY;
+
+ /** Property identifier: root element declaration. */
+ protected static final String ROOT_ELEMENT_DECL =
+ Constants.XERCES_PROPERTY_PREFIX +
Constants.ROOT_ELEMENT_DECLARATION_PROPERTY;
//
// Data
@@ -248,6 +252,7 @@
SCHEMA_LOCATION,
SCHEMA_NONS_LOCATION,
ROOT_TYPE_DEF,
+ ROOT_ELEMENT_DECL,
};
addRecognizedProperties(recognizedProperties);
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/parsers/XML11Configuration.java
URL:
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/parsers/XML11Configuration.java?rev=718173&r1=718172&r2=718173&view=diff
==============================================================================
---
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/parsers/XML11Configuration.java
(original)
+++
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/parsers/XML11Configuration.java
Sun Nov 16 21:36:50 2008
@@ -277,6 +277,10 @@
/** Property identifier: root type definition. */
protected static final String ROOT_TYPE_DEF =
Constants.XERCES_PROPERTY_PREFIX +
Constants.ROOT_TYPE_DEFINITION_PROPERTY;
+
+ /** Property identifier: root element declaration. */
+ protected static final String ROOT_ELEMENT_DECL =
+ Constants.XERCES_PROPERTY_PREFIX +
Constants.ROOT_ELEMENT_DECLARATION_PROPERTY;
// debugging
@@ -541,6 +545,7 @@
SCHEMA_NONS_LOCATION,
LOCALE,
ROOT_TYPE_DEF,
+ ROOT_ELEMENT_DECL,
};
addRecognizedProperties(recognizedProperties);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]