RootElement rootElement = null;
String fileBeingValidated = "com/sun/enterprise/tools/" + //NOI18N
"common/validation/samples/simple/simple.xml"; //NOI18N
String validationFile = "com/sun/enterprise/tools/" + //NOI18N
"common/validation/samples/simple/validation.xml"; //NOI18N
/// String validationFile = "C:/testframe/tests/com/sun/" + //NOI18N
/// "enterprise/tools/common/validation/samples/simple/" + //NOI18N
/// "validation.xml"; //NOI18N
// You should set impl.file to fully qualified file name of the
// impl(implementation) file
/// String implFile = "com.sun.enterprise.tools." + //NOI18N
/// "common.XYZImpl"; //NOI18N
/// System.setProperty("impl.file", implFile); //NOI18N
// You can set constraints.file to either absolute or relative path of the
// Constraints file
/// String cosntriantsFile = "com/sun/enterprise/tools/" + //NOI18N
/// "common/testXYZ.xml"; //NOI18N
/// String cosntriantsFile = "C:/testframe/src/java/com/sun/" + //NOI18N
/// "enterprise/tools/XYZ/testXYZ.xml"; //NOI18N
/// System.setProperty("constraints.file", cosntriantsFile); //NOI18N
//Create an InpurtStream object
Utils utils = new Utils();
InputStream inputStream = utils.getInputStream(fileBeingValidated);
//Create graph
if(inputStream != null) {
try {
rootElement = RootElement.createGraph(inputStream);
} catch(Exception e) {
System.out.println(e.getMessage());
}
} else {
String format =
BundleReader.getValue("MSG_Unable_to_use_file"); //NOI18N
Object[] arguments = new Object[]{fileBeingValidated};
System.out.println(MessageFormat.format(format, arguments));
}
if(rootElement != null){
ValidationManagerFactory validationManagerFactory =
new ValidationManagerFactory();
//you can pass either absolute or relative path of the validation
//file to getValidationManager()
ValidationManager validationManager =
validationManagerFactory.getValidationManager(validationFile);
Collection failures =
validationManager.validate(rootElement);
Display display = new Display();
display.text(failures);
display.gui(failures);
}