2 * Copyright 2001-2006 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.
20 * Advanced anyType implementation suitable for deep processing of unknown content.
24 #include "exceptions.h"
25 #include "impl/AnyElement.h"
27 #include "util/XMLHelper.h"
29 #include <log4cpp/Category.hh>
30 #include <xercesc/util/XMLUniDefs.hpp>
32 using namespace xmltooling;
33 using namespace log4cpp;
36 XMLObject* AnyElementImpl::clone() const {
37 auto_ptr<XMLObject> domClone(AbstractDOMCachingXMLObject::clone());
38 AnyElementImpl* ret=dynamic_cast<AnyElementImpl*>(domClone.get());
44 return new AnyElementImpl(*this);
47 AnyElementImpl::AnyElementImpl(const AnyElementImpl& src) : AbstractXMLObject(src), AbstractDOMCachingXMLObject(src),
48 AbstractElementProxy(src), AbstractAttributeExtensibleXMLObject(src) {
49 for (list<XMLObject*>::const_iterator i=src.m_children.begin(); i!=src.m_children.end(); i++) {
50 getXMLObjects().push_back((*i) ? (*i)->clone() : NULL);
54 void AnyElementImpl::marshallAttributes(DOMElement* domElement) const {
55 for (map<QName,XMLCh*>::const_iterator i=m_attributeMap.begin(); i!=m_attributeMap.end(); i++) {
56 DOMAttr* attr=domElement->getOwnerDocument()->createAttributeNS(i->first.getNamespaceURI(),i->first.getLocalPart());
57 if (i->first.hasPrefix())
58 attr->setPrefix(i->first.getPrefix());
59 attr->setNodeValue(i->second);
60 domElement->setAttributeNode(attr);
64 void AnyElementImpl::marshallElementContent(DOMElement* domElement) const {
65 if(getTextContent()) {
66 domElement->appendChild(domElement->getOwnerDocument()->createTextNode(getTextContent()));
70 void AnyElementImpl::processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
71 getXMLObjects().push_back(childXMLObject);
74 void AnyElementImpl::processAttribute(const DOMAttr* attribute) {
75 QName q(attribute->getNamespaceURI(),attribute->getLocalName(),attribute->getPrefix());
76 setAttribute(q,attribute->getNodeValue());
79 void AnyElementImpl::processElementContent(const XMLCh* elementContent) {
80 setTextContent(elementContent);
83 XMLObject* AnyElementBuilder::buildObject(
84 const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType
86 return new AnyElementImpl(nsURI, localName, prefix, schemaType);