Package weka.core

Class ResourceUtils

java.lang.Object
weka.core.ResourceUtils

public class ResourceUtils extends Object
Helper for resources.
Version:
$Revision$
Author:
FracPete (fracpete at waikato dot ac dot nz)
  • Constructor Details

    • ResourceUtils

      public ResourceUtils()
  • Method Details

    • forName

      public static Object forName(Class<?> classType, String className, String[] options) throws Exception
      Creates a new instance of an object given it's class name and (optional) arguments to pass to it's setOptions method. If the object implements OptionHandler and the options parameter is non-null, the object will have it's options set. Example use:

       String classifierName = Utils.getOption('W', options);
       Classifier c = (Classifier)Utils.forName(Classifier.class,
                                                classifierName,
                                                options);
       setClassifier(c);
       
      Parameters:
      classType - the class that the instantiated object should be assignable to -- an exception is thrown if this is not the case
      className - the fully qualified class name of the object
      options - an array of options suitable for passing to setOptions. May be null. Any options accepted by the object will be removed from the array.
      Returns:
      the newly created object, ready for use (if it is an array, it will have size zero).
      Throws:
      Exception - if the class name is invalid, or if the class is not assignable to the desired class type, or the options supplied are not acceptable to the object
    • readProperties

      public static Properties readProperties(String resourceName) throws Exception
      Reads properties that inherit from three locations. Properties are first defined in the system resource location (i.e. in the CLASSPATH). These default properties must exist. Properties optionally defined in the user properties location (WekaPackageManager.PROPERTIES_DIR) override default settings. Properties defined in the current directory (optional) override all these settings.
      Parameters:
      resourceName - the location of the resource that should be loaded. e.g.: "weka/core/Utils.props". (The use of hardcoded forward slashes here is OK - see jdk1.1/docs/guide/misc/resources.html) This routine will also look for the file (in this case) "Utils.props" in the users home directory and the current directory.
      Returns:
      the Properties
      Throws:
      Exception - if no default properties are defined, or if an error occurs reading the properties files.
    • readProperties

      public static Properties readProperties(String resourceName, ClassLoader loader) throws Exception
      Reads properties that inherit from three locations. Properties are first defined in the system resource location (i.e. in the CLASSPATH). These default properties must exist. Properties optionally defined in the user properties location (WekaPackageManager.PROPERTIES_DIR) override default settings. Properties defined in the current directory (optional) override all these settings.
      Parameters:
      resourceName - the location of the resource that should be loaded. e.g.: "weka/core/Utils.props". (The use of hardcoded forward slashes here is OK - see jdk1.1/docs/guide/misc/resources.html) This routine will also look for the file (in this case) "Utils.props" in the users home directory and the current directory.
      loader - the class loader to use when loading properties
      Returns:
      the Properties
      Throws:
      Exception - if no default properties are defined, or if an error occurs reading the properties files.
    • getWekaHome

      public static File getWekaHome()
      Returns the Weka home directory.
      Returns:
      the home directory