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 * shibsp/attribute/Attribute.cpp
20 * A resolved attribute.
24 #include "attribute/AttributeDecoder.h"
25 #include "attribute/SimpleAttribute.h"
26 #include "attribute/ScopedAttribute.h"
27 #include "attribute/NameIDAttribute.h"
29 #include <shibsp/SPConfig.h>
31 using namespace shibsp;
32 using namespace xmltooling;
37 SHIBSP_DLLLOCAL Attribute* SimpleAttributeFactory(DDF& in) {
38 return new SimpleAttribute(in);
41 SHIBSP_DLLLOCAL Attribute* ScopedAttributeFactory(DDF& in) {
42 return new ScopedAttribute(in);
45 SHIBSP_DLLLOCAL Attribute* NameIDAttributeFactory(DDF& in) {
46 return new NameIDAttribute(in);
49 SHIBSP_DLLLOCAL PluginManager<AttributeDecoder,const DOMElement*>::Factory SimpleAttributeDecoderFactory;
50 SHIBSP_DLLLOCAL PluginManager<AttributeDecoder,const DOMElement*>::Factory ScopedAttributeDecoderFactory;
51 SHIBSP_DLLLOCAL PluginManager<AttributeDecoder,const DOMElement*>::Factory NameIDAttributeDecoderFactory;
54 void shibsp::registerAttributeDecoders()
56 SPConfig& conf = SPConfig::getConfig();
57 conf.AttributeDecoderManager.registerFactory(SIMPLE_ATTRIBUTE_DECODER, SimpleAttributeDecoderFactory);
58 conf.AttributeDecoderManager.registerFactory(SCOPED_ATTRIBUTE_DECODER, ScopedAttributeDecoderFactory);
59 conf.AttributeDecoderManager.registerFactory(NAMEID_ATTRIBUTE_DECODER, NameIDAttributeDecoderFactory);
62 void shibsp::registerAttributeFactories()
64 Attribute::registerFactory("", SimpleAttributeFactory);
65 Attribute::registerFactory("Simple", SimpleAttributeFactory);
66 Attribute::registerFactory("Scoped", ScopedAttributeFactory);
67 Attribute::registerFactory("NameID", NameIDAttributeFactory);
70 std::map<std::string,Attribute::AttributeFactory*> Attribute::m_factoryMap;
72 Attribute* Attribute::unmarshall(DDF& in)
74 map<string,AttributeFactory*>::const_iterator i = m_factoryMap.find(in.name() ? in.name() : "");
75 if (i == m_factoryMap.end())
76 throw AttributeException("No registered factory for Attribute of type ($1).", xmltooling::params(1,in.name()));
77 return (i->second)(in);