Add per-object validation.
[shibboleth/cpp-xmltooling.git] / xmltooling / validation / ValidatingXMLObject.h
diff --git a/xmltooling/validation/ValidatingXMLObject.h b/xmltooling/validation/ValidatingXMLObject.h
new file mode 100644 (file)
index 0000000..07d4a0e
--- /dev/null
@@ -0,0 +1,80 @@
+/*\r
+ *  Copyright 2001-2006 Internet2\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+/**\r
+ * @file ValidatingXMLObject.h\r
+ * \r
+ * An XMLObject that can evaluate per-object validation rules.  \r
+ */\r
+\r
+#if !defined(__xmltooling_valxmlobj_h__)\r
+#define __xmltooling_valxmlobj_h__\r
+\r
+#include <vector>\r
+#include <xmltooling/XMLObject.h>\r
+#include <xmltooling/validation/Validator.h>\r
+\r
+#if defined (_MSC_VER)\r
+    #pragma warning( push )\r
+    #pragma warning( disable : 4250 4251 )\r
+#endif\r
+\r
+namespace xmltooling {\r
+\r
+    /**\r
+     * A functional interface for XMLObjects that offer the ability\r
+     * to evaluate validation rules defined per-object.\r
+     */\r
+    class XMLTOOL_API ValidatingXMLObject : public virtual XMLObject\r
+    {\r
+    protected:\r
+        ValidatingXMLObject() {}\r
+    \r
+    public:\r
+        virtual ~ValidatingXMLObject() {}\r
+        \r
+        /**\r
+         * Registers a validator for this XMLObject.\r
+         * \r
+         * @param validator the validator\r
+         */\r
+        virtual void registerValidator(Validator* validator) const=0;\r
+        \r
+        /**\r
+         * Deregisters a validator for this XMLObject.\r
+         * \r
+         * @param validator the validator\r
+         */\r
+        virtual void deregisterValidator(Validator* validator) const=0;\r
+        \r
+        /**\r
+         * Validates this XMLObject against all registered validators.\r
+         * \r
+         * @param validateDescendants true if all the descendants of this object should \r
+         * be validated as well, false if not\r
+         * \r
+         * @throws ValidationException thrown if the object is not valid\r
+         */\r
+        virtual void validate(bool validateDescendants) const=0;\r
+    };\r
+    \r
+};\r
+\r
+#if defined (_MSC_VER)\r
+    #pragma warning( pop )\r
+#endif\r
+\r
+#endif /* __xmltooling_valxmlobj_h__ */\r