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 using xercesc::DOMAttr;
33 using xercesc::DOMElement;
34 using xercesc::XMLString;
36 set<QName> AttributeExtensibleXMLObject::m_idAttributeSet;
38 AbstractAttributeExtensibleXMLObject::~AbstractAttributeExtensibleXMLObject()
40 for (map<QName,XMLCh*>::iterator i=m_attributeMap.begin(); i!=m_attributeMap.end(); i++)
41 XMLString::release(&(i->second));
44 AbstractAttributeExtensibleXMLObject::AbstractAttributeExtensibleXMLObject(const AbstractAttributeExtensibleXMLObject& src)
45 : AbstractXMLObject(src)
47 m_idAttribute = m_attributeMap.end();
48 for (map<QName,XMLCh*>::const_iterator i=src.m_attributeMap.begin(); i!=src.m_attributeMap.end(); i++) {
49 m_attributeMap[i->first] = XMLString::replicate(i->second);
51 if (src.m_idAttribute != src.m_attributeMap.end()) {
52 m_idAttribute = m_attributeMap.find(src.m_idAttribute->first);
56 void AbstractAttributeExtensibleXMLObject::setAttribute(const QName& qualifiedName, const XMLCh* value, bool ID)
58 map<QName,XMLCh*>::iterator i=m_attributeMap.find(qualifiedName);
59 if (i!=m_attributeMap.end()) {
60 releaseThisandParentDOM();
61 XMLString::release(&(i->second));
62 if (value && *value) {
63 i->second=XMLString::replicate(value);
69 m_idAttribute=m_attributeMap.end();
70 m_attributeMap.erase(i);
73 else if (value && *value) {
74 releaseThisandParentDOM();
75 m_attributeMap[qualifiedName]=XMLString::replicate(value);
77 m_idAttribute = m_attributeMap.find(qualifiedName);
81 void AbstractAttributeExtensibleXMLObject::unmarshallExtensionAttribute(const DOMAttr* attribute)
83 QName q(attribute->getNamespaceURI(),attribute->getLocalName(),attribute->getPrefix());
84 bool ID = attribute->isId() || isRegisteredIDAttribute(q);
85 setAttribute(q,attribute->getNodeValue(),ID);
87 #ifdef XMLTOOLING_XERCESC_BOOLSETIDATTRIBUTE
88 attribute->getOwnerElement()->setIdAttributeNode(attribute, true);
90 attribute->getOwnerElement()->setIdAttributeNode(attribute);
95 void AbstractAttributeExtensibleXMLObject::marshallExtensionAttributes(DOMElement* domElement) const
97 for (map<QName,XMLCh*>::const_iterator i=m_attributeMap.begin(); i!=m_attributeMap.end(); i++) {
98 DOMAttr* attr=domElement->getOwnerDocument()->createAttributeNS(i->first.getNamespaceURI(),i->first.getLocalPart());
99 if (i->first.hasPrefix())
100 attr->setPrefix(i->first.getPrefix());
101 attr->setNodeValue(i->second);
102 domElement->setAttributeNodeNS(attr);
103 if (m_idAttribute==i) {
104 #ifdef XMLTOOLING_XERCESC_BOOLSETIDATTRIBUTE
105 domElement->setIdAttributeNode(attr, true);
107 domElement->setIdAttributeNode(attr);