if( cmd.equals("base") )
{
String typeName = tokens.nextToken();
// to obtain a type by name, call this method.
XSDatatype dt = DatatypeFactory.getTypeByName(typeName);
if(dt==null)
{// if the name is not recognized, null is returned.
System.out.println("no such type");
continue;
}
incubator = new TypeIncubator(dt);
continue;
}
if( cmd.equals("add") )
{
String facetName = tokens.nextToken();
String facetValue = tokens.nextToken();
// to add a facet, call add method.
// you MUST supply a valid ValidationContextProvider,
// although this example omits one.
incubator.addFacet( facetName, facetValue, false, null );
continue;
}
if( cmd.equals("test") )
{
String value = tokens.nextToken();
// a type can be derived by derive method.
// the new type contains all facets that were added.
XSDatatype dt = incubator.derive("","anonymous");
// check validity.
if( dt.isValid(value,null) )
// verify method returns true if the value is valid.
System.out.println("valid value");
else
{// it returns false otherwise,
// call diagnose method to see what is wrong.
try
{
dt.checkValid(value,null);
System.out.println("valid");
}
catch( DatatypeException diag )
{
if( diag.getMessage()==null ) {