27c17029f4f834ee4913daee8c8cda5209cedb1c
[shibboleth/cpp-xmltooling.git] / xmltooling / impl / AnyElement.cpp
1 /*
2  *  Copyright 2001-2009 Internet2
3  * 
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 /**
18  * AnyElement.cpp
19  * 
20  * Advanced anyType implementation suitable for deep processing of unknown content.
21  */
22
23 #include "internal.h"
24 #include "exceptions.h"
25 #include "impl/AnyElement.h"
26 #include "util/NDC.h"
27 #include "util/XMLHelper.h"
28
29 #include <xercesc/util/XMLUniDefs.hpp>
30
31 using namespace xmltooling;
32 using namespace xercesc;
33 using namespace std;
34
35 AnyElementImpl::AnyElementImpl()
36 {
37 }
38
39 AnyElementImpl::AnyElementImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const xmltooling::QName* schemaType)
40     : AbstractXMLObject(nsURI, localName, prefix, schemaType)
41 {
42 }
43
44 AnyElementImpl::~AnyElementImpl()
45 {
46 }
47
48 XMLObject* AnyElementImpl::clone() const {
49     auto_ptr<XMLObject> domClone(AbstractDOMCachingXMLObject::clone());
50     AnyElementImpl* ret=dynamic_cast<AnyElementImpl*>(domClone.get());
51     if (ret) {
52         domClone.release();
53         return ret;
54     }
55
56     return new AnyElementImpl(*this);
57 }
58
59 AnyElementImpl::AnyElementImpl(const AnyElementImpl& src)
60         : AbstractXMLObject(src),
61           AbstractDOMCachingXMLObject(src),
62           AbstractComplexElement(src),
63           AbstractAttributeExtensibleXMLObject(src) {
64     const vector<XMLObject*>& children = src.getUnknownXMLObjects();
65     for (vector<XMLObject*>::const_iterator i=children.begin(); i!=children.end(); ++i)
66         getUnknownXMLObjects().push_back((*i)->clone());
67 }       
68
69 void AnyElementImpl::marshallAttributes(DOMElement* domElement) const
70 {
71     marshallExtensionAttributes(domElement);
72 }
73
74 void AnyElementImpl::processChildElement(XMLObject* childXMLObject, const DOMElement* root)
75 {
76     getUnknownXMLObjects().push_back(childXMLObject);
77 }
78
79 void AnyElementImpl::processAttribute(const DOMAttr* attribute)
80 {
81     unmarshallExtensionAttribute(attribute);
82 }
83
84 XMLObject* AnyElementBuilder::buildObject(
85     const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const xmltooling::QName* schemaType
86     ) const
87 {
88     return new AnyElementImpl(nsURI, localName, prefix, schemaType);
89 }