Missed parameter to log validator exceptions.
[shibboleth/cpp-opensaml.git] / saml / saml2 / metadata / EndpointManager.h
1 /*
2  *  Copyright 2001-2007 Internet2
3  * 
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 /**
18  * @file saml/saml2/metadata/EndpointManager.h
19  * 
20  * Templates for processing endpoint information.
21  */
22
23 #ifndef __saml_epmgr_h__
24 #define __saml_epmgr_h__
25
26 #include <saml/base.h>
27
28 namespace opensaml {
29     namespace saml2md {
30         
31         /**
32          * Template for processing unindexed endpoint information.
33          * 
34          * @param _Tx   the endpoint type being managed
35          */
36         template <class _Tx>
37         class EndpointManager
38         {
39         protected:
40             /** Reference to endpoint array. */
41             const typename std::vector<_Tx*>& m_endpoints;
42             
43         public:
44             /**
45              * Constructor.
46              *
47              * @param endpoints array of endpoints to manage
48              */
49             EndpointManager(const typename std::vector<_Tx*>& endpoints) : m_endpoints(endpoints) {
50             }
51             
52             /**
53              * Returns endpoint that supports a particular binding.
54              * 
55              * @param binding   binding to locate
56              * @return a supporting endpoint, favoring the default, or NULL
57              */
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()))
61                         return *i;
62                 }
63                 return NULL;
64             }
65         };
66
67         /**
68          * Template for processing indexed endpoint information.
69          * 
70          * @param _Tx   the endpoint type being managed
71          */
72         template <class _Tx>
73         class IndexedEndpointManager : public EndpointManager<_Tx>
74         {
75             const _Tx* m_default;
76             
77         public:
78             /**
79              * Constructor.
80              *
81              * @param endpoints array of endpoints to manage
82              */
83             IndexedEndpointManager(const typename std::vector<_Tx*>& endpoints) : EndpointManager<_Tx>(endpoints), m_default(NULL) {
84             }
85             
86             /**
87              * Returns the default endpoint in the set.
88              * 
89              * @return the default endpoint 
90              */
91             const _Tx* getDefault() const {
92                 if (m_default)
93                     return m_default;
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())
96                         return m_default=*i;
97                 }
98                 return (EndpointManager<_Tx>::m_endpoints.empty()) ? m_default=NULL : m_default=EndpointManager<_Tx>::m_endpoints.front();
99             }
100             
101             /**
102              * Returns indexed endpoint.
103              * 
104              * @param index index to locate
105              * @return matching endpoint, or NULL
106              */
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)
111                         return *i;
112                 }
113                 return NULL;
114             }
115             
116             /**
117              * Returns endpoint that supports a particular binding.
118              * 
119              * @param binding   binding to locate
120              * @return a supporting endpoint, favoring the default, or NULL
121              */
122             const _Tx* getByBinding(const XMLCh* binding) const {
123                 if (getDefault() && xercesc::XMLString::equals(binding,m_default->getBinding()))
124                     return m_default;
125                 return EndpointManager<_Tx>::getByBinding(binding);
126             }
127         };
128     };
129 };
130
131 #endif /* __saml_epmgr_h__ */