https://issues.shibboleth.net/jira/browse/CPPXT-18
[shibboleth/cpp-xmltooling.git] / xmltooling / AbstractXMLObject.cpp
index 3eee63a..0f49b55 100644 (file)
@@ -1,6 +1,6 @@
 /*
 *  Copyright 2001-2007 Internet2
- * 
+ *
 * Licensed 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
@@ -16,7 +16,7 @@
 
 /**
  * AbstractXMLObject.cpp
- * 
+ *
  * An abstract implementation of XMLObject.
  */
 
 #include "exceptions.h"
 
 #include <algorithm>
-#include <log4cpp/Category.hh>
 
 using namespace xmltooling;
 
 AbstractXMLObject::AbstractXMLObject(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
-    : m_log(log4cpp::Category::getInstance(XMLTOOLING_LOGCAT".XMLObject")), m_schemaLocation(NULL), m_noNamespaceSchemaLocation(NULL),
+    : m_log(logging::Category::getInstance(XMLTOOLING_LOGCAT".XMLObject")),
+       m_schemaLocation(NULL), m_noNamespaceSchemaLocation(NULL), m_nil(xmlconstants::XML_BOOL_NULL),
         m_parent(NULL), m_elementQname(nsURI, localName, prefix), m_typeQname(NULL)
 {
     addNamespace(Namespace(nsURI, prefix));
@@ -42,13 +42,44 @@ AbstractXMLObject::AbstractXMLObject(const XMLCh* nsURI, const XMLCh* localName,
 
 AbstractXMLObject::AbstractXMLObject(const AbstractXMLObject& src)
     : m_namespaces(src.m_namespaces), m_log(src.m_log), m_schemaLocation(XMLString::replicate(src.m_schemaLocation)),
-        m_noNamespaceSchemaLocation(XMLString::replicate(src.m_noNamespaceSchemaLocation)),
+        m_noNamespaceSchemaLocation(XMLString::replicate(src.m_noNamespaceSchemaLocation)), m_nil(src.m_nil),
         m_parent(NULL), m_elementQname(src.m_elementQname), m_typeQname(NULL)
 {
     if (src.m_typeQname)
         m_typeQname=new QName(*src.m_typeQname);
 }
 
+AbstractXMLObject::~AbstractXMLObject()
+{
+    delete m_typeQname;
+    xercesc::XMLString::release(&m_schemaLocation);
+    xercesc::XMLString::release(&m_noNamespaceSchemaLocation);
+}
+
+void XMLObject::setNil(const XMLCh* value) {
+    if (value) {
+        switch (*value) {
+            case xercesc::chLatin_t:
+                nil(xmlconstants::XML_BOOL_TRUE);
+                break;
+            case xercesc::chLatin_f:
+                nil(xmlconstants::XML_BOOL_FALSE);
+                break;
+            case xercesc::chDigit_1:
+                nil(xmlconstants::XML_BOOL_ONE);
+                break;
+            case xercesc::chDigit_0:
+                nil(xmlconstants::XML_BOOL_ZERO);
+                break;
+            default:
+                nil(xmlconstants::XML_BOOL_NULL);
+        }
+    }
+    else {
+        nil(xmlconstants::XML_BOOL_NULL);
+    }
+}
+
 XMLCh* AbstractXMLObject::prepareForAssignment(XMLCh* oldValue, const XMLCh* newValue)
 {
     if (!XMLString::equals(oldValue,newValue)) {
@@ -97,21 +128,27 @@ DateTime* AbstractXMLObject::prepareForAssignment(DateTime* oldValue, const Date
     return newValue ? new DateTime(*newValue) : NULL;
 }
 
-DateTime* AbstractXMLObject::prepareForAssignment(DateTime* oldValue, time_t newValue)
+DateTime* AbstractXMLObject::prepareForAssignment(DateTime* oldValue, time_t newValue, bool duration)
 {
     delete oldValue;
     releaseThisandParentDOM();
-    DateTime* ret = new DateTime(newValue);
-    ret->parseDateTime();
+    DateTime* ret = new DateTime(newValue, duration);
+    if (duration)
+        ret->parseDuration();
+    else
+        ret->parseDateTime();
     return ret;
 }
 
-DateTime* AbstractXMLObject::prepareForAssignment(DateTime* oldValue, const XMLCh* newValue)
+DateTime* AbstractXMLObject::prepareForAssignment(DateTime* oldValue, const XMLCh* newValue, bool duration)
 {
     delete oldValue;
     releaseThisandParentDOM();
     DateTime* ret = new DateTime(newValue);
-    ret->parseDateTime();
+    if (duration)
+        ret->parseDuration();
+    else
+        ret->parseDateTime();
     return ret;
 }