Author: mukulg
Date: Sat Jan 15 08:18:25 2011
New Revision: 1059272

URL: http://svn.apache.org/viewvc?rev=1059272&view=rev
Log:
committing few improvements related to processing of QName lists (the QName 
strings must be in correct lexical form, and the prefixes must be declared in 
the schema) involved in conditional inclusion namespace (vc:).

This improvement passes few additional tests specified in W3C XML Schema 1.1 
test suite (specifically vc904.xsd & vc905.xsd).

The commit also includes few minor javadoc improvements.

Modified:
    
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/opti/SchemaDOMParser.java
    
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAttributeTraverser.java
    
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSTypeHelper.java

Modified: 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/opti/SchemaDOMParser.java
URL: 
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/opti/SchemaDOMParser.java?rev=1059272&r1=1059271&r2=1059272&view=diff
==============================================================================
--- 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/opti/SchemaDOMParser.java
 (original)
+++ 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/opti/SchemaDOMParser.java
 Sat Jan 15 08:18:25 2011
@@ -17,17 +17,18 @@
 
 package org.apache.xerces.impl.xs.opti;
 
-import java.util.Iterator;
-import java.util.List;
-import java.util.StringTokenizer;
 import java.io.IOException;
 import java.math.BigDecimal;
 import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.StringTokenizer;
 
 import org.apache.xerces.impl.Constants;
 import org.apache.xerces.impl.XMLErrorReporter;
 import org.apache.xerces.impl.xs.SchemaSymbols;
 import org.apache.xerces.impl.xs.XSMessageFormatter;
+import org.apache.xerces.impl.xs.util.XSTypeHelper;
 import org.apache.xerces.util.XMLAttributesImpl;
 import org.apache.xerces.util.XMLChar;
 import org.apache.xerces.xni.Augmentations;
@@ -655,16 +656,16 @@ public class SchemaDOMParser extends Def
                     }
                 }
                 else if 
(SchemaSymbols.ATT_TYPEAVAILABLE.equals(attrLocalName)) {
-                   typeAvailableList = tokenizeString(attrValue);
+                   typeAvailableList = tokenizeQNameListString(attrValue);
                 }
                 else if 
(SchemaSymbols.ATT_TYPEUNAVAILABLE.equals(attrLocalName)) {
-                    typeUnavailableList = tokenizeString(attrValue);
+                    typeUnavailableList = tokenizeQNameListString(attrValue);
                 }
                 else if 
(SchemaSymbols.ATT_FACETAVAILABLE.equals(attrLocalName)) {
-                    facetAvailableList = tokenizeString(attrValue);
+                    facetAvailableList = tokenizeQNameListString(attrValue);
                 }
                 else if 
