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
20 * Rules checking of XMLObjects
\r
23 #if !defined(__xmltooling_validator_h__)
\r
24 #define __xmltooling_validator_h__
\r
28 #include <xmltooling/QName.h>
\r
29 #include <xmltooling/XMLObject.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 * An interface for classes that implement rules for checking the
\r
40 * validity of XMLObjects.
\r
42 class XMLTOOL_API Validator
\r
44 MAKE_NONCOPYABLE(Validator);
\r
46 virtual ~Validator() {}
\r
49 * Checks to see if an XMLObject is valid.
\r
51 * @param xmlObject the XMLObject to validate
\r
53 * @throws ValidationException thrown if the element is not valid
\r
55 virtual void validate(const XMLObject* xmlObject) const=0;
\r
58 * Returns a copy of the validator.
\r
60 * @return the new validator
\r
62 virtual Validator* clone() const=0;
\r
65 * Evaluates the registered validators against the given XMLObject and it's children.
\r
67 * @param xmlObject the XMLObject tree to validate
\r
69 * @throws ValidationException thrown if the element tree is not valid
\r
71 static void checkValidity(const XMLObject* xmlObject);
\r
74 * Registers a new validator for the given key.
\r
76 * @param key the key used to retrieve the validator
\r
77 * @param validator the validator
\r
79 static void registerValidator(const QName& key, Validator* validator) {
\r
80 std::map< QName, std::vector<Validator*> >::iterator i=m_map.find(key);
\r
82 m_map.insert(std::make_pair(key,std::vector<Validator*>(1,validator)));
\r
84 i->second.push_back(validator);
\r
88 * Deregisters validators.
\r
90 * @param key the key for the validators to be deregistered
\r
92 static void deregisterValidators(const QName& key);
\r
95 * Unregisters and destroys all registered validators.
\r
97 static void destroyValidators();
\r
103 static std::map< QName, std::vector<Validator*> > m_map;
\r
108 #if defined (_MSC_VER)
\r
109 #pragma warning( pop )
\r
112 #endif /* __xmltooling_validator_h__ */
\r