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.
18 * @file saml/saml2/metadata/EndpointManager.h
20 * Templates for processing endpoint information.
23 #ifndef __saml_epmgr_h__
24 #define __saml_epmgr_h__
26 #include <saml/base.h>
32 * Template for processing unindexed endpoint information.
34 * @param _Tx the endpoint type being managed
40 typename const std::vector<_Tx*>& m_endpoints;
46 * @param endpoints array of endpoints to manage
48 EndpointManager(typename const std::vector<_Tx*>& endpoints) : m_endpoints(endpoints) {
52 * Returns endpoint that supports a particular binding.
54 * @param binding binding to locate
55 * @return a supporting endpoint, favoring the default, or NULL
57 const _Tx* getByBinding(const XMLCh* binding) const {
58 for (std::vector<_Tx*>::const_iterator i = m_endpoints.begin(); i!=m_endpoints.end(); ++i) {
59 if (xercesc::XMLString::equals(binding,(*i)->getBinding()))
67 * Template for processing indexed endpoint information.
69 * @param _Tx the endpoint type being managed
72 class IndexedEndpointManager : public EndpointManager<_Tx>
74 typename const _Tx* m_default;
80 * @param endpoints array of endpoints to manage
82 IndexedEndpointManager(typename const std::vector<_Tx*>& endpoints) : EndpointManager(endpoints), m_default(NULL) {
86 * Returns the default endpoint in the set.
88 * @return the default endpoint
90 const _Tx* getDefault() const {
93 for (std::vector<_Tx*>::const_iterator i = m_endpoints.begin(); i!=m_endpoints.end(); ++i) {
94 if ((*i)->isDefault())
97 return (m_endpoints.empty()) ? m_default=NULL : m_default=m_endpoints.front();
101 * Returns indexed endpoint.
103 * @param index index to locate
104 * @return matching endpoint, or NULL
106 const _Tx* getByIndex(unsigned short index) const {
107 for (std::vector<_Tx*>::const_iterator i = m_endpoints.begin(); i!=m_endpoints.end(); ++i) {
108 std::pair<bool,int> comp = (*i)->getIndex();
109 if (comp.first && index == comp.second)
116 * Returns endpoint that supports a particular binding.
118 * @param binding binding to locate
119 * @return a supporting endpoint, favoring the default, or NULL
121 const _Tx* getByBinding(const XMLCh* binding) const {
122 if (getDefault() && xercesc::XMLString::equals(binding,m_default->getBinding()))
124 return EndpointManager::getByBinding(binding);
130 #endif /* __saml_epmgr_h__ */