Author: mrglavas
Date: Sun Nov 16 21:36:07 2008
New Revision: 718172

URL: http://svn.apache.org/viewvc?rev=718172&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/trunk/src/org/apache/xerces/impl/Constants.java
    xerces/java/trunk/src/org/apache/xerces/impl/xs/XMLSchemaValidator.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/impl/Constants.java
URL: 
http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/Constants.java?rev=718172&r1=718171&r2=718172&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/Constants.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/Constants.java Sun Nov 16 
21:36:07 2008
@@ -413,9 +413,12 @@
     /** Validation manager property ("internal/validation-manager"). */
     public static final String VALIDATION_MANAGER_PROPERTY = 
"internal/validation-manager";
     
-    /** Schema type of the root element in a document 
("validation/schema/root-type-definition"). */
+    /** Schema type for 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";
+    
     // general constants
     
     /** Element PSVI is stored in augmentations using string "ELEMENT_PSVI" */
@@ -534,6 +537,7 @@
             SECURITY_MANAGER_PROPERTY,
             LOCALE_PROPERTY,
             ROOT_TYPE_DEFINITION_PROPERTY,
+            ROOT_ELEMENT_DECLARATION_PROPERTY,
     };
     
     /** Empty enumeration. */

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=718172&r1=718171&r2=718172&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 Sun 
Nov 16 21:36:07 2008
@@ -231,6 +231,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;
 
     // recognized features and properties
 
@@ -295,11 +299,12 @@
             JAXP_SCHEMA_SOURCE,
             JAXP_SCHEMA_LANGUAGE,
             ROOT_TYPE_DEF,
+            ROOT_ELEMENT_DECL,
         };
 
     /** 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, };
 
     // this is the number of valuestores of each kind
     // we expect an element to have.  It's almost
@@ -565,6 +570,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;
+            }
+        }
     } // setProperty(String,Object)
 
     /**
@@ -1219,9 +1238,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;
@@ -1433,6 +1457,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);
@@ -1919,32 +1963,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();
             }
         }
         
@@ -3300,6 +3332,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/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=718172&r1=718171&r2=718172&view=diff
==============================================================================
--- 
xerces/java/trunk/src/org/apache/xerces/parsers/StandardParserConfiguration.java
 (original)
+++ 
xerces/java/trunk/src/org/apache/xerces/parsers/StandardParserConfiguration.java
 Sun Nov 16 21:36:07 2008
@@ -137,6 +137,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
@@ -242,6 +246,7 @@
             SCHEMA_LOCATION,
             SCHEMA_NONS_LOCATION,
             ROOT_TYPE_DEF,
+            ROOT_ELEMENT_DECL,
         };
         
         addRecognizedProperties(recognizedProperties);

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=718172&r1=718171&r2=718172&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/parsers/XML11Configuration.java 
(original)
+++ xerces/java/trunk/src/org/apache/xerces/parsers/XML11Configuration.java Sun 
Nov 16 21:36:07 2008
@@ -274,6 +274,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
 
@@ -536,6 +540,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]

Reply via email to