Author: mukulg
Date: Sun Aug  1 03:25:46 2010
New Revision: 981126

URL: http://svn.apache.org/viewvc?rev=981126&view=rev
Log:
doing refactoring for assertions processing (forking assertions logic into a 
separate class). i thought this was good for better modularity, which eases 
maintenance of the code-base.

Added:
    
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDAssertionValidator.java
Modified:
    
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java
    
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java

Modified: 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java
URL: 
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java?rev=981126&r1=981125&r2=981126&view=diff
==============================================================================
--- 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java
 (original)
+++ 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java
 Sun Aug  1 03:25:46 2010
@@ -17,6 +17,7 @@
 
 package org.apache.xerces.impl.xs;
 
+import java.util.List;
 import java.util.Map;
 import java.util.Stack;
 import java.util.Vector;
@@ -74,11 +75,11 @@ public class XMLAssertPsychopathImpl ext
     // changes as per the XNI document events.
     Element currentAssertDomNode = null;
 
-    // a stack holding the DOM root for assertions evaluation
+    // a stack holding the DOM roots for assertions evaluation
     Stack assertRootStack = null;
 
     // a stack parallel to 'assertRootStack' storing all assertions for a
-    // single assert tree.
+    // single XDM tree.
     Stack assertListStack = null;
 
     // XMLSchemaValidator reference. set from the XMLSchemaValidator object
@@ -92,14 +93,14 @@ public class XMLAssertPsychopathImpl ext
     /*
      * Class constructor
      */
-    public XMLAssertPsychopathImpl(Map assertParams) {
+    public XMLAssertPsychopathImpl(Map assertParams) {        
         // initializing the class variables.        
-        // we use the PSVI enabled DOM implementation, so as to have typed
+        // we use a PSVI enabled DOM implementation, to be able to have typed
         // XDM nodes.
         this.assertDocument = new PSVIDocumentImpl();        
         this.assertRootStack = new Stack();
         this.assertListStack = new Stack();
-        this.assertParams = assertParams;  
+        this.assertParams = assertParams;        
     }
     
 
@@ -107,6 +108,7 @@ public class XMLAssertPsychopathImpl ext
      * Initialize the PsychoPath XPath processor
      */
     private void initXPathProcessor() throws Exception {
+        
         validator = (XMLSchemaValidator) getProperty
                         ("http://apache.org/xml/properties/assert/validator";); 
       
         abstrPsychopathImpl = new AbstractPsychoPathImpl();
@@ -156,12 +158,12 @@ public class XMLAssertPsychopathImpl ext
             currentAssertDomNode.setAttributeNode(attrNode);
         }
 
-        Object assertion = augs.getItem("ASSERT");
-        // if we have assertion applicable to this element, store the element
-        // reference and the assertions on it, on the runtime stacks
-        if (assertion != null) {
+        List assertionList = (List) augs.getItem("ASSERT");
+        // if we have assertions applicable to this element, store the element
+        // reference and the assertions on it, on the runtime stacks.
+        if (assertionList != null) {
             assertRootStack.push(currentAssertDomNode);
-            assertListStack.push(assertion);
+            assertListStack.push(assertionList);
         }
         
     } // startElement
@@ -189,7 +191,7 @@ public class XMLAssertPsychopathImpl ext
                  // pop the stack, to go one level up
                  assertRootStack.pop();
                  // get assertions, and go one level up
-                 Object assertions = assertListStack.pop(); 
+                 List assertions = (List) assertListStack.pop(); 
                  
                  processAllAssertionsOnElement(element, assertions);
             }