(SchemaSymbols.ATT_FACETUNAVAILABLE.equals(attrLocalName)) {
-                    facetUnavailableList = tokenizeString(attrValue);
+                    facetUnavailableList = tokenizeQNameListString(attrValue);
                 }
                 else {
                     // report a warning
@@ -826,20 +827,24 @@ public class SchemaDOMParser extends Def
 
     
     /*
-     * Method to tokenize a string value (with XML white spaces as the 
delimiter) and return a List
+     * Method to tokenize a QName list specified as a string value (with XML 
white spaces as the delimiter) and return a List
      * containing the string tokens. 
      */
-    private List tokenizeString(String strValue) {
+    private List tokenizeQNameListString(String strValue) {
         
         StringTokenizer st = new StringTokenizer(strValue, " \n\t\r");
         List stringTokens = new ArrayList(st.countTokens());
+        
         while (st.hasMoreTokens()) {
-           stringTokens.add(st.nextToken());
+           String QNameStr = st.nextToken();
+           XSTypeHelper.validateQNameValue(QNameStr, fNamespaceContext, 
fErrorReporter);          
+           stringTokens.add(QNameStr);
         }
+        
         return stringTokens;
         
-    } // tokenizeString
-    
+    } // tokenizeQNameListString
+
 
     /**
      * A simple boolean based stack.

Modified: 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAttributeTraverser.java
URL: 
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAttributeTraverser.java?rev=1059272&r1=1059271&r2=1059272&view=diff
==============================================================================
--- 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAttributeTraverser.java
 (original)
+++ 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAttributeTraverser.java
 Sat Jan 15 08:18:25 2011
@@ -96,7 +96,7 @@ class XSDAttributeTraverser extends XSDA
                     attribute = 
getAttributeDeclForXSINamespace(refAtt.localpart, enclosingParent, 
schemaFactory); 
                 }
                 else {
-                   attribute = 
(XSAttributeDecl)fSchemaHandler.getGlobalDecl(schemaDoc, 
XSDHandler.ATTRIBUTE_TYPE, refAtt, attrDecl);
+                    attribute = 
(XSAttributeDecl)fSchemaHandler.getGlobalDecl(schemaDoc, 
XSDHandler.ATTRIBUTE_TYPE, refAtt, attrDecl);
                 }
                 
                 Element child = DOMUtil.getFirstChildElement(attrDecl);
@@ -231,7 +231,7 @@ class XSDAttributeTraverser extends XSDA
     }
     
     /*
-     * Construct an XSAttributeDecl object for attributes in the namespace 
http://www.w3.org/2001/XMLSchema-instance 
+     * Construct an XSAttributeDecl object for attributes in the namespace 
http://www.w3.org/2001/XMLSchema-instance.
      */
     private XSAttributeDecl getAttributeDeclForXSINamespace(String localpart, 
XSObject enclosingParent, SchemaDVFactory schemaFactory) {
         

Modified: 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSTypeHelper.java
URL: 
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSTypeHelper.java?rev=1059272&r1=1059271&r2=1059272&view=diff
==============================================================================
--- 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSTypeHelper.java
 (original)
+++ 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSTypeHelper.java
 Sat Jan 15 08:18:25 2011
@@ -17,12 +17,16 @@
 
 package org.apache.xerces.impl.xs.util;
 
+import org.apache.xerces.impl.XMLErrorReporter;
 import org.apache.xerces.impl.dv.InvalidDatatypeValueException;
 import org.apache.xerces.impl.dv.ValidatedInfo;
 import org.apache.xerces.impl.dv.ValidationContext;
 import org.apache.xerces.impl.dv.XSSimpleType;
 import org.apache.xerces.impl.validation.ValidationState;
 import org.apache.xerces.impl.xs.SchemaSymbols;
+import org.apache.xerces.impl.xs.XSMessageFormatter;
+import org.apache.xerces.util.XMLChar;
+import org.apache.xerces.xni.NamespaceContext;
 import org.apache.xerces.xs.XSObjectList;
 import org.apache.xerces.xs.XSTypeDefinition;
 
@@ -36,6 +40,8 @@ import org.apache.xerces.xs.XSTypeDefini
  */
 public class XSTypeHelper {
     
+    private static final String EMPTY_STRING = "".intern();
+    
     
     /*
      * Checks if the two schema type components are identical.
@@ -80,8 +86,7 @@ public class XSTypeHelper {
      * If this method returns 'true', then the value is valid with respect to 
entire union 
      * schema component. 
      */
-    public static boolean isAtomicValueValidForAnUnion(XSObjectList 
memberTypes, String content, 
-                                                       ValidatedInfo 
validatedInfo) {
+    public static boolean isAtomicValueValidForAnUnion(XSObjectList 
memberTypes, String content, ValidatedInfo validatedInfo) {
         
         boolean isValid = false;
         
@@ -104,9 +109,8 @@ public class XSTypeHelper {
     
     
     /*
-     * Determine if a lexical "string value" belongs to the value space (i.e 
is valid
-     * according to the type) of a given schema simpleType definition. Using 
Xerces API
-     * 'XSSimpleType.validate' for this need.
+     * Determine if a lexical "string value" belongs to the value space (i.e 
is valid according to the type) of a given schema 
+     * simpleType definition. Using Xerces API 'XSSimpleType.validate' for 
this need.
      */
     public static boolean isValueValidForASimpleType(String value, 
XSSimpleType simplType) {
         
@@ -126,6 +130,43 @@ public class XSTypeHelper {
         
         return isValueValid;
         
-    } // isValueValidForASimpleType    
+    } // isValueValidForASimpleType
+    
+    
+    /*
+     * Validate a QName value (it should be in correct lexical form, and it's 
prefix must be declared), and report
+     * errors as found.
+     */
+    public static void validateQNameValue(String qNameStr, NamespaceContext 
namespaceContext, XMLErrorReporter errorReporter) {
+        
+        String prefix, localpart;
+        int colonptr = qNameStr.indexOf(":");
+        if (colonptr > 0) {
+            prefix = qNameStr.substring(0, colonptr);
+            localpart = qNameStr.substring(colonptr + 1);
+        } else {
+            prefix = EMPTY_STRING;
+            localpart = qNameStr;
+        }
+        
+        // both prefix (if any) and localpart must be valid NCName
+        if (prefix.length() > 0 && !XMLChar.isValidNCName(prefix)) {
+            errorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN, 
"cvc-datatype-valid.1.2.1",
+                                      new Object[] {qNameStr, "QName"}, 
XMLErrorReporter.SEVERITY_ERROR);
+        }
+
+        if(!XMLChar.isValidNCName(localpart)) {
+            errorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN, 
"cvc-datatype-valid.1.2.1",
+                                      new Object[] {qNameStr, "QName"}, 
XMLErrorReporter.SEVERITY_ERROR);
+        }
+
+        // resove prefix to a uri, report an error if failed
+        String uri = namespaceContext.getURI(prefix.intern());
+        if (prefix.length() > 0 && uri == null) {
+            errorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN, 
"UndeclaredPrefix",
+                                      new Object[] {qNameStr, prefix}, 
XMLErrorReporter.SEVERITY_ERROR);
+        }
+        
+    } // validateQNameValue
     
 } // class XSTypeHelper



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to