Multi-line svn commit, see body.
[shibboleth/cpp-opensaml.git] / saml / saml2 / metadata / impl / NullMetadataProvider.cpp
1 /*
2  *  Copyright 2001-2007 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  * NullMetadataProvider.cpp
19  * 
20  * Dummy provider that returns an empty entity supporting any role.
21  */
22
23 #include "internal.h"
24 #include "saml2/metadata/Metadata.h"
25 #include "saml2/metadata/DynamicMetadataProvider.h"
26
27 #include <xmltooling/util/XMLHelper.h>
28
29 using namespace opensaml::saml2md;
30 using namespace xmltooling;
31 using namespace std;
32
33 namespace opensaml {
34     namespace saml2md {
35         class SAML_DLLLOCAL NullMetadataProvider : public DynamicMetadataProvider
36         {
37         public:
38             NullMetadataProvider(const DOMElement* e) : DynamicMetadataProvider(e), m_template(NULL) {
39                 e = XMLHelper::getFirstChildElement(e, samlconstants::SAML20MD_NS, EntityDescriptor::LOCAL_NAME);
40                 if (e)
41                     m_template = dynamic_cast<EntityDescriptor*>(XMLObjectBuilder::buildOneFromElement(const_cast<DOMElement*>(e)));
42             }
43
44             virtual ~NullMetadataProvider() {
45                 delete m_template;
46             }
47
48         protected:
49             EntityDescriptor* resolve(const char* entityID) const;
50
51         private:
52             EntityDescriptor* m_template;
53         }; 
54
55         MetadataProvider* SAML_DLLLOCAL NullMetadataProviderFactory(const DOMElement* const & e)
56         {
57             return new NullMetadataProvider(e);
58         }
59     };
60 };
61
62 EntityDescriptor* NullMetadataProvider::resolve(const char* entityID) const
63 {
64     // Resolving for us just means fabricating a new dummy element.
65     EntityDescriptor* entity = m_template ? m_template->cloneEntityDescriptor() : EntityDescriptorBuilder::buildEntityDescriptor();
66     auto_ptr_XMLCh temp(entityID);
67     entity->setEntityID(temp.get());
68     return entity;
69 }