final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
// TypeIncubator is used to "incubate" a type by adding facets.
// constructor accepts the base type instance.
TypeIncubator incubator = new TypeIncubator(StringType.theInstance);
while(true)
{
try
{
System.out.print("-->");
String s = in.readLine();
StringTokenizer tokens = new StringTokenizer(s);
String cmd = tokens.nextToken();
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");