boost changes and header fixes
[shibboleth/cpp-opensaml.git] / saml / saml2 / metadata / impl / NullMetadataProvider.cpp
1 /**
2  * Licensed to the University Corporation for Advanced Internet
3  * Development, Inc. (UCAID) under one or more contributor license
4  * agreements. See the NOTICE file distributed with this work for
5  * additional information regarding copyright ownership.
6  *
7  * UCAID licenses this file to you under the Apache License,
8  * Version 2.0 (the "License"); you may not use this file except
9  * in compliance with the License. You may obtain a copy of the
10  * License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17  * either express or implied. See the License for the specific
18  * language governing permissions and limitations under the License.
19  */
20
21 /**
22  * NullMetadataProvider.cpp
23  * 
24  * Dummy provider that returns an empty entity supporting any role.
25  */
26
27 #include "internal.h"
28 #include "saml2/metadata/Metadata.h"
29 #include "saml2/metadata/DynamicMetadataProvider.h"
30
31 #include <xmltooling/util/XMLHelper.h>
32
33 using namespace opensaml::saml2md;
34 using namespace xmltooling;
35 using namespace std;
36
37 namespace opensaml {
38     namespace saml2md {
39         class SAML_DLLLOCAL NullMetadataProvider : public DynamicMetadataProvider
40         {
41         public:
42             NullMetadataProvider(const DOMElement* e) : DynamicMetadataProvider(e) {
43                 e = XMLHelper::getFirstChildElement(e, samlconstants::SAML20MD_NS, EntityDescriptor::LOCAL_NAME);
44                 if (e)
45                     m_template.reset(dynamic_cast<EntityDescriptor*>(XMLObjectBuilder::buildOneFromElement(const_cast<DOMElement*>(e))));
46             }
47
48             virtual ~NullMetadataProvider() {}
49
50         protected:
51             EntityDescriptor* resolve(const char* entityID) const;
52
53         private:
54             auto_ptr<EntityDescriptor> m_template;
55         }; 
56
57         MetadataProvider* SAML_DLLLOCAL NullMetadataProviderFactory(const DOMElement* const & e)
58         {
59             return new NullMetadataProvider(e);
60         }
61     };
62 };
63
64 EntityDescriptor* NullMetadataProvider::resolve(const char* entityID) const
65 {
66     // Resolving for us just means fabricating a new dummy element.
67     EntityDescriptor* entity = m_template.get() ? m_template->cloneEntityDescriptor() : EntityDescriptorBuilder::buildEntityDescriptor();
68     auto_ptr_XMLCh temp(entityID);
69     entity->setEntityID(temp.get());
70     return entity;
71 }