/*
-* 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.
#include "exceptions.h"
#include <algorithm>
-#include <log4cpp/Category.hh>
using namespace xmltooling;
-AbstractXMLObject::~AbstractXMLObject() {
- delete m_typeQname;
- std::for_each(m_children.begin(), m_children.end(), cleanup<XMLObject>());
-}
-
AbstractXMLObject::AbstractXMLObject(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
- : m_log(&log4cpp::Category::getInstance(XMLTOOLING_LOGCAT".XMLObject")),
+ : m_log(logging::Category::getInstance(XMLTOOLING_LOGCAT".XMLObject")), m_schemaLocation(NULL), m_noNamespaceSchemaLocation(NULL),
m_parent(NULL), m_elementQname(nsURI, localName, prefix), m_typeQname(NULL)
{
addNamespace(Namespace(nsURI, prefix));
}
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_noNamespaceSchemaLocation(XMLString::replicate(src.m_noNamespaceSchemaLocation)),
+ m_parent(NULL), m_elementQname(src.m_elementQname), m_typeQname(NULL)
{
if (src.m_typeQname)
m_typeQname=new QName(*src.m_typeQname);
}
-XMLObject* AbstractXMLObject::prepareForAssignment(XMLObject* oldValue, XMLObject* newValue) {
+XMLCh* AbstractXMLObject::prepareForAssignment(XMLCh* oldValue, const XMLCh* newValue)
+{
+ if (!XMLString::equals(oldValue,newValue)) {
+ releaseThisandParentDOM();
+ XMLCh* newString = XMLString::replicate(newValue);
+ XMLString::release(&oldValue);
+ return newString;
+ }
+ return oldValue;
+}
+
+QName* AbstractXMLObject::prepareForAssignment(QName* oldValue, const QName* newValue)
+{
+ if (!oldValue) {
+ if (newValue) {
+ releaseThisandParentDOM();
+ Namespace newNamespace(newValue->getNamespaceURI(), newValue->getPrefix());
+ addNamespace(newNamespace);
+ return new QName(*newValue);
+ }
+ return NULL;
+ }
+
+ delete oldValue;
+ releaseThisandParentDOM();
+ if (newValue) {
+ Namespace newNamespace(newValue->getNamespaceURI(), newValue->getPrefix());
+ addNamespace(newNamespace);
+ return new QName(*newValue);
+ }
+ return NULL;
+}
+
+DateTime* AbstractXMLObject::prepareForAssignment(DateTime* oldValue, const DateTime* newValue)
+{
+ if (!oldValue) {
+ if (newValue) {
+ releaseThisandParentDOM();
+ return new DateTime(*newValue);
+ }
+ return NULL;
+ }
+
+ delete oldValue;
+ releaseThisandParentDOM();
+ return newValue ? new DateTime(*newValue) : NULL;
+}
+
+DateTime* AbstractXMLObject::prepareForAssignment(DateTime* oldValue, time_t newValue)
+{
+ delete oldValue;
+ releaseThisandParentDOM();
+ DateTime* ret = new DateTime(newValue);
+ ret->parseDateTime();
+ return ret;
+}
+
+DateTime* AbstractXMLObject::prepareForAssignment(DateTime* oldValue, const XMLCh* newValue)
+{
+ delete oldValue;
+ releaseThisandParentDOM();
+ DateTime* ret = new DateTime(newValue);
+ ret->parseDateTime();
+ return ret;
+}
+XMLObject* AbstractXMLObject::prepareForAssignment(XMLObject* oldValue, XMLObject* newValue)
+{
if (newValue && newValue->hasParent())
throw XMLObjectException("child XMLObject cannot be added - it is already the child of another XMLObject");
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;
+}