Merge branch '1.x' of ssh://authdev.it.ohio-state.edu/~scantor/git/cpp-xmltooling...
[shibboleth/cpp-xmltooling.git] / xmltooling / validation / ValidatorSuite.h
1 /**
2  * Licensed to the University Corporation for Advanced Internet
3  * Development, Inc. (UCAID) under one or more contributor license
4  * agreements. See the NOTICE file distributed with this work for
5  * additional information regarding copyright ownership.
6  *
7  * UCAID licenses this file to you under the Apache License,
8  * Version 2.0 (the "License"); you may not use this file except
9  * in compliance with the License. You may obtain a copy of the
10  * License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17  * either express or implied. See the License for the specific
18  * language governing permissions and limitations under the License.
19  */
20
21 /**
22  * @file xmltooling/validation/ValidatorSuite.h
23  * 
24  * Groups of rule checkers of XMLObjects based on type or element name. 
25  */
26
27 #ifndef __xmltooling_valsuite_h__
28 #define __xmltooling_valsuite_h__
29
30 #include <xmltooling/QName.h>
31
32 #include <map>
33 #include <string>
34
35 #if defined (_MSC_VER)
36     #pragma warning( push )
37     #pragma warning( disable : 4250 4251 )
38 #endif
39
40 namespace xmltooling {
41
42     class XMLTOOL_API Validator;
43
44     /**
45      * A collection of validators that can be applied to an XMLObject and its children. These collections can represent
46      * usage specific checks, such as those outlined in schemas or profiles of specific XML specifications.
47      * 
48      * Registered Validators must be stateless. Validators are fetched based on schema type and
49      * element name, in that order.
50      */
51     class XMLTOOL_API ValidatorSuite
52     {
53     MAKE_NONCOPYABLE(ValidatorSuite);
54     public:
55         /**
56          * Creates a new suite.
57          * 
58          * @param id    an identifier for the suite
59          */
60         ValidatorSuite(const char* id);
61         
62         ~ValidatorSuite();
63
64         /**
65          * Gets a unique ID for this suite.
66          * 
67          * @return a unique ID for this suite
68          */
69         const char* getId();
70
71         /**
72          * Evaluates the registered validators against the given XMLObject and it's children.
73          * 
74          * @param xmlObject the XMLObject tree to validate
75          * 
76          * @throws ValidationException thrown if the element tree is not valid
77          */
78         void validate(const XMLObject* xmlObject) const;
79
80         /**
81          * Registers a new validator for the given key.
82          * 
83          * @param key       the key used to retrieve the validator
84          * @param validator the validator
85          */
86         void registerValidator(const QName& key, Validator* validator);
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__ */