2 * Copyright 2001-2007 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * AbstractAttributeExtensibleXMLObject.cpp
20 * Extension of AbstractDOMCachingXMLObject that implements an AttributeExtensibleXMLObject.
24 #include "AbstractAttributeExtensibleXMLObject.h"
29 using namespace xmltooling;
32 set<QName> AttributeExtensibleXMLObject::m_idAttributeSet;
34 AbstractAttributeExtensibleXMLObject::~AbstractAttributeExtensibleXMLObject()
36 for (map<QName,XMLCh*>::iterator i=m_attributeMap.begin(); i!=m_attributeMap.end(); i++)
37 XMLString::release(&(i->second));
40 AbstractAttributeExtensibleXMLObject::AbstractAttributeExtensibleXMLObject(const AbstractAttributeExtensibleXMLObject& src)
41 : AbstractXMLObject(src)
43 m_idAttribute = m_attributeMap.end();
44 for (map<QName,XMLCh*>::const_iterator i=src.m_attributeMap.begin(); i!=src.m_attributeMap.end(); i++) {
45 m_attributeMap[i->first] = XMLString::replicate(i->second);
47 if (src.m_idAttribute != src.m_attributeMap.end()) {
48 m_idAttribute = m_attributeMap.find(src.m_idAttribute->first);
52 void AbstractAttributeExtensibleXMLObject::setAttribute(const QName& qualifiedName, const XMLCh* value, bool ID)
54 map<QName,XMLCh*>::iterator i=m_attributeMap.find(qualifiedName);
55 if (i!=m_attributeMap.end()) {
56 releaseThisandParentDOM();
57 XMLString::release(&(i->second));
58 if (value && *value) {
59 i->second=XMLString::replicate(value);
65 m_idAttribute=m_attributeMap.end();
66 m_attributeMap.erase(i);
69 else if (value && *value) {
70 releaseThisandParentDOM();
71 m_attributeMap[qualifiedName]=XMLString::replicate(value);
73 m_idAttribute = m_attributeMap.find(qualifiedName);
77 void AbstractAttributeExtensibleXMLObject::unmarshallExtensionAttribute(const DOMAttr* attribute)
79 QName q(attribute->getNamespaceURI(),attribute->getLocalName(),attribute->getPrefix());
80 bool ID = attribute->isId() || isRegisteredIDAttribute(q);
81 setAttribute(q,attribute->getNodeValue(),ID);
83 attribute->getOwnerElement()->setIdAttributeNode(attribute);
87 void AbstractAttributeExtensibleXMLObject::marshallExtensionAttributes(DOMElement* domElement) const
89 for (map<QName,XMLCh*>::const_iterator i=m_attributeMap.begin(); i!=m_attributeMap.end(); i++) {
90 DOMAttr* attr=domElement->getOwnerDocument()->createAttributeNS(i->first.getNamespaceURI(),i->first.getLocalPart());
91 if (i->first.hasPrefix())
92 attr->setPrefix(i->first.getPrefix());
93 attr->setNodeValue(i->second);
94 domElement->setAttributeNodeNS(attr);
96 domElement->setIdAttributeNode(attr);