#include <rwsf/core/XmlValidator.h>
rwsf::XmlValidator methods are used in classes generated by Hydra to check values in instance documents, working through the isValid() method of each generated class. This method in generated classes validates simple type data in an instance document based on facets defined in the XML schema for that document type. In an XML schema, simple types can have associated facets that restrict the allowable data values for an element or attribute of the specified type.
When isValid() is called on one of the generated datatype classes, it checks all of the simple type data in the instance document that is modeled by the class. If any of the data is found to be invalid, the method returns a bool value of false. Only if all of the data is found to be valid does the method return true.
The methods of rwsf::XmlValidator can be used directly by constructing an instance of rwsf::XmlValidator for some class that is a C++ data binding for an XML element and then calling methods to validate the data in an element of that type. In this case, you must know the facets defined for simple types in the element and call rwsf::XmlValidator methods to check the data for these simple types. For example, if an element contained simple type data with a maxLength facet, you would call checkMaxLength() on that data.
The facet checking methods set a state variable at the end of each check. If the data was found to be invalid, the state variable is set to false and remains that way even if additional calls are made to the method where the data is found to be valid. (The exception to this rule are the methods for checking enumerations and patterns, as described below for checkEnumerations() and checkPatterns().) Thus the state variable indicates whether any of the checks for a particular facet found invalid data. At any point, you can call the rwsf::XmlValidator isValid() method, which checks all of the state variables to determine whether any have been set to false. If any have been, it returns false. If all of the state variables are set to true, it returns true.
The direct use of rwsf::XmlValidator described above is, in fact, what the implementation of the isValid() method in the generated code does.
rwsf::XmlValidator initializes an std::list for rwsf::XmlSchemaException objects. A rwsf::XmlSchemaException object is added to this list whenever one of the facet checking methods reports invalid data. If a call to isValid() returns false, you can obtain the error list through the validator's getErrors() method and iterate through the list to obtain information on the errors discovered. rwsf::XmlSchemaException inherits from rwsf::Exception, so you can use the why() method to obtain the string that describes the error.
rwsf::XmlSchemaException
XmlValidator(const std::string& name);
Creates an rwsf::XmlValidator instance for the class represented by name. Initializes internal data to their default values.
enum WhiteSpace {PRESERVE, REPLACE, COLLAPSE};
void addError(rwsf::XmlSchemaException error);
Adds the rwsf::XmlSchemaException to the list of errors maintained by the rwsf::XmlValidator object.
bool checkEnumeration(const std::string& value,
const std::string& facetValue, WhiteSpace ws = PRESERVE);
Checks a particular enumeration value in the instance document against one of the possible values for the enumeration. Returns true if the instance value is found to be equivalent to the possible value, false otherwise. Sets its state variable to true if the check returns true, and leaves the state variable set to true even though subsequent calls return false.
bool checkEnumerations();
This method is called after checkEnumeration() has been called against all of the possible values for the enumeration. It returns the value of the state variable set by the calls to checkEnumeration(). The state variable will have been set to true if any of the calls to checkEnumeration() found a valid value.
If this method returns false, an rwsf::XmlSchemaException object is added to the list of errors indicating that the enumeration value is invalid.
bool checkEnumerations(std::string enumeration, rwsf::HashSet<std::string> enumerations, WhiteSpace ws = PRESERVE);
Checks all enumeration values in an instance document against their possible values. This method is passed a hash table of enumerations, and then tests them all at once. Returns true if the instance values are found to be equivalent to the possible values, false otherwise. Sets its state variable to true if the check returns true, and leaves the state variable set to true even though subsequent calls return false.
template <class T> bool checkFixed(const T& fixedValue, const T& candidate)
Checks whether a fixed element or fixed attribute has been set correctly by an instance document. If not, returns an error message identifying which element/attribute failed to meet the fixed constraint.
template <class T> bool checkFractionDigits(const T& value, const std::string& facetValue, WhiteSpace=PRESERVE);
For simple types that can take a fractionDigits facet, checks whether the number of digits in the fractional part of the simple type value, represented by value, is equal to or less than the number specified by facetValue. If not, the state variable is set to false, and an rwsf::XmlSchemaException object containing an explanatory string is added to the list of errors maintained in the rwsf::XmlValidator object.
template <class T> bool checkLength(size_t length, const std::string& facetValue); template <class T> bool checkLength(const std::string& value, const std::string& facetValue, WhiteSpace ws=PRESERVE)
For simple types that can take a length facet, checks whether the length of the data in the simple type value, represented by value, equals the length specified by facetValue. If not, the state variable is set to false, and an rwsf::XmlSchemaException object containing an explanatory string is added to the list of errors maintained in the rwsf::XmlValidator object.
template <class T> bool checkMaxExclusive(T value, T facetValue,WhiteSpace=PRESERVE);
For simple types that can take a maxExclusive facet, checks whether the data in the simple type value, represented by value, is less than the maximum specified by facetValue. If not, the state variable is set to false, and an rwsf::XmlSchemaException object containing an explanatory string is added to the list of errors maintained in the rwsf::XmlValidator object.
template <class T> bool checkMaxExclusive(ConverterBase<T> converter, T value, T facetValue, WhiteSpace) template <class T> bool checkMaxInclusive(ConverterBase<T> converter, T value, T facetValue, WhiteSpace) template <class T> bool checkMaxInclusive(T value, T facetValue, WhiteSpace = PRESERVE);
For simple types that can take a maxInclusive facet, checks whether the data in the simple type value, represented by value, is less than or equal to the maximum specified by facetValue. If not, the state variable is set to false, and an rwsf::XmlSchemaException object containing an explanatory string is added to the list of errors maintained in the rwsf::XmlValidator object.
bool checkMaxLength(const std::string& value, const std::string& facetValue, WhiteSpace ws = PRESERVE) bool checkMaxLength(size_t length, const std::string& facetValue);
For simple types that can take a maxLength facet, checks whether the length of the data in the simple type value, represented by value, is less than or equal to the maximum specified by facetValue. If not, the state variable is set to false, and an rwsf::XmlSchemaException object containing an explanatory string is added to the list of errors maintained in the rwsf::XmlValidator object.
The interpretation of the maxLength facet value depends on the simple type for which the facet is specified. See the XML Schema specification at http://www.w3.org/TR/xmlschema-0/ for details.
template <class T> bool checkMinExclusive(ConverterBase<T> converter, T value, T facetValue, WhiteSpace) template <class T> bool checkMinExclusive(T value, T facetValue,WhiteSpace=PRESERVE);
For simple types that can take a minExclusive facet, checks whether the data in the simple type value, represented by value, is greater than the minimum specified by facetValue. If not, the state variable is set to false, and an rwsf::XmlSchemaException object containing an explanatory string is added to the list of errors maintained in the rwsf::XmlValidator object.
template <class T> bool checkMinInclusive(ConverterBase<T> converter, T value, T facetValue, WhiteSpace) template <class T> bool checkMinInclusive(T value, T facetValue,WhiteSpace=PRESERVE);
For simple types that can take a minInclusive facet, checks whether the data in the simple type value, represented by value, is greater than or equal to the minimum specified by facetValue. If not, the state variable is set to false, and an rwsf::XmlSchemaException object containing an explanatory string is added to the list of errors maintained in the rwsf::XmlValidator object.
bool checkMinLength(const std::string& value, const std::string& facetValue, WhiteSpace ws=PRESERVE); bool checkMinLength(size_t length,const std::string& facetValue);
For simple types that can take a minLength facet, checks whether the length of the data in the simple type value, represented by value, is greater than or equal to the minimum specified by facetValue. If not, the state variable is set to false, and an rwsf::XmlSchemaException object containing an explanatory string is added to the list of errors maintained in the rwsf::XmlValidator object.
The interpretation of the minLength facet value depends on the simple type for which the facet is specified. See the XML Schema specification at http://www.w3.org/TR/xmlschema-0/ for details.
bool checkPattern(const std::string& value, const std::string& facetValue, WhiteSpace ws=PRESERVE);
Checks the string represented by value against a regular expression pattern represented by facetValue. Returns true if the instance value is found to match the regular expression, false otherwise.
Because a simple type can have two or more valid patterns defined, this method behaves similar to checkEnumerations(). The method sets its state variable to true if the check returns true, and leaves the state variable set to true even though subsequent calls return false.
bool checkPatterns();
This method is called after checkPattern() has been called against all of the valid patterns defined for the simple type. It returns the value of the state variable set by the calls to checkPattern(). The state variable will have been set to true if any of the calls to checkPattern() found a match with the defined pattern.
If this method returns false, an rwsf::XmlSchemaException object is added to the list of errors indicating that no matches were found to defined patterns.
bool checkPatterns(std::string pattern, std::vector<std::string> patterns, WhiteSpace ws = PRESERVE);
Checks all pattern values in an instance document against their possible values. This method is passed a vector of patterns, and then tests them all at once. Returns true if the instance values are found to be equivalent to the possible values, false otherwise. Sets its state variable to true if the check returns true.
If this method returns false, an rwsf::XmlSchemaException object is added to the list of errors indicating that no matches were found to defined patterns.
template <class T> bool checkTotalDigits(const T& value, const std::string& facetValue, WhiteSpace=PRESERVE);
For simple types that can take a totalDigits facet, checks whether the number of digits in the simple type value, represented by value, is equal to or less than the number specified by facetValue. If not, the state variable is set to false, and an rwsf::XmlSchemaException object containing an explanatory string is added to the list of errors maintained in the rwsf::XmlValidator object.
bool checkVectorBounds(int size, int minOccurs, int maxOccurs);
If the minOccurs and maxOccurs attributes on an element allow the instance document to have two or more such elements in a given context, checks that the number of occurrences falls within the allowable number as specified by minOccurs and maxOccurs. If not, the state variable is set to false, and an rwsf::XmlSchemaException object containing an explanatory string is added to the list of errors maintained in the rwsf::XmlValidator object.
void clear();
Resets all internal data to its initial value, and calls clearErrors() to clear the list that holds reported errors.
void clearErrors();
Clears the list that holds reported errors.
std::list<rwsf::XmlSchemaException> getErrors();
Returns the list that contains all reported errors. If isValid() returns false, you can then iterate through the list to determine the nature of the errors found.
bool isValid() const;
Checks all of the state variables for the individual facet checks. If all of the state variables are set to true, returns true; if one or more of the state variables is set to false, returns false.
If the method returns false, this validator's getErrors() method can be used to retrieve the list that holds rwsf::XmlSchemaException instances describing the errors found.
bool isValid(XmlValidator& validator);
Checks all of the state variables for the rwsf::XmlValidator instance represented by validator. If all of the state variables are set to true, returns true; if one or more of the state variables is set to false, returns false.
If the method returns false, the supplied validator's getErrors() method can be used to retrieve the list that holds rwsf::XmlSchemaException instances describing the errors found.
©2004-2007 Copyright Quovadx, Inc. All Rights Reserved.
Quovadx and Rogue Wave are registered trademarks and HydraSDO is a trademark of Quovadx, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.