Update copyright.
[shibboleth/cpp-xmltooling.git] / xmltooling / validation / ValidatorSuite.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 ValidatorSuite.h
19  * 
20  * Groups of rule checkers of XMLObjects based on type or element name. 
21  */
22
23 #ifndef __xmltooling_valsuite_h__
24 #define __xmltooling_valsuite_h__
25
26 #include <xmltooling/QName.h>
27 #include <xmltooling/validation/Validator.h>
28
29 #include <map>
30
31 #if defined (_MSC_VER)
32     #pragma warning( push )
33     #pragma warning( disable : 4250 4251 )
34 #endif
35
36 namespace xmltooling {
37
38     /**
39      * A collection of validators that can be applied to an XMLObject and its children. These collections can represent
40      * usage specific checks, such as those outlined in schemas or profiles of specific XML specifications.
41      * 
42      * Registered Validators must be stateless. Validators are fetched based on schema type and
43      * element name, in that order.
44      */
45     class XMLTOOL_API ValidatorSuite
46     {
47     MAKE_NONCOPYABLE(ValidatorSuite);
48     public:
49         /**
50          * Creates a new suite.
51          * 
52          * @param id    an identifier for the suite
53          */
54         ValidatorSuite(const char* id) : m_id(id) {}
55         
56         ~ValidatorSuite() {
57             destroyValidators();
58         }
59
60         /**
61          * Gets a unique ID for this suite.
62          * 
63          * @return a unique ID for this suite
64          */
65         const char* getId() {
66             return m_id.c_str();
67         }
68
69         /**
70          * Evaluates the registered validators against the given XMLObject and it's children.
71          * 
72          * @param xmlObject the XMLObject tree to validate
73          * 
74          * @throws ValidationException thrown if the element tree is not valid
75          */
76         void validate(const XMLObject* xmlObject) const;
77
78         /**
79          * Registers a new validator for the given key.
80          * 
81          * @param key       the key used to retrieve the validator
82          * @param validator the validator
83          */
84         void registerValidator(const QName& key, Validator* validator) {
85             m_map.insert(std::make_pair(key,validator));
86         }
87
88         /**
89          * Deregisters validators.
90          * 
91          * @param key       the key for the validators to be deregistered
92          */
93         void deregisterValidators(const QName& key);
94
95         /**
96          * Unregisters and destroys all registered validators. 
97          */
98         void destroyValidators();
99
100     private:
101         std::string m_id;
102         std::multimap<QName,Validator*> m_map;
103     };
104
105     /**
106      * Validator suite for schema-style structural validation.
107      * 
108      * This is <strong>NOT</strong> a comprehensive replacement for real
109      * schema validation, but it does basic structural checking of overall
110      * element relationships and some basic attribute presence checking.
111      */
112     extern XMLTOOL_API xmltooling::ValidatorSuite SchemaValidators;
113     
114 };
115
116 #if defined (_MSC_VER)
117     #pragma warning( pop )
118 #endif
119
120 #endif /* __xmltooling_valsuite_h__ */