2 * Copyright 2001-2006 Internet2
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
18 * @file ValidatorSuite.h
\r
20 * Groups of rule checkers of XMLObjects based on type or element name.
\r
23 #ifndef __xmltooling_valsuite_h__
\r
24 #define __xmltooling_valsuite_h__
\r
28 #include <xmltooling/QName.h>
\r
29 #include <xmltooling/validation/Validator.h>
\r
31 #if defined (_MSC_VER)
\r
32 #pragma warning( push )
\r
33 #pragma warning( disable : 4250 4251 )
\r
36 namespace xmltooling {
\r
39 * A collection of validators that can be applied to an XMLObject and its children. These collections can represent
\r
40 * usage specific checks, such as those outlined in schemas or profiles of specific XML specifications.
\r
42 * Registered Validators must be stateless and cloneable. Validators are fetched based on schema type and
\r
43 * element name, in that order.
\r
45 class XMLTOOL_API ValidatorSuite
\r
47 MAKE_NONCOPYABLE(ValidatorSuite);
\r
50 * Creates a new suite.
\r
52 * @param id an identifier for the suite
\r
54 ValidatorSuite(const char* id) : m_id(id) {}
\r
57 destroyValidators();
\r
61 * Gets a unique ID for this suite.
\r
63 * @return a unique ID for this suite
\r
65 const char* getId() {
\r
66 return m_id.c_str();
\r
70 * Evaluates the registered validators against the given XMLObject and it's children.
\r
72 * @param xmlObject the XMLObject tree to validate
\r
74 * @throws ValidationException thrown if the element tree is not valid
\r
76 void validate(const XMLObject* xmlObject) const;
\r
79 * Registers a new validator for the given key.
\r
81 * @param key the key used to retrieve the validator
\r
82 * @param validator the validator
\r
84 void registerValidator(const QName& key, Validator* validator) {
\r
85 std::map< QName, std::vector<Validator*> >::iterator i=m_map.find(key);
\r
87 m_map.insert(std::make_pair(key,std::vector<Validator*>(1,validator)));
\r
89 i->second.push_back(validator);
\r
93 * Deregisters validators.
\r
95 * @param key the key for the validators to be deregistered
\r
97 void deregisterValidators(const QName& key);
\r
100 * Unregisters and destroys all registered validators.
\r
102 void destroyValidators();
\r
106 std::map< QName, std::vector<Validator*> > m_map;
\r
111 #if defined (_MSC_VER)
\r
112 #pragma warning( pop )
\r
115 #endif /* __xmltooling_valsuite_h__ */
\r