lcsim/src/org/lcsim/job
diff -u -r1.14 -r1.15
--- JobControlManager.java 31 Oct 2008 19:34:02 -0000 1.14
+++ JobControlManager.java 4 Feb 2009 00:20:33 -0000 1.15
@@ -5,14 +5,17 @@
import java.beans.BeanInfo;
import java.beans.MethodDescriptor;
+import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
+import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.lang.reflect.Method;
+import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
@@ -35,7 +38,7 @@
/**
* The <code>JobControlManager</code> provides an XML frontend for running LCSim jobs.
- * The command line syntax is <code>./bin/lcsim steeringFile.xml</code>.
+ * The command line syntax is <code>java -jar ./lib/lcsim.jar steeringFile.xml</code>.
* @author jeremym
* @verbose $id: $
*/
@@ -66,8 +69,12 @@
boolean verbose;
boolean wasSetup;
PrintStream logStream = System.out;
- LCSimLoop loop;
+ LCSimLoop loop;
+ Element root;
+ /**
+ * Default no-argument constructor.
+ */
public JobControlManager()
{
findAvailableDrivers();
@@ -75,7 +82,7 @@
/**
* Simple frontend method taking the name of the XML steering file.
- * @param args
+ * @param args The command line arguments.
*/
public static void main(String args[])
{
@@ -90,42 +97,57 @@
}
/**
- * User method for executing the job if JobControlManager is being explicitly instantiated rather than called through main method.
+ * User method for executing the job if JobControlManager is being
+ * explicitly instantiated rather than created by calling the {#{@link JobControlManager#main(String[])}.
+ * method.
*/
public void run()
{
if (!wasSetup)
- throw new RuntimeException("Bailing on job! The setup() method was never called!");
+ throw new RuntimeException("Aborting job! The setup() method was never called.");
+
if (printSystemProperties)
printSystemProperties(logStream);
+
+ // Add the drivers to the loop.
for (Driver driver : driverExec)
{
loop.add(driver);
}
+
try
{
+ // Add the LCIO files to the loop.
loop.setLCIORecordSource(new LCIOEventSource("test", inputFiles));
+
PrintStream statsStream = null;
+
if (printDriverStatistics)
statsStream = logStream;
+
if (verbose)
{
logStream.println("Start time: " + (new Date()));
logStream.println();
}
+
if (skipEvents != -1)
{
if (verbose)
logStream.println("Skipping " + skipEvents + " events");
loop.skip(skipEvents);
}
+
+ // Execute the loop.
loop.loop(maxEvents, statsStream);
+
if (verbose)
{
logStream.println();
logStream.println("End time: " + (new Date()));
}
- } catch (Exception x)
+ }
+ catch (Exception x)
{
throw new RuntimeException(x);
}
@@ -133,7 +155,7 @@
}
/**
- * User setup method which uses an embedded resource as the steering file.
+ * Setup method which uses an embedded resource as the steering file.
* @param resource
*/
public void setup(String resource)
@@ -142,7 +164,7 @@
}
/**
- * User setup method which uses a File.
+ * Setup method which uses a File.
* @param file
*/
public void setup(File file)
@@ -150,16 +172,16 @@
try
{
setup((new FileInputStream(file)));
- } catch (FileNotFoundException x)
+ }
+ catch (FileNotFoundException x)
{
throw new RuntimeException(x);
}
}
/**
- * User setup method which uses a generic <code>InputStream</code> for steering.
- * This stream should be a text stream of XML.
- * @param in The XML input.
+ * Setup method which uses a <code>InputStream</code> for steering.
+ * @param in The XML input stream.
*/
public void setup(InputStream in)
{
@@ -178,123 +200,486 @@
/**
* The primary setup method. Public setup methods all end up here.
- * @param doc
+ * @param doc The lcsim recon XML document describing the job.
*/
private void setup(Document doc)
{
- // Clear data structures if a previous job was run.
+ // Clear data structures in case a previous job was run.
clear();
- // Get the root element.
- Element root = doc.getRootElement();
+ // Set the root element.
+ root = doc.getRootElement();
- // Setup job control parameters.
- Element control = root.getChild("control");
- if (control != null)
- {
- // Verbose mode.
- Element verboseElement = control.getChild("verbose");
- if (verboseElement != null)
- verbose = Boolean.valueOf(verboseElement.getText());
+ // Setup the job control parameters.
+ setupJobControlParameters();
+
+ // Setup the class loader.
+ setupClassLoader();
+
+ // Setup drivers with parameters and execution order.
+ setupDrivers();
- // Log file setup needs to come first.
- Element logFileElement = control.getChild("logFile");
- String logFilePath = null;
- if (logFileElement != null)
- {
- logFilePath = logFileElement.getText();
- File logFile = new File(logFilePath);
- try {
- logFile.createNewFile();
- logStream = new PrintStream(new FileOutputStream(logFile));
+ // Setup the file cache.
+ setupFileCache();
- // Redirect standard out and err to log file.
- System.setOut(logStream);
- System.setErr(logStream);
- }
- catch (IOException x)
- {
- throw new RuntimeException(x);
- }
- }
-
- // Print the lcsim version info to the log (always).
- (new LCSimVersion()).printOut(logStream);
- logStream.println();
+ // Setup the input files.
+ setupInputFiles();
- // Print hello world message to appear at top of log.
- if (verbose)
- {
- logStream.println(this.getClass().getCanonicalName() + " is initialized.");
- logStream.println();
- logStream.println("--- Job Control Parameters ---");
- }
+ // Flag JobManager as setup.
+ wasSetup = true;
+ }
- // Print log file path now that PrintStream is set.
- if (verbose)
- logStream.println("logFile = " + logFilePath);
+ /**
+ * Reset private variables before next execution.
+ */
+ private void clear()
+ {
+ inputFiles = new ArrayList<File>();
+ driverExec = new ArrayList<Driver>();
+ driverMap = new LinkedHashMap<String, Driver>();
+ maxEvents = -1;
+ cacheDirectory = null;
+ fileCache = null;
+ loader = null;
+ printDriverStatistics = false;
+ printSystemProperties = false;
+ printUserClassPath = false;
+ printDriversDetailed = false;
+ verbose = false;
+ wasSetup = false;
+ logStream = System.out;
+ loop = new LCSimLoop();
+ root = null;
+ }
- // Number of events to run.
- Element controlElement = control.getChild("numberOfEvents");
- if (controlElement != null)
+ /**
+ * Converts a String <code>value</code> to a Java class specified by <code>propertyType</code>.
+ * @param value The string value from the XML parameter.
+ * @param propertyType The type of the parameter.
+ * @return The value of <code>value</code> as Class <code>propertyType</code>.
+ */
+ private Object convertParameter(String value, Class propertyType)
+ {
+ Object o = null;
+
+ // Single int.
+ if (propertyType.equals(int.class))
+ {
+ o = Integer.valueOf(value);
+ }
+ // Single String.
+ else if (propertyType.equals(String.class))
+ {
+ o = value;
+ }
+ // Single double.
+ else if (propertyType.equals(double.class))
+ {
+ o = Double.valueOf(value);
+ }
+ // Single float.
+ else if (propertyType.equals(float.class))
+ {
+ o = Float.valueOf(value);
+ }
+ // Single boolean.
+ else if (propertyType.equals(boolean.class))
+ {
+ o = Boolean.valueOf(value);
+ }
+ // Single Hep3Vector type.
+ else if (propertyType.equals(Hep3Vector.class))
+ {
+ StringTokenizer tokenize = new StringTokenizer(value);
+ double x = Double.valueOf(tokenize.nextToken());
+ double y = Double.valueOf(tokenize.nextToken());
+ double z = Double.valueOf(tokenize.nextToken());
+ o = new BasicHep3Vector(x, y, z);
+ }
+ // 1d array of doubles.
+ else if (propertyType.getName().equals("[D"))
+ {
+ StringTokenizer tokenize = new StringTokenizer(value);
+ int size = tokenize.countTokens();
+ double da[] = new double[size];
+ int i = 0;
+ while (tokenize.hasMoreTokens())
{
- maxEvents = Integer.valueOf(controlElement.getText());
- if (verbose)
- logStream.println("numberOfEvents = " + maxEvents);
+ da[i] = Double.valueOf(tokenize.nextToken());
+ ++i;
}
-
- Element skipElement = control.getChild("skipEvents");
- if (skipElement != null)
+ o = da;
+ }
+ // 1d array of ints.
+ else if (propertyType.getName().equals("[I"))
+ {
+ StringTokenizer tokenize = new StringTokenizer(value);
+ int size = tokenize.countTokens();
+ int ia[] = new int[size];
+ int i = 0;
+ while (tokenize.hasMoreTokens())
{
- skipEvents = Integer.valueOf(skipElement.getText());
- if (verbose)
- logStream.println("skipEvents = " + skipEvents);
+ ia[i] = Integer.valueOf(tokenize.nextToken());
+ ++i;
}
-
- // The cache directory. Defaults to the current directory.
- Element cacheDirElement = control.getChild("cacheDirectory");
- if (cacheDirElement != null)
+ o = ia;
+ }
+ // 1d array of floats.
+ else if (propertyType.getName().equals("[F"))
+ {
+ StringTokenizer tokenize = new StringTokenizer(value);
+ int size = tokenize.countTokens();
+ float fa[] = new float[size];
+ int i = 0;
+ while (tokenize.hasMoreTokens())
{
- cacheDirectory = new File(cacheDirElement.getText());
- if (!cacheDirectory.exists())
- throw new RuntimeException("cacheDirectory does not exist at location: " + cacheDirElement.getText());
- }
- else
+ fa[i] = Float.valueOf(tokenize.nextToken());
+ ++i;
+ }
+ o = fa;
+ }
+ // 1d array of strings.
+ else if (propertyType.getName().equals("[Ljava.lang.String;"))
+ {
+ StringTokenizer tokenize = new StringTokenizer(value);
+ int size = tokenize.countTokens();
+ String sa[] = new String[size];
+ int i = 0;
+ while (tokenize.hasMoreTokens())
{
- // Default to the current working dir if cacheDirectory was not set explicitly.
- cacheDirectory = new File(System.getProperties().get("user.dir").toString());
+ sa[i] = tokenize.nextToken();
+ ++i;
}
-
- if (verbose)
- logStream.println("cacheDirectory = " + cacheDirectory);
-
- Element printStatisticsElement = control.getChild("printDriverStatistics");
- if (printStatisticsElement != null)
+ o = sa;
+ }
+ // 1d array of booleans.
+ else if (propertyType.getName().equals("[Z"))
+ {
+ StringTokenizer tokenize = new StringTokenizer(value);
+ int size = tokenize.countTokens();
+ boolean ba[] = new boolean[size];
+ int i = 0;
+ while (tokenize.hasMoreTokens())
{
- printDriverStatistics = Boolean.valueOf(printStatisticsElement.getText());
+ ba[i] = Boolean.valueOf(tokenize.nextToken());
+ ++i;
}
-
- if (verbose)
- logStream.println("printDriverStatistics = " + printDriverStatistics);
-
- Element printSystemPropertiesElement = control.getChild("printSystemProperties");
- if (printSystemPropertiesElement != null)
+ o = ba;
+ }
+ // Single File type.
+ else if (propertyType.getName().equals(File.class))
+ {
+ o = new File(value);
+ }
+ // Single URL type.
+ else if (propertyType.getName().equals(URL.class))
+ {
+ try
{
- printSystemProperties = Boolean.valueOf(printSystemPropertiesElement.getText());
+ o = new URL(value);
+ } catch (Exception x)
+ {
+ throw new RuntimeException(x);
}
+ }
- if (verbose)
- logStream.println("printSystemProperties = " + printSystemProperties);
-
- Element printUserClassPathElement = control.getChild("printUserClassPath");
- if (printUserClassPathElement != null)
- printUserClassPath = Boolean.valueOf(printUserClassPathElement.getText());
+ return o;
+ }
- if (verbose)
- logStream.println("printUserClassPath = " + printUserClassPath);
+ /**
+ * Add a Driver to the Driver map.
+ * @param name The unique name of the Driver.
+ * @param driver The instance of the Driver.
+ */
+ private void addDriver(String name, Driver driver)
+ {
+ if (driverMap.containsKey(name))
+ {
+ throw new RuntimeException("ERROR: duplicate driver name: " + name);
+ }
+ driverMap.put(name, driver);
+ }
- Element printDriversDetailedElement = control.getChild("printDriversDetailed");
- if (printDriversDetailedElement != null)
+ /**
+ * Setup a list of available Drivers if a services file exists.
+ */
+ private void findAvailableDrivers()
+ {
+ InputStream in = JobControlManager.class.getResourceAsStream("/META-INF/services/org.lcsim.util.Driver");
+ if (in == null)
+ {
+ return;
+ }
+ Scanner scan = new Scanner(in);
+ while (scan.hasNext())
+ {
+ String fullName = scan.nextLine().trim();
+ String shortName = fullName.substring(fullName.lastIndexOf(".") + 1);
+ availableDrivers.put(shortName, fullName);
+ }
+ }
+
+ private void printSystemProperties(PrintStream ps)
+ {
+ logStream.println("--- System Properties ---");
+ for (Entry<Object, Object> entry : System.getProperties().entrySet())
+ {
+ logStream.println(entry.getKey() + " = " + entry.getValue());
+ }
+ logStream.println("-- End System Properties");
+ logStream.println();
+ }
+
+ private static Class getPrimitiveType(String name)
+ {
+ if (name.equals("byte")) return byte.class;
+ if (name.equals("short")) return short.class;
+ if (name.equals("int")) return int.class;
+ if (name.equals("long")) return long.class;
+ if (name.equals("char")) return char.class;
+ if (name.equals("float")) return float.class;
+ if (name.equals("double")) return double.class;
+ if (name.equals("boolean")) return boolean.class;
+ if (name.equals("String")) return String.class;
+ return null;
+ }
+
+ private void setupInputFiles()
+ {
+ // Read local files.
+ List<Element> files = root.getChild("inputFiles").getChildren("file");
+ for (Element file : files)
+ {
+ String fileLoc = file.getText();
+ File nextFile = new File(fileLoc);
+ inputFiles.add(nextFile);
+ }
+
+ // Read file URLs.
+ List<Element> fileUrls = root.getChild("inputFiles").getChildren("fileUrl");
+ for (Element fileUrl : fileUrls)
+ {
+ URL url;
+ try
+ {
+ url = new URL(fileUrl.getText());
+ }
+ catch (MalformedURLException x)
+ {
+ throw new RuntimeException(x);
+ }
+
+ File nextFile;
+ try
+ {
+ nextFile = fileCache.getCachedFile(url);
+ }
+ catch (IOException x)
+ {
+ throw new RuntimeException(x);
+ }
+ inputFiles.add(nextFile);
+ }
+
+ // Read lists of file locations.
+ List<Element> fileLists = root.getChild("inputFiles").getChildren("fileList");
+ for (Element fileList : fileLists)
+ {
+ String filePath = fileList.getText();
+ BufferedReader input;
+ try
+ {
+ input = new BufferedReader(new FileReader(new File(filePath)));
+ }
+ catch (FileNotFoundException x)
+ {
+ throw new RuntimeException(x);
+ }
+ String line = null;
+ try
+ {
+ while (( line = input.readLine()) != null)
+ {
+ File nextFile = new File(line.trim());
+
+ // DEBUG
+ System.out.println("adding " + nextFile.getAbsolutePath());
+ //
+
+ inputFiles.add(nextFile);
+ }
+ }
+ catch (IOException x)
+ {
+ throw new RuntimeException(x);
+ }
+ }
+
+ // Read lists of file URLs.
+ List<Element> fileUrlLists = root.getChild("inputFiles").getChildren("fileUrlList");
+ for (Element fileUrlList : fileUrlLists)
+ {
+ String filePath = fileUrlList.getText();
+ BufferedReader input;
+ try
+ {
+ input = new BufferedReader(new FileReader(new File(filePath)));
+ }
+ catch (FileNotFoundException x)
+ {
+ throw new RuntimeException(x);
+ }
+ String line = null;
+ try
+ {
+ while ((line = input.readLine()) != null)
+ {
+
+ URL url = new URL(line);
+ File nextFile = fileCache.getCachedFile(url);
+ inputFiles.add(nextFile);
+ }
+ }
+ catch (IOException x)
+ {
+ throw new RuntimeException(x);
+ }
+ }
+
+ // Check and print out input files.
+ if (verbose)
+ {
+ logStream.println();
+ logStream.println("--- Input Files ---");
+ }
+
+ for (File file : inputFiles)
+ {
+ // Check that input LCIO file exists.
+ if (!file.exists())
+ {
+ throw new RuntimeException("The file " + file.getAbsolutePath() + " does not exist!");
+ }
+
+ if (verbose)
+ logStream.println(file.getAbsolutePath());
+ }
+ if (verbose)
+ {
+ logStream.println("--- End Input Files ---");
+ logStream.println();
+ }
+
+ }
+
+ private void setupJobControlParameters()
+ {
+ Element control = root.getChild("control");
+ if (control != null)
+ {
+ // Verbose mode.
+ Element verboseElement = control.getChild("verbose");
+ if (verboseElement != null)
+ verbose = Boolean.valueOf(verboseElement.getText());
+
+ // Log file setup needs to come first.
+ Element logFileElement = control.getChild("logFile");
+ String logFilePath = null;
+ if (logFileElement != null)
+ {
+ logFilePath = logFileElement.getText();
+ File logFile = new File(logFilePath);
+ try {
+ logFile.createNewFile();
+ logStream = new PrintStream(new FileOutputStream(logFile));
+
+ // Redirect standard out and err to log file.
+ System.setOut(logStream);
+ System.setErr(logStream);
+ }
+ catch (IOException x)
+ {
+ throw new RuntimeException(x);
+ }
+ }
+
+ // Print the lcsim version info to the log (always).
+ (new LCSimVersion()).printOut(logStream);
+ logStream.println();
+
+ // Print hello world message to appear at top of log.
+ if (verbose)
+ {
+ logStream.println(this.getClass().getCanonicalName() + " is initialized.");
+ logStream.println();
+ logStream.println("--- Job Control Parameters ---");
+ }
+
+ // Print log file path now that PrintStream is set.
+ if (verbose)
+ logStream.println("logFile = " + logFilePath);
+
+ // Number of events to run.
+ Element controlElement = control.getChild("numberOfEvents");
+ if (controlElement != null)
+ {
+ maxEvents = Integer.valueOf(controlElement.getText());
+ if (verbose)
+ logStream.println("numberOfEvents = " + maxEvents);
+ }
+
+ Element skipElement = control.getChild("skipEvents");
+ if (skipElement != null)
+ {
+ skipEvents = Integer.valueOf(skipElement.getText());
+ if (verbose)
+ logStream.println("skipEvents = " + skipEvents);
+ }
+
+ // The cache directory. Defaults to the current directory.
+ Element cacheDirElement = control.getChild("cacheDirectory");
+ if (cacheDirElement != null)
+ {
+ cacheDirectory = new File(cacheDirElement.getText());
+ if (!cacheDirectory.exists())
+ throw new RuntimeException("cacheDirectory does not exist at location: " + cacheDirElement.getText());
+ }
+ else
+ {
+ // Default to the current working dir if cacheDirectory was not set explicitly.
+ cacheDirectory = new File(System.getProperties().get("user.dir").toString());
+ }
+
+ if (verbose)
+ logStream.println("cacheDirectory = " + cacheDirectory);
+
+ Element printStatisticsElement = control.getChild("printDriverStatistics");
+ if (printStatisticsElement != null)
+ {
+ printDriverStatistics = Boolean.valueOf(printStatisticsElement.getText());
+ }
+
+ if (verbose)
+ logStream.println("printDriverStatistics = " + printDriverStatistics);
+
+ Element printSystemPropertiesElement = control.getChild("printSystemProperties");
+ if (printSystemPropertiesElement != null)
+ {
+ printSystemProperties = Boolean.valueOf(printSystemPropertiesElement.getText());
+ }
+
+ if (verbose)
+ logStream.println("printSystemProperties = " + printSystemProperties);
+
+ Element printUserClassPathElement = control.getChild("printUserClassPath");
+ if (printUserClassPathElement != null)
+ printUserClassPath = Boolean.valueOf(printUserClassPathElement.getText());
+
+ if (verbose)
+ logStream.println("printUserClassPath = " + printUserClassPath);
+
+ Element printDriversDetailedElement = control.getChild("printDriversDetailed");
+ if (printDriversDetailedElement != null)
printDriversDetailed = Boolean.valueOf(printDriversDetailedElement.getText());
if (verbose)
@@ -304,8 +689,10 @@
logStream.println();
}
}
-
- // Setup the class loader.
+ }
+
+ private void setupClassLoader()
+ {
Element classpath = root.getChild("classpath");
List<URL> urlList = new ArrayList<URL>();
if (classpath != null)
@@ -336,7 +723,7 @@
URL[] urls = urlList.toArray(new URL[]{});
loader = new LCSimClassLoader(urls);
- // Print user's classpath entries.
+ // Print user classpath entries.
if (printUserClassPath)
{
logStream.println("-- Extra Classpath URLs --");
@@ -346,16 +733,30 @@
}
logStream.println("-- End Extra Classpath URLs --");
logStream.println();
+ }
+ }
+
+ private void setupFileCache()
+ {
+ try
+ {
+ fileCache = new FileCache();
+ fileCache.setCacheDirectory(cacheDirectory);
+ fileCache.setPrintStream(null);
+ }
+ catch (IOException x)
+ {
+ throw new RuntimeException(x);
}
-
- // Get list of driver declarations from steering file.
- List<Element> drivers = root.getChild("drivers").getChildren("driver");
-
- // Loop over the driver declarations.
+ }
+
+ private void setupDrivers()
+ {
if (printDriversDetailed)
{
- logStream.println("--- Drivers ---");
+ System.out.println("--- Drivers ---");
}
+ List<Element> drivers = root.getChild("drivers").getChildren("driver");
for (Element driver : drivers)
{
// Get the name of the Driver.
@@ -484,10 +885,10 @@
} // parameter loop
addDriver(name, newDriver);
} // driver loop
+
if (printDriversDetailed)
{
logStream.println("--- End Drivers ---");
- logStream.println();
}
// Make a list of Drivers to be executed from the execute list.
@@ -501,282 +902,5 @@
else
throw new RuntimeException("Driver not found: " + driverName);
}
-
- // Setup the file cache.
- try
- {
- fileCache = new FileCache();
- fileCache.setCacheDirectory(cacheDirectory);
- fileCache.setPrintStream(null);
- } catch (IOException x)
- {
- throw new RuntimeException(x);
- }
-
- // Make list of input LCIO files.
- if (verbose)
- logStream.println("--- Input Files ---");
- List<Element> files = root.getChild("inputFiles").getChildren("file");
- for (Element file : files)
- {
- String fileLoc = file.getText();
- File nextFile = new File(fileLoc);
- //if (!nextFile.exists())
- //{
- // throw new RuntimeException("File not found on local filesystem: " + fileLoc);
- //}
- inputFiles.add(nextFile);
- if (verbose)
- {
- try
- {
- logStream.println(nextFile.getCanonicalPath());
- } catch (IOException x)
- {
- throw new RuntimeException(x);
- }
- }
- }
-
- // Make list of input LCIO files with URLs. Uses the file cache.
- List<Element> fileURLs = root.getChild("inputFiles").getChildren("fileUrl");
- for (Element fileURL : fileURLs)
- {
- try
- {
- URL url = new URL(fileURL.getText());
- if (verbose)
- {
- logStream.println(url);
- }
- File nextFile = fileCache.getCachedFile(url);
- inputFiles.add(nextFile);
- } catch (Exception x)
- {
- throw new RuntimeException("Bad file URL: " + fileURL.getText());
- }
- }
-
- if (verbose)
- {
- logStream.println("--- End Input Files ---");
- logStream.println();
- }
-
- wasSetup = true;
- }
-
- /**
- * Reset all private variables before next execution.
- */
- private void clear()
- {
- inputFiles = new ArrayList<File>();
- driverExec = new ArrayList<Driver>();
- driverMap = new LinkedHashMap<String, Driver>();
- maxEvents = -1;
- cacheDirectory = null;
- fileCache = null;
- loader = null;
- printDriverStatistics = false;
- printSystemProperties = false;
- printUserClassPath = false;
- printDriversDetailed = false;
- verbose = false;
- wasSetup = false;
- logStream = System.out;
- loop = new LCSimLoop();
- }
-
- /**
- * Converts a String <code>value</code> to a Java class specified by <code>propertyType</code>.
- * @param value The string value from the XML parameter.
- * @param propertyType The type of the parameter.
- * @return The value of <code>value</code> as Class <code>propertyType</code>.
- */
- private Object convertParameter(String value, Class propertyType)
- {
- Object o = null;
-
- // Single int.
- if (propertyType.equals(int.class))
- {
- o = Integer.valueOf(value);
- }
- // Single String.
- else if (propertyType.equals(String.class))
- {
- o = value;
- }
- // Single double.
- else if (propertyType.equals(double.class))
- {
- o = Double.valueOf(value);
- }
- // Single float.
- else if (propertyType.equals(float.class))
- {
- o = Float.valueOf(value);
- }
- // Single boolean.
- else if (propertyType.equals(boolean.class))
- {
- o = Boolean.valueOf(value);
- }
- // Single Hep3Vector type.
- else if (propertyType.equals(Hep3Vector.class))
- {
- StringTokenizer tokenize = new StringTokenizer(value);
- double x = Double.valueOf(tokenize.nextToken());
- double y = Double.valueOf(tokenize.nextToken());
- double z = Double.valueOf(tokenize.nextToken());
- o = new BasicHep3Vector(x, y, z);
- }
- // 1d array of doubles.
- else if (propertyType.getName().equals("[D"))
- {
- StringTokenizer tokenize = new StringTokenizer(value);
- int size = tokenize.countTokens();
- double da[] = new double[size];
- int i = 0;
- while (tokenize.hasMoreTokens())
- {
- da[i] = Double.valueOf(tokenize.nextToken());
- ++i;
- }
- o = da;
- }
- // 1d array of ints.
- else if (propertyType.getName().equals("[I"))
- {
- StringTokenizer tokenize = new StringTokenizer(value);
- int size = tokenize.countTokens();
- int ia[] = new int[size];
- int i = 0;
- while (tokenize.hasMoreTokens())
- {
- ia[i] = Integer.valueOf(tokenize.nextToken());
- ++i;
- }
- o = ia;
- }
- // 1d array of floats.
- else if (propertyType.getName().equals("[F"))
- {
- StringTokenizer tokenize = new StringTokenizer(value);
- int size = tokenize.countTokens();
- float fa[] = new float[size];
- int i = 0;
- while (tokenize.hasMoreTokens())
- {
- fa[i] = Float.valueOf(tokenize.nextToken());
- ++i;
- }
- o = fa;
- }
- // 1d array of strings.
- else if (propertyType.getName().equals("[Ljava.lang.String;"))
- {
- StringTokenizer tokenize = new StringTokenizer(value);
- int size = tokenize.countTokens();
- String sa[] = new String[size];
- int i = 0;
- while (tokenize.hasMoreTokens())
- {
- sa[i] = tokenize.nextToken();
- ++i;
- }
- o = sa;
- }
- // 1d array of booleans.
- else if (propertyType.getName().equals("[Z"))
- {
- StringTokenizer tokenize = new StringTokenizer(value);
- int size = tokenize.countTokens();
- boolean ba[] = new boolean[size];
[truncated at 1000 lines; 86 more skipped]