Set fourth file version digit to signify rebuild.
[shibboleth/cpp-xmltooling.git] / xmltooling / AbstractXMLObject.cpp
index 3f6726a..59c41d0 100644 (file)
@@ -1,17 +1,21 @@
-/*
-*  Copyright 2001-2010 Internet2
+/**
+ * Licensed to the University Corporation for Advanced Internet
+ * Development, Inc. (UCAID) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for
+ * additional information regarding copyright ownership.
  *
-* 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
+ * UCAID 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
+ * 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.
+ * 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.
  */
 
 /**
@@ -52,14 +56,44 @@ void XMLObject::releaseThisAndChildrenDOM() const
     releaseDOM();
 }
 
+const XMLCh* XMLObject::getLang() const
+{
+    return nullptr;
+}
+
+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);
+    }
+}
+
 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),
-        m_parent(NULL), m_elementQname(nsURI, localName, prefix), m_typeQname(NULL)
+    : m_log(logging::Category::getInstance(XMLTOOLING_LOGCAT ".XMLObject")),
+       m_schemaLocation(nullptr), m_noNamespaceSchemaLocation(nullptr), m_nil(xmlconstants::XML_BOOL_NULL),
+        m_parent(nullptr), m_elementQname(nsURI, localName, prefix)
 {
     addNamespace(Namespace(nsURI, prefix, false, Namespace::VisiblyUsed));
     if (schemaType) {
-        m_typeQname = new QName(*schemaType);
+        m_typeQname.reset(new QName(*schemaType));
         addNamespace(Namespace(m_typeQname->getNamespaceURI(), m_typeQname->getPrefix(), false, Namespace::NonVisiblyUsed));
     }
 }
@@ -67,15 +101,13 @@ 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_nil(src.m_nil),
-        m_parent(NULL), m_elementQname(src.m_elementQname), m_typeQname(NULL)
+        m_parent(nullptr), m_elementQname(src.m_elementQname),
+        m_typeQname(src.m_typeQname.get() ? new QName(*src.m_typeQname) : nullptr)
 {
-    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);
 }
@@ -90,7 +122,7 @@ void AbstractXMLObject::detach()
     // Pull ourselves out of the parent and then blast him.
     getParent()->removeChild(this);
     delete m_parent;
-    m_parent = NULL;
+    m_parent = nullptr;
 }
 
 const QName& AbstractXMLObject::getElementQName() const
@@ -103,51 +135,33 @@ const set<Namespace>& AbstractXMLObject::getNamespaces() const
     return m_namespaces;
 }
 
-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);
-    }
-}
-
 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);
-        switch (ns.usage()) {
-            case Namespace::Indeterminate:
-                break;
-            case Namespace::VisiblyUsed:
-                const_cast<Namespace&>(*i).setUsage(Namespace::VisiblyUsed);
-                break;
-            case Namespace::NonVisiblyUsed:
-                if (i->usage() == Namespace::Indeterminate)
-                    const_cast<Namespace&>(*i).setUsage(Namespace::NonVisiblyUsed);
-                break;
+    for (set<Namespace>::const_iterator n = m_namespaces.begin(); n != m_namespaces.end(); ++n) {
+        // Look for the prefix in the existing set.
+        if (XMLString::equals(ns.getNamespacePrefix(), n->getNamespacePrefix())) {
+            // See if it's the same declaration, and overlay various properties if so.
+            if (XMLString::equals(ns.getNamespaceURI(), n->getNamespaceURI())) {
+                if (ns.alwaysDeclare())
+                    const_cast<Namespace&>(*n).setAlwaysDeclare(true);
+                switch (ns.usage()) {
+                    case Namespace::Indeterminate:
+                        break;
+                    case Namespace::VisiblyUsed:
+                        const_cast<Namespace&>(*n).setUsage(Namespace::VisiblyUsed);
+                        break;
+                    case Namespace::NonVisiblyUsed:
+                        if (n->usage() == Namespace::Indeterminate)
+                            const_cast<Namespace&>(*n).setUsage(Namespace::NonVisiblyUsed);
+                        break;
+                }
+            }
+            return;
         }
     }
+
+    // If the prefix is now, go ahead and add it.
+    m_namespaces.insert(ns);
 }
 
 void AbstractXMLObject::removeNamespace(const Namespace& ns)
@@ -157,12 +171,12 @@ void AbstractXMLObject::removeNamespace(const Namespace& ns)
 
 const QName* AbstractXMLObject::getSchemaType() const
 {
-    return m_typeQname;
+    return m_typeQname.get();
 }
 
 const XMLCh* AbstractXMLObject::getXMLID() const
 {
-    return NULL;
+    return nullptr;
 }
 
 xmlconstants::xmltooling_bool_t AbstractXMLObject::getNil() const
@@ -180,7 +194,7 @@ void AbstractXMLObject::nil(xmlconstants::xmltooling_bool_t value)
 
 bool AbstractXMLObject::hasParent() const
 {
-    return m_parent != NULL;
+    return m_parent != nullptr;
 }
 
 XMLObject* AbstractXMLObject::getParent() const
@@ -212,7 +226,7 @@ QName* AbstractXMLObject::prepareForAssignment(QName* oldValue, const QName* new
             addNamespace(Namespace(newValue->getNamespaceURI(), newValue->getPrefix(), false, Namespace::NonVisiblyUsed));
             return new QName(*newValue);
         }
-        return NULL;
+        return nullptr;
     }
 
     delete oldValue;
@@ -222,7 +236,7 @@ QName* AbstractXMLObject::prepareForAssignment(QName* oldValue, const QName* new
         addNamespace(Namespace(newValue->getNamespaceURI(), newValue->getPrefix(), false, Namespace::NonVisiblyUsed));
         return new QName(*newValue);
     }
-    return NULL;
+    return nullptr;
 }
 
 DateTime* AbstractXMLObject::prepareForAssignment(DateTime* oldValue, const DateTime* newValue)
@@ -232,12 +246,12 @@ DateTime* AbstractXMLObject::prepareForAssignment(DateTime* oldValue, const Date
             releaseThisandParentDOM();
             return new DateTime(*newValue);
         }
-        return NULL;
+        return nullptr;
     }
 
     delete oldValue;
     releaseThisandParentDOM();
-    return newValue ? new DateTime(*newValue) : NULL;
+    return newValue ? new DateTime(*newValue) : nullptr;
 }
 
 DateTime* AbstractXMLObject::prepareForAssignment(DateTime* oldValue, time_t newValue, bool duration)
@@ -257,7 +271,7 @@ DateTime* AbstractXMLObject::prepareForAssignment(DateTime* oldValue, const XMLC
     delete oldValue;
     releaseThisandParentDOM();
     if (!newValue || !*newValue)
-        return NULL;
+        return nullptr;
     DateTime* ret = new DateTime(newValue);
     if (duration)
         ret->parseDuration();