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 * @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 /** Reference to endpoint array. */
41 const typename std::vector<_Tx*>& m_endpoints;
47 * @param endpoints array of endpoints to manage
49 EndpointManager(const typename std::vector<_Tx*>& endpoints) : m_endpoints(endpoints) {
53 * Returns endpoint that supports a particular binding.
55 * @param binding binding to locate
56 * @return a supporting endpoint, favoring the default, or NULL
58 const _Tx* getByBinding(const XMLCh* binding) const {
59 for (typename std::vector<_Tx*>::const_iterator i = m_endpoints.begin(); i!=m_endpoints.end(); ++i) {
60 if (xercesc::XMLString::equals(binding,(*i)->getBinding()))
68 * Template for processing indexed endpoint information.
70 * @param _Tx the endpoint type being managed
73 class IndexedEndpointManager : public EndpointManager<_Tx>
81 * @param endpoints array of endpoints to manage
83 IndexedEndpointManager(const typename std::vector<_Tx*>& endpoints) : EndpointManager<_Tx>(endpoints), m_default(NULL) {
87 * Returns the default endpoint in the set.
89 * @return the default endpoint
91 const _Tx* getDefault() const {
94 for (typename std::vector<_Tx*>::const_iterator i = EndpointManager<_Tx>::m_endpoints.begin(); i!=EndpointManager<_Tx>::m_endpoints.end(); ++i) {
95 if ((*i)->isDefault())
98 return (EndpointManager<_Tx>::m_endpoints.empty()) ? m_default=NULL : m_default=EndpointManager<_Tx>::m_endpoints.front();
102 * Returns indexed endpoint.
104 * @param index index to locate
105 * @return matching endpoint, or NULL
107 const _Tx* getByIndex(unsigned short index) const {
108 for (typename std::vector<_Tx*>::const_iterator i = EndpointManager<_Tx>::m_endpoints.begin(); i!=EndpointManager<_Tx>::m_endpoints.end(); ++i) {
109 std::pair<bool,int> comp = (*i)->getIndex();
110 if (comp.first && index == comp.second)
117 * Returns endpoint that supports a particular binding.
119 * @param binding binding to locate
120 * @return a supporting endpoint, favoring the default, or NULL
122 const _Tx* getByBinding(const XMLCh* binding) const {
123 if (getDefault() && xercesc::XMLString::equals(binding,m_default->getBinding()))
125 return EndpointManager<_Tx>::getByBinding(binding);
131 #endif /* __saml_epmgr_h__ */