System.exit(1);
}
// get DOM implementation
DOMImplementationAS domImpl = (DOMImplementationAS)DOMImplementationImpl.getDOMImplementation();
// create a new parser, and set the error handler
DOMASBuilder parser = domImpl.createDOMASBuilder();
parser.setErrorHandler(new ASBuilder());
boolean schemaFullChecking = DEFAULT_SCHEMA_FULL_CHECKING;
String arg = null;
int i = 0;
// process -f/F
arg = argv[i];
if (arg.equals("-f")) {
schemaFullChecking = true;
arg = argv[++i];
} else if (arg.equals("-F")) {
schemaFullChecking = false;
arg = argv[++i];
}
// set the features. since we only deal with schema, some features have
// to be true
parser.setFeature(NAMESPACES_FEATURE_ID, true);
parser.setFeature(VALIDATION_FEATURE_ID, true);
parser.setFeature(SCHEMA_VALIDATION_FEATURE_ID, true);
parser.setFeature(SCHEMA_FULL_CHECKING_FEATURE_ID, schemaFullChecking);
// process -a: as model files
if (!arg.equals("-a")) {
printUsage();
System.exit(1);
}
i++;
Vector asfiles = new Vector();
while (i < argv.length && !(arg = argv[i]).startsWith("-")) {
asfiles.addElement(arg);
i++;
}
// has to be at least one as file, and there has to be other parameters
if (asfiles.size() == 0) {
printUsage();
System.exit(1);
}
// process -i: instance files, if any
Vector ifiles = null;
if (i < argv.length) {
if (!arg.equals("-i")) {
printUsage();
System.exit(1);
}
i++;
ifiles = new Vector();
while (i < argv.length && !(arg = argv[i]).startsWith("-")) {
ifiles.addElement(arg);
i++;
}
// has to be at least one instance file, and there has to be no more
// parameters
if (ifiles.size() == 0 || i != argv.length) {
printUsage();
System.exit(1);
}
}
//
// PARSING XML SCHEMAS
//
try {
ASModel asmodel = null;
for (i = 0; i < asfiles.size(); i++) {
asmodel = parser.parseASURI((String)asfiles.elementAt(i));
parser.setAbstractSchema(asmodel);
}
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
// then for each instance file, try to validate it
if (ifiles != null) {
try {
for (i = 0; i < ifiles.size(); i++) {
parser.parseURI((String)ifiles.elementAt(i));
}
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}