XSDConstrainingFacet.isConstraintSatisfied [message #593199] |
Mon, 27 December 2004 22:44 |
Klaas Dellschaft Messages: 58 Registered: July 2009 |
Member |
|
|
Hi,
I've been looking for a way to validate whether a value (not its lexical
representation!) is contained in the value space of a type. I had a look at
the interface definitions and saw the method
XSDConstrainingFacet.isConstraintSatisfied(Object value) which seems to be
made for this purpose.
I'm trying to run this source code:
--------------------------------------------
boolean result = true;
XSDEnumerationFacet enumeration = type2.getEffectiveEnumerationFacet();
for (Iterator i = enumeration.getValue().iterator(); i.hasNext();) {
Object value = i.next();
for (Iterator j = type1.getFacets().iterator(); j.hasNext();) {
XSDConstrainingFacet facet = (XSDConstrainingFacet) j.next();
result = result && facet.isConstraintSatisfied(value);
}
}
--------------------------------------------
But now I'm discovering problems: For XSDWhiteSpaceFacet instances the
method always returns false (which I didn't expect) and for XSDPatternFacets
always a ClassCastExcpetion is thrown if I pass for example a BigDecimal as
the value. I inserted the source code from XSDPatternFacetImpl.java below.
---XSDPatternFacetImpl.java-----------------
public boolean isConstraintSatisfied(Object value)
{
for (Iterator thePatterns = getPatterns(false).iterator();
thePatterns.hasNext(); )
{
RegularExpression pattern = (RegularExpression)thePatterns.next();
// In this if-condition a ClassCastException is thrown
if (!pattern.matches((String)value))
{
return false;
}
}
return true;
}
--------------------------------------------
I think one possible solution would be to use "value.toString()" instead of
"(String)value" or to return false if the object isn't a String.
Cheers
Klaas
|
|
|
Powered by
FUDForum. Page generated in 0.04431 seconds