@@ -208,10 +210,10 @@ public class XMLAssertPsychopathImpl ext
      */
     private void processAllAssertionsOnElement(
                                     QName element,
-                                    Object assertions)
+                                    List assertions)
                                     throws Exception {
          
-        // initialize the XPath engine
+         // initialize the XPath engine
          initXPathProcessor();
          
          // determine value of variable, $value
@@ -235,7 +237,7 @@ public class XMLAssertPsychopathImpl ext
 
          // evaluate assertions
          if (assertions instanceof XSObjectList) {
-            // assertions from a complex type definition
+            // assertions from a complex type definition             
             if (value != null) {
               // complex type with simple content
               setValueOf$value(value, null);
@@ -283,11 +285,13 @@ public class XMLAssertPsychopathImpl ext
      *      (org.apache.xerces.xni.XMLString)
      */
     public void characters(XMLString text) {
+        
         // add a child text node to the assertions, DOM tree
         if (currentAssertDomNode != null) {
             currentAssertDomNode.appendChild(assertDocument.createTextNode(new 
                                    String(text.ch, text.offset, text.length)));
         }
+        
     }
     
 

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=981126&r1=981125&r2=981126&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 Aug  1 03:25:46 2010
@@ -43,9 +43,6 @@ import org.apache.xerces.impl.validation
 import org.apache.xerces.impl.validation.ValidationState;
 import org.apache.xerces.impl.xs.alternative.Test;
 import org.apache.xerces.impl.xs.alternative.XSTypeAlternativeImpl;
-import org.apache.xerces.impl.xs.assertion.XMLAssertHandler;
-import org.apache.xerces.impl.xs.assertion.XSAssert;
-import org.apache.xerces.impl.xs.assertion.XSAssertImpl;
 import org.apache.xerces.impl.xs.identity.Field;
 import org.apache.xerces.impl.xs.identity.FieldActivator;
 import org.apache.xerces.impl.xs.identity.IdentityConstraint;
@@ -90,11 +87,8 @@ import org.apache.xerces.xs.ElementPSVI;
 import org.apache.xerces.xs.ShortList;
 import org.apache.xerces.xs.StringList;
 import org.apache.xerces.xs.XSAttributeDeclaration;
-import org.apache.xerces.xs.XSComplexTypeDefinition;
 import org.apache.xerces.xs.XSConstants;
-import org.apache.xerces.xs.XSMultiValueFacet;
 import org.apache.xerces.xs.XSObjectList;
-import org.apache.xerces.xs.XSSimpleTypeDefinition;
 import org.apache.xerces.xs.XSTypeDefinition;
 import org.xml.sax.SAXNotRecognizedException;
 import org.xml.sax.SAXNotSupportedException;
@@ -415,9 +409,6 @@ public class XMLSchemaValidator
      * While parsing a document, keep the location of the document.
      */
     private XMLLocator fLocator;
-
-    // assertion processor object reference
-    private XMLAssertHandler fAssertionProcessor = null;
     
     // a Vector list storing inheritable attributes
     private Vector fInheritableAttrList = new Vector();
@@ -838,37 +829,6 @@ public class XMLSchemaValidator
         }
 
     } // startElement(QName,XMLAttributes, Augmentations)
-
-    
-    /*
-     * Method initializing the assertions processor. 
-     * 
-     * @param assertParams Parameters that are passed, to the assertions 
processor
-     */
-    private void initializeAssertProcessor(Map assertParams) {
-        String assertProcessorProp = System
-                .getProperty("org.apache.xerces.assertProcessor");
-        
-        if (assertProcessorProp == null || assertProcessorProp.equals("")) {
-            // if assertion processor is not specified via a system
-            // property, default to the Psychopath processor
-            fAssertionProcessor = new XMLAssertPsychopathImpl(assertParams);
-        } else {
-            try {
-                Class assertClass = ClassLoader.getSystemClassLoader()
-                        .loadClass(assertProcessorProp);
-                fAssertionProcessor = (XMLAssertHandler) 
assertClass.newInstance();
-            } catch (ClassNotFoundException ex) {
-                throw new XNIException(ex.getMessage(), ex);
-            } catch (InstantiationException ex) {
-                throw new XNIException(ex.getMessage(), ex);
-            } catch (IllegalAccessException ex) {
-                throw new XNIException(ex.getMessage(), ex);
-            }
-        }
-        
-        
fAssertionProcessor.setProperty("http://apache.org/xml/properties/assert/validator";,
 this);
-    }
     
 
     /**
@@ -1394,6 +1354,9 @@ public class XMLSchemaValidator
 
     /** Cache of value stores for identity constraint fields. */
     protected ValueStoreCache fValueStoreCache = new ValueStoreCache();
+    
+    // assertion validator subcomponent
+    private XSDAssertionValidator assertionValidator = null;
 
     //
     // Constructors
@@ -1405,7 +1368,7 @@ public class XMLSchemaValidator
         fState4ApplyDefault.setFacetChecking(false);
         fSchemaVersion = fSchemaLoader.getSchemaVersion();
         fXSConstraints = fSchemaLoader.getXSConstraints();
-
+        assertionValidator = new XSDAssertionValidator(this); 
     } // <init>()
 
     /*
@@ -1863,9 +1826,9 @@ public class XMLSchemaValidator
             }
         }
         
-        // invoke the assertions processor method
-        if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1 && 
fAssertionProcessor != null) {
-            fAssertionProcessor.characters(text);
+        // delegate to assertions validator subcomponent
+        if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1) {
+            assertionValidator.characterDataHandler(text);
         }
 
         return text;
@@ -2467,9 +2430,9 @@ public class XMLSchemaValidator
             fCurrentPSVI.fNil = fNil;
         }
         
-        // process assertions
+        // delegate to assertions validator subcomponent
         if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1) {
-           addAssertsForEvaluation(element, attributes);
+            assertionValidator.handleStartElement(element, attributes);
         }
 
         return augs;
@@ -2477,117 +2440,6 @@ public class XMLSchemaValidator
     } // handleStartElement(QName,XMLAttributes,boolean)
     
 
-    /** Add assertions for processing */
-    private void addAssertsForEvaluation(QName element,
-                                XMLAttributes attributes) {
-        
-       XSTypeDefinition typeDef = fCurrentPSVI.getTypeDefinition();
-       Object assertObject = null;
-            
-       if (typeDef.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) {
-          // if element's governing type is a "complex type"
-          XSObjectListImpl assertions = new XSObjectListImpl();                
-          XSComplexTypeDefinition complexTypeDef = (XSComplexTypeDefinition) 
typeDef;
-          
-          XSObjectList complexTypeAsserts = complexTypeDef.getAssertions();
-          if (complexTypeAsserts.getLength() > 0) {
-            for (int i = 0; i < complexTypeAsserts.getLength(); i++) {
-               assertions.addXSObject((XSAssert)complexTypeAsserts.get(i));
-            }
-          }
-          
-          // add assertion facets, from "complexType -> simpleContent -> 
restriction"
-          XSSimpleTypeDefinition simpleTypeDef = 
complexTypeDef.getSimpleType();
-          if (simpleTypeDef != null) {
-            XSObjectList complexTypeFacets = 
simpleTypeDef.getMultiValueFacets();
-            for (int i = 0; i < complexTypeFacets.getLength(); i++) {
-              XSMultiValueFacet facet = (XSMultiValueFacet) 
complexTypeFacets.item(i);
-              if (facet.getFacetKind() == XSSimpleTypeDefinition.FACET_ASSERT) 
{
-                 Vector simpleContentAsserts = facet.getAsserts();
-                 for (int simpleAssertIdx = 0; simpleAssertIdx < 
-                              simpleContentAsserts.size(); simpleAssertIdx++) {
-                    XSAssert simpleContentAssert = (XSAssert)
-                                         
simpleContentAsserts.get(simpleAssertIdx);
-                    assertions.addXSObject(simpleContentAssert);
-                 }
-              }
-            }
-          }
-
-          // there could be assertions, to be evaluated on attributes. add 
these
-          // assertions to the list of assertions to be processed.
-          for (int attrIndx = 0; attrIndx < attributes.getLength(); 
attrIndx++) {
-              Augmentations attrAugs = attributes.getAugmentations(attrIndx);
-              AttributePSVImpl attrPSVI = (AttributePSVImpl)attrAugs.getItem
-                                                 (Constants.ATTRIBUTE_PSVI);
-              XSSimpleTypeDefinition attrType = 
(XSSimpleTypeDefinition)attrPSVI.
-                                                        getTypeDefinition();
-              if (attrType != null) {
-                 XSObjectList facets = attrType.getMultiValueFacets();         
     
-                 for (int i = 0; i < facets.getLength(); i++) {
-                    XSMultiValueFacet facet = (XSMultiValueFacet) 
facets.item(i);
-                    if (facet.getFacetKind() == 
XSSimpleTypeDefinition.FACET_ASSERT) {
-                       Vector attrAsserts = facet.getAsserts();
-                       for (int j = 0; j < attrAsserts.size(); j++) {
-                         XSAssertImpl attrAssert = (XSAssertImpl) 
attrAsserts.elementAt(j);
-                         
attrAssert.setAttrName(attributes.getLocalName(attrIndx));
-                         
attrAssert.setAttrValue(attributes.getValue(attrIndx));
-                         assertions.addXSObject(attrAssert);    
-                       }                        
-                       break;
-                    }
-                 }
-              }
-          }
-              
-          if (assertions.size() > 0) {
-              assertObject = assertions;             
-              // instantiate the assertions processor
-              if (fAssertionProcessor == null) {
-                // construct parameter values for the assertion processor
-                Map assertProcessorParams = new HashMap();
-                assertProcessorParams.put("XPATH2_NS_CONTEXT",
-                                     ((XSAssertImpl)assertions.get(0)).
-                                     getXPath2NamespaceContext());
-                // initialize the assertions processor
-                initializeAssertProcessor(assertProcessorParams);
-              }
-          }
-        }
-        else if (typeDef.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) {
-            // if element's governing type is a "simple type"
-            XSSimpleTypeDefinition simpleTypeDef = (XSSimpleTypeDefinition) 
typeDef;
-            XSObjectList facets = simpleTypeDef.getMultiValueFacets();
-            for (int i = 0; i < facets.getLength(); i++) {
-              XSMultiValueFacet facet = (XSMultiValueFacet) facets.item(i);
-              if (facet.getFacetKind() == XSSimpleTypeDefinition.FACET_ASSERT) 
{
-                assertObject = facet.getAsserts();
-                // instantiate the assertions processor
-                if (fAssertionProcessor == null) {
-                   // construct parameter values for the assertion processor
-                   Map assertProcessorParams = new HashMap();
-                   assertProcessorParams.put("XPATH2_NS_CONTEXT",
-                                     ((XSAssertImpl)facet.getAsserts().get(0)).
-                                     getXPath2NamespaceContext());
-                   // initialize the assertions processor
-                   initializeAssertProcessor(assertProcessorParams);
-                }
-                break;
-              }
-            }
-         }
-               
-         // invoke the assertions processor method
-         if (fAssertionProcessor != null) {
-            // construct the augmentations object, for assertions
-            AugmentationsImpl assertAugs = new AugmentationsImpl();
-            assertAugs.putItem("ASSERT", assertObject);
-            fAssertionProcessor.startElement(element, attributes, assertAugs);
-         }
-         
-    } // addAssertsForEvaluation
-    
-
     /**
      *  Handle end element. If there is not text content, and there is a
      *  {value constraint} on the corresponding element decl, then
@@ -2719,24 +2571,11 @@ public class XMLSchemaValidator
             fValueStoreCache.endElement();
         }
         
-        // invoke the assertions processor method
-        if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1 && 
fAssertionProcessor != null) {
-           try {
-             // create the ElementPSVImpl object, for assertions
-             ElementPSVImpl assertPSVI = new ElementPSVImpl();
-             assertPSVI.fDeclaration = fCurrentElemDecl;
-             assertPSVI.fTypeDecl = fCurrentType;
-             assertPSVI.fNotation = fNotation;
-             assertPSVI.fGrammars = fGrammarBucket.getGrammars();
-                
-             // construct the augmentations object for assertions.
-             // store assertPSVI into the augmentations
-             AugmentationsImpl assertAugs = new AugmentationsImpl();
-             assertAugs.putItem(Constants.ELEMENT_PSVI, assertPSVI);           
     
-             fAssertionProcessor.endElement(element, assertAugs);
-           } catch (Exception ex) {
-               throw new XNIException(ex.getMessage(), ex);
-           }
+        // delegate to assertions validator subcomponent
+        if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1) {
+            assertionValidator.handleEndElement(element, fCurrentElemDecl, 
+                                                fCurrentType, fNotation, 
+                                                fGrammarBucket);
         }
 
         // Check if we should modify the xsi:type ignore depth

Added: 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDAssertionValidator.java
URL: 
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDAssertionValidator.java?rev=981126&view=auto
==============================================================================
--- 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDAssertionValidator.java
 (added)
+++ 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDAssertionValidator.java
 Sun Aug  1 03:25:46 2010
@@ -0,0 +1,284 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.xerces.impl.xs;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
+
+import org.apache.xerces.impl.Constants;
+import org.apache.xerces.impl.xs.assertion.XMLAssertHandler;
+import org.apache.xerces.impl.xs.assertion.XSAssert;
+import org.apache.xerces.impl.xs.assertion.XSAssertImpl;
+import org.apache.xerces.impl.xs.util.XSObjectListImpl;
+import org.apache.xerces.util.AugmentationsImpl;
+import org.apache.xerces.xni.Augmentations;
+import org.apache.xerces.xni.QName;
+import org.apache.xerces.xni.XMLAttributes;
+import org.apache.xerces.xni.XMLString;
+import org.apache.xerces.xni.XNIException;
+import org.apache.xerces.xs.XSComplexTypeDefinition;
+import org.apache.xerces.xs.XSMultiValueFacet;
+import org.apache.xerces.xs.XSObjectList;
+import org.apache.xerces.xs.XSSimpleTypeDefinition;
+import org.apache.xerces.xs.XSTypeDefinition;
+
+/**
+ * An XML Schema validator subcomponent handling assertions processing.
+ * 
+ * @xerces.internal
+ * 
+ * @author Mukul Gandhi IBM
+ * 
+ * @version $Id: $
+ */
+public class XSDAssertionValidator {
+    
+    // XMLSchemaValidator instance that behaves as context for the present 
+    // assertion validator subcomponent. Passed into the constructor of 
+    // this object.
+    XMLSchemaValidator xmlSchemaValidator = null;
+    
+    // assertion processor object reference
+    XMLAssertHandler fAssertionProcessor = null;
+    
+    
+    /*
+     * Class constructor
+     */
+    public XSDAssertionValidator(XMLSchemaValidator xmlSchemaValidator) {
+       this.xmlSchemaValidator = xmlSchemaValidator;   
+    }
+
+    
+    /*
+     * Assertions processing interface during the XNI event, 'handleCharacters'
+     * in XMLSchemaValidator. 
+     */
+    public void characterDataHandler(XMLString text) {
+        
+        if (fAssertionProcessor != null) {
+           fAssertionProcessor.characters(text);
+        }
+        
+    } // characterDataHandler
+    
+    
+    /*
+     * Assertions processing interface during the XNI event, 
'handleStartElement'
+     * in XMLSchemaValidator.
+     */
+    public void handleStartElement(QName element, XMLAttributes attributes) {
+       
+        // get list of assertions for processing
+        List assertionList = getAssertsForEvaluation(element, attributes);
+       
+        // invoke the assertions processor method
+        if (fAssertionProcessor != null) {
+           // construct the augmentations object, for assertions
+           AugmentationsImpl assertAugs = new AugmentationsImpl();
+           assertAugs.putItem("ASSERT", assertionList);
+           fAssertionProcessor.startElement(element, attributes, assertAugs);
+        }
+        
+    } // handleStartElement
+    
+    
+    /*
+     * Assertions processing interface during the XNI event, 'handleEndElement'
+     * in XMLSchemaValidator.
+     */
+    public void handleEndElement(QName element, 
+                                 XSElementDecl elemDecl, 
+                                 XSTypeDefinition typeDef, 
+                                 XSNotationDecl notation,
+                                 XSGrammarBucket grammarBucket) {
+        
+        if (fAssertionProcessor != null) {
+            try {
+                // create the ElementPSVImpl object, for assertions
+                ElementPSVImpl assertPSVI = new ElementPSVImpl();
+                assertPSVI.fDeclaration = elemDecl;
+                assertPSVI.fTypeDecl = typeDef;
+                assertPSVI.fNotation = notation;
+                assertPSVI.fGrammars = grammarBucket.getGrammars();
+
+                // construct the augmentations object for assertions.
+                // store assertPSVI into the augmentations
+                AugmentationsImpl assertAugs = new AugmentationsImpl();
+                assertAugs.putItem(Constants.ELEMENT_PSVI, assertPSVI);        
        
+                fAssertionProcessor.endElement(element, assertAugs);
+            } catch (Exception ex) {
+                throw new XNIException(ex.getMessage(), ex);
+            }
+        }
+          
+    } // handleEndElement
+    
+    
+    /*
+     * Accumulate a list of assertions (fetch from the underlying XSModel
+     * instance) to be processed for the current context. Return the 
+     * assertions list.
+     */
+    private List getAssertsForEvaluation(QName element,
+                                         XMLAttributes attributes) {
+        
+       XSTypeDefinition typeDef = xmlSchemaValidator.fCurrentPSVI.
+                                                         getTypeDefinition();
+       List assertionList = null;
+            
+       if (typeDef.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) {
+          // if element's governing type is a "complex type"
+          XSObjectListImpl assertions = new XSObjectListImpl();                
+          XSComplexTypeDefinition complexTypeDef = (XSComplexTypeDefinition) 
+                                                               typeDef;
+          
+          XSObjectList complexTypeAsserts = complexTypeDef.getAssertions();
+          if (complexTypeAsserts.getLength() > 0) {
+             for (int i = 0; i < complexTypeAsserts.getLength(); i++) {
+                assertions.addXSObject((XSAssert)complexTypeAsserts.get(i));
+             }
+          }
+          
+          // add assertion facets, from "complexType -> simpleContent -> 
restriction"
+          XSSimpleTypeDefinition simpleTypeDef = 
complexTypeDef.getSimpleType();
+          if (simpleTypeDef != null) {
+            XSObjectList complexTypeFacets = 
simpleTypeDef.getMultiValueFacets();
+            for (int i = 0; i < complexTypeFacets.getLength(); i++) {
+              XSMultiValueFacet facet = (XSMultiValueFacet) 
+                                                  complexTypeFacets.item(i);
+              if (facet.getFacetKind() == XSSimpleTypeDefinition.FACET_ASSERT) 
{
+                 Vector simpleContentAsserts = facet.getAsserts();
+                 for (int simpleAssertIdx = 0; simpleAssertIdx < 
+                              simpleContentAsserts.size(); simpleAssertIdx++) {
+                    XSAssert simpleContentAssert = (XSAssert)
+                                      
simpleContentAsserts.get(simpleAssertIdx);
+                    assertions.addXSObject(simpleContentAssert);
+                 }
+              }
+            }
+          }
+
+          // there could be assertions, to be evaluated on attributes. add 
these
+          // assertions to the list of assertions to be processed.
+          for (int attrIndx = 0; attrIndx < attributes.getLength(); 
attrIndx++) {
+              Augmentations attrAugs = attributes.getAugmentations(attrIndx);
+              AttributePSVImpl attrPSVI = (AttributePSVImpl)attrAugs.getItem
+                                                 (Constants.ATTRIBUTE_PSVI);
+              XSSimpleTypeDefinition attrType = 
(XSSimpleTypeDefinition)attrPSVI.
+                                                        getTypeDefinition();
+              if (attrType != null) {
+                 XSObjectList facets = attrType.getMultiValueFacets();         
     
+                 for (int i = 0; i < facets.getLength(); i++) {
+                    XSMultiValueFacet facet = (XSMultiValueFacet) 
facets.item(i);
+                    if (facet.getFacetKind() == 
XSSimpleTypeDefinition.FACET_ASSERT) {
+                       Vector attrAsserts = facet.getAsserts();
+                       for (int j = 0; j < attrAsserts.size(); j++) {
+                         XSAssertImpl attrAssert = (XSAssertImpl) 
+                                                       
attrAsserts.elementAt(j);
+                         
attrAssert.setAttrName(attributes.getLocalName(attrIndx));
+                         
attrAssert.setAttrValue(attributes.getValue(attrIndx));
+                         assertions.addXSObject(attrAssert);    
+                       }                        
+                       break;
+                    }
+                 }
+              }
+          }
+              
+          if (assertions.size() > 0) {
+              assertionList = assertions;             
+              // instantiate the assertions processor
+              if (fAssertionProcessor == null) {
+                // construct parameter values for the assertion processor
+                Map assertProcessorParams = new HashMap();
+                assertProcessorParams.put("XPATH2_NS_CONTEXT",
+                                     ((XSAssertImpl)assertions.get(0)).
+                                       getXPath2NamespaceContext());
+                // initialize the assertions processor
+                initializeAssertProcessor(assertProcessorParams);
+              }
+          }
+        }
+        else if (typeDef.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) {
+            // if element's governing type is a "simple type"
+            XSSimpleTypeDefinition simpleTypeDef = (XSSimpleTypeDefinition) 
+                                                                typeDef;
+            XSObjectList facets = simpleTypeDef.getMultiValueFacets();
+            for (int i = 0; i < facets.getLength(); i++) {
+               XSMultiValueFacet facet = (XSMultiValueFacet) facets.item(i);
+               if (facet.getFacetKind() == 
XSSimpleTypeDefinition.FACET_ASSERT) {
+                  assertionList = facet.getAsserts();
+                  // instantiate the assertions processor
+                  if (fAssertionProcessor == null) {
+                     // construct parameter values for the assertion processor
+                     Map assertProcessorParams = new HashMap();
+                     assertProcessorParams.put("XPATH2_NS_CONTEXT",
+                                       
((XSAssertImpl)facet.getAsserts().get(0)).
+                                         getXPath2NamespaceContext());
+                     // initialize the assertions processor
+                     initializeAssertProcessor(assertProcessorParams);
+                  }
+                  
+                  break;
+                  
+               }
+            }
+         }
+               
+         return assertionList;
+         
+    } // getAssertsForEvaluation
+    
+    
+    /*
+     * Method to initialize the assertions processor.
+     */
+    private void initializeAssertProcessor(Map assertParams) {
+        
+        String assertProcessorProp = System
+                .getProperty("org.apache.xerces.assertProcessor");
+        
+        if (assertProcessorProp == null || assertProcessorProp.equals("")) {
+            // if assertion processor is not specified via a system
+            // property, initialize it to the PsychoPath XPath 2.0 processor.
+            fAssertionProcessor = new XMLAssertPsychopathImpl(assertParams);
+        } else {
+            try {
+                Class assertClass = ClassLoader.getSystemClassLoader()
+                        .loadClass(assertProcessorProp);
+                fAssertionProcessor = (XMLAssertHandler) 
+                                             assertClass.newInstance();
+            } catch (ClassNotFoundException ex) {
+                throw new XNIException(ex.getMessage(), ex);
+            } catch (InstantiationException ex) {
+                throw new XNIException(ex.getMessage(), ex);
+            } catch (IllegalAccessException ex) {
+                throw new XNIException(ex.getMessage(), ex);
+            }
+        }
+        
+        fAssertionProcessor.setProperty
+                    ("http://apache.org/xml/properties/assert/validator";, 
+                                                      xmlSchemaValidator);
+        
+    } // initializeAssertProcessor
+    
+} // class XMLAssertionValidator



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

Reply via email to