Example program for reading and manipulating the quantitation.xml file.
import java.util.Date;
import matrix_science.msparser.*;
public class config_quantitation {
static {
try {
System.loadLibrary("msparserj");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. "
+ "Is msparserj.dll on the path?\n" + e);
System.exit(0);
}
}
public static void main(String argv[])
{
if(argv.length < 2) {
System.out.println("Must specify results quantitation.xml location as the first parameter and schema path as the second.");
System.exit(0);
}
ms_quant_configfile file = new ms_quant_configfile(argv[0], argv[1]);
if ( !file.isValid() )
{
System.out.println("Error number: "+file.getLastError());
System.out.println("Error string: "+file.getLastErrorString());
System.exit(0);
}
System.out.print("There are " + file.getNumberOfMethods());
System.out.println(" methods available");
for (int i=0; i < file.getNumberOfMethods(); i++)
{
System.out.println(file.getMethodByNumber(i).getName());
}
ms_xml_schema schemaFile = new ms_xml_schema();
schemaFile.setFileName(argv[1]);
schemaFile.read_file();
if ( !schemaFile.isValid() )
{
System.out.println("Errors while reading schema-file. The last error description:");
System.out.println("Error string: " + schemaFile.getLastErrorString());
System.exit(0);
}
String strValidationErrors = file.validateDocument();
if ( (strValidationErrors != null) && (strValidationErrors.length() > 0) )
{
System.out.println("Initial document validation errors: " + strValidationErrors);
}
for(int i = 0; i < file.getNumberOfMethods(); i++)
{
ms_quant_method pMethod = file.getMethodByNumber(i);
String strErrors = pMethod.validateShallow(schemaFile);
if ( (strErrors != null) && (strErrors.length() > 0) )
{
System.out.println("Method " + pMethod.getName());
System.out.println("Shallow validation errors: " + strErrors);
System.out.println();
}
strErrors = pMethod.validateDeep(schemaFile);
if ( (strErrors != null) && (strErrors.length() > 0) )
{
System.out.println("Method " + pMethod.getName());
System.out.println("Deep validation errors: " + strErrors);
System.out.println();
}
}
ms_quant_configfile configFileInvalid = new ms_quant_configfile();
ms_quant_method myMethodInvalid = new ms_quant_method(file.getMethodByNumber(0));
myMethodInvalid.setName("");
String strErr1 = myMethodInvalid.validateShallow(schemaFile);
System.out.println("Shallow validation of a method: " + strErr1);
String strErr2 = myMethodInvalid.validateDeep(schemaFile);
System.out.println("Deep validation of a method: " + strErr2);
String strErr3 = schemaFile.validateComplexObject(myMethodInvalid, true);
System.out.println("Deep validation using schema-object: " + strErr3);
String strErr4 = schemaFile.validateSimpleString(myMethodInvalid.getName(),
myMethodInvalid.getNameSchemaType());
System.out.println("Attribute validation: " + strErr4);
configFileInvalid.appendMethod(myMethodInvalid);
String errMethod = configFileInvalid.validateDocument();
System.out.println("Document validation errors: " + errMethod);
if ( !configFileInvalid.isValid() )
{
System.out.println("Errors in config-file object. The last error description:");
System.out.println(configFileInvalid.getLastErrorString());
}
configFileInvalid.setFileName("quantitation_temp.xml");
configFileInvalid.save_file();
if ( !configFileInvalid.isValid() )
{
System.out.println("Errors in config-file object. The last error description:");
System.out.println(configFileInvalid.getLastErrorString());
}
}
}