pattern.next();
continue;
}
// derive a type with test facets.
XSDatatype typeObj=null;
try
{
typeObj = ti.derive("anonymousURI","anonymousLocal");
}
catch( DatatypeException bte )
{
err.reportTestCaseError(baseType,ti,bte);
}
{// make sure that the serialization works.
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
// serialize it
oos.writeObject( typeObj );
oos.flush();
// obtain byte array (just in case)
ObjectInputStream ois = new ObjectInputStream(
new ByteArrayInputStream(bos.toByteArray()));
typeObj = (XSDatatype)ois.readObject();
ois.close();
}
if(typeObj!=null)
{
if( answer.length()!=values.length )
throw new IllegalStateException("answer and values have different length");
// if( testCase.facets.isEmpty()) out.println("nofacet");
// else testCase.facets.dump(out);
// test each value and see what happens
for( int i=0; i<values.length; i++ )
{
boolean v = typeObj.isValid(values[i],DummyContextProvider.theInstance);
boolean d;
boolean roundTripError = false;
Object o = typeObj.createValue(
values[i],DummyContextProvider.theInstance);
try {
if(o!=null) {
// should be able to convert it back.
String s = typeObj.convertToLexicalValue(o,DummyContextProvider.theInstance);
// try round trip conversion.
Object o2 = typeObj.createValue(s,DummyContextProvider.theInstance);
if( o2==null || !o.equals(o2) )
roundTripError = true;
}
} catch( UnsupportedOperationException uoe ) {
// ignore this exception
} catch( IllegalArgumentException iae ) {
roundTripError = true;
}
Object jo = typeObj.createJavaObject( values[i], DummyContextProvider.theInstance );
if( jo!=null ) {
if( !typeObj.getJavaObjectType().isAssignableFrom(jo.getClass()) ) {
System.out.println("type error");
roundTripError = true;
}
String s = typeObj.serializeJavaObject( jo,
DummyContextProvider.theInstance );
if(s==null) {
System.out.println("serializeJavaObject failed");
roundTripError = true;
} else {
Object o2 = typeObj.createJavaObject(s,DummyContextProvider.theInstance);
if( o2==null ) {
System.out.println("round-trip conversion failed");
roundTripError = true;
}
}
}
try {
typeObj.checkValid(values[i],DummyContextProvider.theInstance);
d = true;
} catch( DatatypeException de ) {
d = false;
}
// if convertToValueObject and verify method differs,
// it's always an error.
// roundTripError is always an error.
if(!roundTripError && (o!=null)==v && (jo!=null)==v ) {
if(v && d && answer.charAt(i)=='o')
continue; // as predicted
if(!v && !d && answer.charAt(i)=='.')
continue; // as predicted
if(completenessOnly && answer.charAt(i)=='.' && v==d )
continue; // do not report error if
// the validator accepts things that
// may not be accepted.
}
// dump error messages
if( !err.report( new UnexpectedResultException(
typeObj, baseType.getName(),
values[i], answer.charAt(i)=='o',
ti ) ) )
{
out.println("test aborted");
return;
}
}
// test each wrong values and makes sure that they are rejected.
for( int i=0; i<wrongs.length; i++ ) {
boolean err = false;
err = typeObj.isValid(wrongs[i],DummyContextProvider.theInstance);
try {
typeObj.checkValid(wrongs[i],DummyContextProvider.theInstance);
err = true;
} catch (DatatypeException de) {
; // it should throw an exception
}
if( typeObj.createJavaObject(wrongs[i],DummyContextProvider.theInstance)!=null )
err = true;
if( err ) {
if( !this.err.report( new UnexpectedResultException(
typeObj, baseType.getName(),