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.
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 * @file saml/saml2/metadata/EndpointManager.h
24 * Templates for processing endpoint information.
27 #ifndef __saml_epmgr_h__
28 #define __saml_epmgr_h__
30 #include <saml/base.h>
33 #include <xercesc/util/XMLString.hpp>
39 * Template for processing unindexed endpoint information.
41 * @param _Tx the endpoint type being managed
47 /** Reference to endpoint array. */
48 const typename std::vector<_Tx*>& m_endpoints;
54 * @param endpoints array of endpoints to manage
56 EndpointManager(const typename std::vector<_Tx*>& endpoints) : m_endpoints(endpoints) {
60 * Returns endpoint that supports a particular binding.
62 * @param binding binding to locate
63 * @return a supporting endpoint, favoring the default, or nullptr
65 const _Tx* getByBinding(const XMLCh* binding) const {
66 for (typename std::vector<_Tx*>::const_iterator i = m_endpoints.begin(); i!=m_endpoints.end(); ++i) {
67 if (xercesc::XMLString::equals(binding,(*i)->getBinding()))
75 * Template for processing indexed endpoint information.
77 * @param _Tx the endpoint type being managed
80 class IndexedEndpointManager : public EndpointManager<_Tx>
88 * @param endpoints array of endpoints to manage
90 IndexedEndpointManager(const typename std::vector<_Tx*>& endpoints) : EndpointManager<_Tx>(endpoints), m_default(nullptr) {
94 * Returns the default endpoint in the set.
96 * @return the default endpoint
98 const _Tx* getDefault() const {
101 for (typename std::vector<_Tx*>::const_iterator i = EndpointManager<_Tx>::m_endpoints.begin(); i!=EndpointManager<_Tx>::m_endpoints.end(); ++i) {
102 if ((*i)->isDefault())
105 return (EndpointManager<_Tx>::m_endpoints.empty()) ? m_default=nullptr : m_default=EndpointManager<_Tx>::m_endpoints.front();
109 * Returns indexed endpoint.
111 * @param index index to locate
112 * @return matching endpoint, or nullptr
114 const _Tx* getByIndex(unsigned short index) const {
115 for (typename std::vector<_Tx*>::const_iterator i = EndpointManager<_Tx>::m_endpoints.begin(); i!=EndpointManager<_Tx>::m_endpoints.end(); ++i) {
116 std::pair<bool,int> comp = (*i)->getIndex();
117 if (comp.first && index == comp.second)
124 * Returns endpoint that supports a particular binding.
126 * @param binding binding to locate
127 * @return a supporting endpoint, favoring the default, or nullptr
129 const _Tx* getByBinding(const XMLCh* binding) const {
130 if (getDefault() && xercesc::XMLString::equals(binding,m_default->getBinding()))
132 return EndpointManager<_Tx>::getByBinding(binding);
138 #endif /* __saml_epmgr_h__ */