From 61b6f41602435f854533e6f9013d207a0ef1ccf7 Mon Sep 17 00:00:00 2001
From: Neil Graham <neilg@apache.org>
Date: Mon, 24 Nov 2003 05:10:26 +0000
Subject: [PATCH] implement method for determining member type of union that
 validated some value

git-svn-id: https://svn.apache.org/repos/asf/xerces/c/trunk@175437 13f79535-47bb-0310-9956-ffa450edef68
---
 src/xercesc/framework/ValidationContext.hpp   | 13 ++++++++
 .../internal/ValidationContextImpl.cpp        |  4 +++
 .../internal/ValidationContextImpl.hpp        | 32 +++++++++++++++++++
 .../datatype/UnionDatatypeValidator.cpp       |  9 ++++--
 .../datatype/UnionDatatypeValidator.hpp       |  4 +++
 5 files changed, 60 insertions(+), 2 deletions(-)

diff --git a/src/xercesc/framework/ValidationContext.hpp b/src/xercesc/framework/ValidationContext.hpp
index 748fc3e7d..8dab51742 100644
--- a/src/xercesc/framework/ValidationContext.hpp
+++ b/src/xercesc/framework/ValidationContext.hpp
@@ -56,6 +56,9 @@
 
 /*
  * $Log$
+ * Revision 1.2  2003/11/24 05:10:26  neilg
+ * implement method for determining member type of union that validated some value
+ *
  * Revision 1.1  2003/11/12 20:28:16  peiyongz
  * Stateless Grammar: ValidationContext
  *
@@ -75,6 +78,7 @@ XERCES_CPP_NAMESPACE_BEGIN
 
 class XMLRefInfo;
 class DTDEntityDecl;
+class DatatypeValidator;
 
 class XMLPARSER_EXPORT ValidationContext : public XMemory
 {
@@ -122,6 +126,14 @@ public :
            
     virtual void                             checkEntity(const XMLCh * const ) const = 0 ;
 
+    /**
+      * Union datatype handling
+      *
+      */
+
+    virtual DatatypeValidator * getValidatingMemberType() const = 0 ;
+    virtual void setValidatingMemberType(DatatypeValidator * validatingMemberType) = 0 ;
+
     //@}
 
    
@@ -158,3 +170,4 @@ private :
 XERCES_CPP_NAMESPACE_END
 
 #endif
+
diff --git a/src/xercesc/internal/ValidationContextImpl.cpp b/src/xercesc/internal/ValidationContextImpl.cpp
index d5714c74b..34f3177f2 100644
--- a/src/xercesc/internal/ValidationContextImpl.cpp
+++ b/src/xercesc/internal/ValidationContextImpl.cpp
@@ -56,6 +56,9 @@
 
 /*
  * $Log$
+ * Revision 1.2  2003/11/24 05:10:26  neilg
+ * implement method for determining member type of union that validated some value
+ *
  * Revision 1.1  2003/11/12 20:29:47  peiyongz
  * Stateless Grammar: ValidationContext
  *
@@ -88,6 +91,7 @@ ValidationContextImpl::ValidationContextImpl(MemoryManager* const manager)
 ,fIdRefList(0)
 ,fEntityDeclPool(0)
 ,fToCheckIdRefList(true)
+,fValidatingMemberType(0)
 {
     fIdRefList = new (fMemoryManager) RefHashTableOf<XMLRefInfo>(109, fMemoryManager);
 }
diff --git a/src/xercesc/internal/ValidationContextImpl.hpp b/src/xercesc/internal/ValidationContextImpl.hpp
index 87dbbeaf2..81a5b5ed7 100644
--- a/src/xercesc/internal/ValidationContextImpl.hpp
+++ b/src/xercesc/internal/ValidationContextImpl.hpp
@@ -56,6 +56,9 @@
 
 /*
  * $Log$
+ * Revision 1.2  2003/11/24 05:10:26  neilg
+ * implement method for determining member type of union that validated some value
+ *
  * Revision 1.1  2003/11/12 20:29:47  peiyongz
  * Stateless Grammar: ValidationContext
  *
@@ -119,6 +122,15 @@ public :
            
     virtual void                             checkEntity(const XMLCh * const ) const;
 
+
+    /**
+      * Union datatype handling
+      *
+      */
+
+    virtual DatatypeValidator * getValidatingMemberType() const;
+    virtual void setValidatingMemberType(DatatypeValidator * validatingMemberType) ;
+
     //@}
   
 private:
