Update copyright.
[shibboleth/cpp-xmltooling.git] / xmltooling / AbstractXMLObject.cpp
index 3111c8d..63d3b73 100644 (file)
@@ -1,5 +1,5 @@
 /*
-*  Copyright 2001-2006 Internet2
+*  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.
@@ -30,7 +30,7 @@
 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_log(log4cpp::Category::getInstance(XMLTOOLING_LOGCAT".XMLObject")), m_schemaLocation(NULL),
         m_parent(NULL), m_elementQname(nsURI, localName, prefix), m_typeQname(NULL)
 {
     addNamespace(Namespace(nsURI, prefix));
@@ -41,7 +41,8 @@ AbstractXMLObject::AbstractXMLObject(const XMLCh* nsURI, const XMLCh* localName,
 }
 
 AbstractXMLObject::AbstractXMLObject(const AbstractXMLObject& src)
-    : m_namespaces(src.m_namespaces), m_log(src.m_log), m_parent(NULL), m_elementQname(src.m_elementQname), m_typeQname(NULL)
+    : m_namespaces(src.m_namespaces), m_log(src.m_log), m_schemaLocation(XMLString::replicate(src.m_schemaLocation)),
+        m_parent(NULL), m_elementQname(src.m_elementQname), m_typeQname(NULL)
 {
     if (src.m_typeQname)
         m_typeQname=new QName(*src.m_typeQname);
@@ -49,15 +50,13 @@ AbstractXMLObject::AbstractXMLObject(const AbstractXMLObject& src)
 
 XMLCh* AbstractXMLObject::prepareForAssignment(XMLCh* oldValue, const XMLCh* newValue)
 {
-    XMLCh* newString = XMLString::replicate(newValue);
-    XMLString::trim(newString);
     if (!XMLString::equals(oldValue,newValue)) {
         releaseThisandParentDOM();
+        XMLCh* newString = XMLString::replicate(newValue);
         XMLString::release(&oldValue);
         return newString;
     }
-    XMLString::release(&newString);
-    return oldValue;            
+    return oldValue;
 }
 
 QName* AbstractXMLObject::prepareForAssignment(QName* oldValue, const QName* newValue)
@@ -65,8 +64,8 @@ QName* AbstractXMLObject::prepareForAssignment(QName* oldValue, const QName* new
     if (!oldValue) {
         if (newValue) {
             releaseThisandParentDOM();
-            Namespace newNamespace(newValue->getNamespaceURI(), newValue->getPrefix());\r
-            addNamespace(newNamespace);\r
+            Namespace newNamespace(newValue->getNamespaceURI(), newValue->getPrefix());
+            addNamespace(newNamespace);
             return new QName(*newValue);
         }
         return NULL;
@@ -75,9 +74,9 @@ QName* AbstractXMLObject::prepareForAssignment(QName* oldValue, const QName* new
     delete oldValue;
     releaseThisandParentDOM();
     if (newValue) {
-        Namespace newNamespace(newValue->getNamespaceURI(), newValue->getPrefix());\r
-        addNamespace(newNamespace);\r
-        return new QName(*newValue);\r
+        Namespace newNamespace(newValue->getNamespaceURI(), newValue->getPrefix());
+        addNamespace(newNamespace);
+        return new QName(*newValue);
     }
     return NULL;
 }
@@ -137,3 +136,16 @@ XMLObject* AbstractXMLObject::prepareForAssignment(XMLObject* oldValue, XMLObjec
 
     return newValue;
 }
+
+void AbstractXMLObject::detach()
+{
+    if (!getParent())
+        return;
+    else if (getParent()->hasParent())
+        throw XMLObjectException("Cannot detach an object whose parent is itself a child.");
+
+    // Pull ourselves out of the parent and then blast him.
+    getParent()->removeChild(this);
+    delete m_parent;
+    m_parent = NULL;
+}