net.sf.taverna.raven.prelauncher
Class ClassLocation

java.lang.Object
  extended by net.sf.taverna.raven.prelauncher.ClassLocation

public class ClassLocation
extends java.lang.Object

Given a Class, find the directory/JAR it was loaded from. This can be used to find the bootstrap directory the application was installed to.

Author:
Stian Soiland-Reyes, Stuart Owen

Constructor Summary
ClassLocation()
           
 
Method Summary
static java.io.File getClassLocationDir(java.lang.Class<?> theClass)
          Get the canonical directory of the class file or jar file that the given class was loaded from.
static java.io.File getClassLocationFile(java.lang.Class<?> theClass)
          Get the canonical directory or jar file that the given class was loaded from.
static java.net.URI getClassLocationURI(java.lang.Class<?> theClass)
          Get the URI from where the given class was loaded from.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassLocation

public ClassLocation()
Method Detail

getClassLocationDir

public static java.io.File getClassLocationDir(java.lang.Class<?> theClass)
                                        throws java.io.IOException
Get the canonical directory of the class file or jar file that the given class was loaded from. This method can be used to calculate the root directory of an installation.

Parameters:
theClass - The class which location is to be found
Returns:
The canonical directory of the class or jar file that this class file was loaded from
Throws:
java.io.IOException - if the canonical directory or jar file cannot be found
See Also:
getClassLocationFile(Class)

getClassLocationFile

public static java.io.File getClassLocationFile(java.lang.Class<?> theClass)
                                         throws java.io.IOException
Get the canonical directory or jar file that the given class was loaded from. Note that this file might be a jar, use getClassLocationDir(Class) if you want the directory that contains the JAR.

Returns:
The canonical directory or jar file that this class file was loaded from
Throws:
java.io.IOException - if the canonical directory or jar file cannot be found, or the class was not loaded from a file:/// URI.
See Also:
getClassLocationURI(Class)

getClassLocationURI

public static java.net.URI getClassLocationURI(java.lang.Class<?> theClass)
                                        throws java.io.IOException
Get the URI from where the given class was loaded from. Note that this might be pointing to a JAR or a location on the network. If you want the location as a file or directory, use getClassLocationFile(Class) or getClassLocationDir(Class).

Returns:
The canonical directory or jar file that this class file was loaded from
Throws:
java.io.IOException - if the canonical directory or jar file cannot be found, or the class was not loaded from a file:/// URI.
See Also:
getClassLocationURI(Class)