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