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 * AbstractValidatingXMLObject.cpp
\r
20 * Extension of AbstractXMLObject that implements a ValidatingXMLObject.
\r
23 #include "internal.h"
\r
24 #include "exceptions.h"
\r
25 #include "validation/AbstractValidatingXMLObject.h"
\r
27 #include <algorithm>
\r
28 #include <functional>
\r
30 using namespace xmltooling;
\r
31 using namespace std;
\r
33 AbstractValidatingXMLObject::ValidatorWrapper::~ValidatorWrapper()
\r
35 for_each(v.begin(),v.end(),cleanup<Validator>());
\r
38 AbstractValidatingXMLObject::AbstractValidatingXMLObject(const AbstractValidatingXMLObject& src) : AbstractXMLObject(src)
\r
40 if (src.m_validators) {
\r
41 m_validators=new ValidatorWrapper();
\r
42 xmltooling::clone(src.m_validators->v,m_validators->v);
\r
46 AbstractValidatingXMLObject::~AbstractValidatingXMLObject()
\r
48 delete m_validators;
\r
51 void AbstractValidatingXMLObject::registerValidator(Validator* validator) const
\r
54 m_validators=new ValidatorWrapper();
\r
55 m_validators->v.push_back(validator);
\r
58 void AbstractValidatingXMLObject::deregisterValidator(Validator* validator) const
\r
61 for (std::vector<Validator*>::iterator i=m_validators->v.begin(); i!=m_validators->v.end(); i++) {
\r
62 if ((*i)==validator)
\r
63 m_validators->v.erase(i);
\r
69 class _validate : public binary_function<const XMLObject*,bool,void> {
\r
71 void operator()(const XMLObject* obj, bool propagate) const {
\r
72 const ValidatingXMLObject* val = dynamic_cast<const ValidatingXMLObject*>(obj);
\r
74 val->validate(propagate);
\r
79 void AbstractValidatingXMLObject::validate(bool validateDescendants) const
\r
83 m_validators->v.begin(),m_validators->v.end(),
\r
84 bind2nd(mem_fun<void,Validator,const XMLObject*>(&Validator::validate),this)
\r
88 if (validateDescendants && hasChildren()) {
\r
89 for_each(m_children.begin(),m_children.end(),bind2nd(_validate(),validateDescendants));
\r