2 * Copyright 2001-2009 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>
29 #include <xercesc/util/XMLString.hpp>
35 * Template for processing unindexed endpoint information.
37 * @param _Tx the endpoint type being managed
43 /** Reference to endpoint array. */
44 const typename std::vector<_Tx*>& m_endpoints;
50 * @param endpoints array of endpoints to manage
52 EndpointManager(const typename std::vector<_Tx*>& endpoints) : m_endpoints(endpoints) {
56 * Returns endpoint that supports a particular binding.
58 * @param binding binding to locate
59 * @return a supporting endpoint, favoring the default, or NULL
61 const _Tx* getByBinding(const XMLCh* binding) const {
62 for (typename std::vector<_Tx*>::const_iterator i = m_endpoints.begin(); i!=m_endpoints.end(); ++i) {
63 if (xercesc::XMLString::equals(binding,(*i)->getBinding()))
71 * Template for processing indexed endpoint information.
73 * @param _Tx the endpoint type being managed
76 class IndexedEndpointManager : public EndpointManager<_Tx>
84 * @param endpoints array of endpoints to manage
86 IndexedEndpointManager(const typename std::vector<_Tx*>& endpoints) : EndpointManager<_Tx>(endpoints), m_default(NULL) {
90 * Returns the default endpoint in the set.
92 * @return the default endpoint
94 const _Tx* getDefault() const {
97 for (typename std::vector<_Tx*>::const_iterator i = EndpointManager<_Tx>::m_endpoints.begin(); i!=EndpointManager<_Tx>::m_endpoints.end(); ++i) {
98 if ((*i)->isDefault())
101 return (EndpointManager<_Tx>::m_endpoints.empty()) ? m_default=NULL : m_default=EndpointManager<_Tx>::m_endpoints.front();
105 * Returns indexed endpoint.
107 * @param index index to locate
108 * @return matching endpoint, or NULL
110 const _Tx* getByIndex(unsigned short index) const {
111 for (typename std::vector<_Tx*>::const_iterator i = EndpointManager<_Tx>::m_endpoints.begin(); i!=EndpointManager<_Tx>::m_endpoints.end(); ++i) {
112 std::pair<bool,int> comp = (*i)->getIndex();
113 if (comp.first && index == comp.second)
120 * Returns endpoint that supports a particular binding.
122 * @param binding binding to locate
123 * @return a supporting endpoint, favoring the default, or NULL
125 const _Tx* getByBinding(const XMLCh* binding) const {
126 if (getDefault() && xercesc::XMLString::equals(binding,m_default->getBinding()))
128 return EndpointManager<_Tx>::getByBinding(binding);
134 #endif /* __saml_epmgr_h__ */