Package weka.core

Class ResourceUtils


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

      Constructors 
      Constructor Description
      ResourceUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Object forName​(java.lang.Class<?> classType, java.lang.String className, java.lang.String[] options)
      Creates a new instance of an object given it's class name and (optional) arguments to pass to it's setOptions method.
      static java.io.File getWekaHome()
      Returns the Weka home directory.
      static java.util.Properties readProperties​(java.lang.String resourceName)
      Reads properties that inherit from three locations.
      static java.util.Properties readProperties​(java.lang.String resourceName, java.lang.ClassLoader loader)
      Reads properties that inherit from three locations.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ResourceUtils

        public ResourceUtils()
    • Method Detail

      • forName

        public static java.lang.Object forName​(java.lang.Class<?> classType,
                                               java.lang.String className,
                                               java.lang.String[] options)
                                        throws java.lang.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:
        java.lang.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 java.util.Properties readProperties​(java.lang.String resourceName)
                                                   throws java.lang.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:
        java.lang.Exception - if no default properties are defined, or if an error occurs reading the properties files.
      • readProperties

        public static java.util.Properties readProperties​(java.lang.String resourceName,
                                                          java.lang.ClassLoader loader)
                                                   throws java.lang.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:
        java.lang.Exception - if no default properties are defined, or if an error occurs reading the properties files.
      • getWekaHome

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