@@ -143,14 +155,34 @@ private:
     //      default entities (such as &gt; &lt; ...) defined by the XML Standard.
     //
     //  fToAddToList
+    //  fValidatingMemberType
+    //      The member type in a union that actually
+    //      validated some text.  Note that the validationContext does not
+    //      own this object, and the value of getValidatingMemberType
+    //      will not be accurate unless the type of the most recently-validated
+    //      element/attribute is in fact a union datatype.
     // -----------------------------------------------------------------------
 
     RefHashTableOf<XMLRefInfo>*         fIdRefList;
     const NameIdPool<DTDEntityDecl>*    fEntityDeclPool;
     bool                                fToCheckIdRefList;
+    DatatypeValidator *                 fValidatingMemberType;
 
 };
 
+
+
+inline DatatypeValidator * ValidationContextImpl::getValidatingMemberType() const
+{
+    return fValidatingMemberType;
+}
+
+inline void ValidationContextImpl::setValidatingMemberType(DatatypeValidator * validatingMemberType) 
+{
+    fValidatingMemberType = validatingMemberType;
+}
+
 XERCES_CPP_NAMESPACE_END
 
 #endif
+
diff --git a/src/xercesc/validators/datatype/UnionDatatypeValidator.cpp b/src/xercesc/validators/datatype/UnionDatatypeValidator.cpp
index 4883ff431..888df3a41 100644
--- a/src/xercesc/validators/datatype/UnionDatatypeValidator.cpp
+++ b/src/xercesc/validators/datatype/UnionDatatypeValidator.cpp
@@ -57,6 +57,9 @@
 /*
  * $Id$
  * $Log$
+ * Revision 1.18  2003/11/24 05:10:26  neilg
+ * implement method for determining member type of union that validated some value
+ *
  * Revision 1.17  2003/11/13 23:19:18  peiyongz
  * initSize
  *
@@ -138,9 +141,8 @@
 
 XERCES_CPP_NAMESPACE_BEGIN
 
-static const int BUF_LEN = 64;
+static const unsigned int BUF_LEN = 64;
 static XMLCh value1[BUF_LEN+1];
-static XMLCh value2[BUF_LEN+1];
 
 // ---------------------------------------------------------------------------
 //  Constructors and Destructor
@@ -360,6 +362,9 @@ void UnionDatatypeValidator::checkContent(const XMLCh*             const content
                 //set the validator of the type actually used to validate the content
                 DatatypeValidator *dtv = fMemberTypeValidators->elementAt(i);
                 fValidatedDatatype = dtv;
+                // context will be null during schema construction
+                if(context)
+                    context->setValidatingMemberType(dtv);
             }
             catch (XMLException&)
             {
diff --git a/src/xercesc/validators/datatype/UnionDatatypeValidator.hpp b/src/xercesc/validators/datatype/UnionDatatypeValidator.hpp
index 3174071a0..e10a7152f 100644
--- a/src/xercesc/validators/datatype/UnionDatatypeValidator.hpp
+++ b/src/xercesc/validators/datatype/UnionDatatypeValidator.hpp
@@ -57,6 +57,9 @@
 /*
  * $Id$
  * $Log$
+ * Revision 1.13  2003/11/24 05:10:26  neilg
+ * implement method for determining member type of union that validated some value
+ *
  * Revision 1.12  2003/11/12 20:32:03  peiyongz
  * Statless Grammar: ValidationContext
  *
@@ -462,3 +465,4 @@ XERCES_CPP_NAMESPACE_END
 /**
   * End of file UnionDatatypeValidator.hpp
   */
+
-- 
GitLab