https://issues.shibboleth.net/jira/browse/CPPXT-41
[shibboleth/cpp-xmltooling.git] / xmltooling / AbstractXMLObject.cpp
index 6448856..1a51a44 100644 (file)
@@ -1,6 +1,6 @@
 /*
-*  Copyright 2001-2007 Internet2
- * 
+*  Copyright 2001-2009 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.
  */
 
@@ -28,6 +28,8 @@
 
 using namespace xmltooling;
 
+using xercesc::XMLString;
+
 AbstractXMLObject::AbstractXMLObject(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
     : m_log(logging::Category::getInstance(XMLTOOLING_LOGCAT".XMLObject")),
        m_schemaLocation(NULL), m_noNamespaceSchemaLocation(NULL), m_nil(xmlconstants::XML_BOOL_NULL),
@@ -49,7 +51,15 @@ AbstractXMLObject::AbstractXMLObject(const AbstractXMLObject& src)
         m_typeQname=new QName(*src.m_typeQname);
 }
 
-void XMLObject::setNil(const XMLCh* value) {
+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:
@@ -73,6 +83,15 @@ void XMLObject::setNil(const XMLCh* value) {
     }
 }
 
+void AbstractXMLObject::addNamespace(const Namespace& ns) const
+{
+    std::set<Namespace>::iterator i = m_namespaces.find(ns);
+    if (i == m_namespaces.end())
+        m_namespaces.insert(ns);
+    else if (ns.alwaysDeclare())
+        const_cast<Namespace&>(*i).setAlwaysDeclare(true);
+}
+
 XMLCh* AbstractXMLObject::prepareForAssignment(XMLCh* oldValue, const XMLCh* newValue)
 {
     if (!XMLString::equals(oldValue,newValue)) {
@@ -121,21 +140,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;
 }