Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » XML Schema Definition (XSD) » XSDConstrainingFacet.isConstraintSatisfied
XSDConstrainingFacet.isConstraintSatisfied [message #593199] Mon, 27 December 2004 22:44
Klaas Dellschaft is currently offline Klaas DellschaftFriend
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
Previous Topic:Resolving a basetype reference in a different schema.
Next Topic:java.lang.NullPointerException when adding Element
Goto Forum:
  


Current Time: Sun Dec 21 04:15:42 GMT 2014

Powered by FUDForum. Page generated in 0.08319 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software