org.abstracthorizon.extend.server.support
Class ClassUtils

java.lang.Object
  extended by org.abstracthorizon.extend.server.support.ClassUtils

public class ClassUtils
extends Object

Utility class that contains class and url tool methods.

Author:
Daniel Sendula

Nested Class Summary
static class ClassUtils.LocalURLClassLoader
           
 
Constructor Summary
ClassUtils()
           
 
Method Summary
static Collection<URL> collectFiles(URL url)
          Collects files from given url.
static Collection<URL> collectFilesFromJar(URL original, JarFile jarFile)
          Collects files from jar file (root of)
static Collection<URL> collectFilesFromPath(File path)
          Collects files from given path
static Collection<URL> collectFilesFromURL(URL url)
          Collects files from give (generic) url
static URLClassLoader createClassLoader(ClassLoader parent, URL lib)
          Creates class loader for given url.
static URL getHomeLocation(Class<?> cls)
          Gets home location.
static void invokeMethod(Object object, String methodName, boolean mustBePresent)
          Invokes parametherless method with given name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassUtils

public ClassUtils()
Method Detail

invokeMethod

public static void invokeMethod(Object object,
                                String methodName,
                                boolean mustBePresent)
Invokes parametherless method with given name. If mustBePresent is set to true NoSuchMethodException is propagated wrapped in RuntimeException.

Parameters:
object - instance on which method is going to be executed
methodName - method name
mustBePresent - if set then method must be present or NoSuchMethodError is thrown
Throws:
RuntimeException - if NoSuchMethodException, IllegalArgumentException, IllegalAccessException or InvocationTargetException is thrown.

createClassLoader

public static URLClassLoader createClassLoader(ClassLoader parent,
                                               URL lib)
Creates class loader for given url. If url is directory then it is scanned and all jar files from it added to classpath.

Parameters:
parent - parent class loader or null
lib - url class loader to be created for.
Returns:
ClassUtils.LocalURLClassLoader instance

collectFiles

public static Collection<URL> collectFiles(URL url)
                                    throws IOException
Collects files from given url.

Parameters:
url - url
Returns:
collection of urls
Throws:
IOException

collectFilesFromPath

public static Collection<URL> collectFilesFromPath(File path)
                                            throws IOException
Collects files from given path

Parameters:
path - directory
Returns:
collection of urls
Throws:
IOException

collectFilesFromJar

public static Collection<URL> collectFilesFromJar(URL original,
                                                  JarFile jarFile)
                                           throws IOException
Collects files from jar file (root of)

Parameters:
original - original url
jarFile - jar file
Returns:
collection of urls
Throws:
IOException

collectFilesFromURL

public static Collection<URL> collectFilesFromURL(URL url)
                                           throws IOException
Collects files from give (generic) url

Parameters:
url - url
Returns:
collection of files
Throws:
IOException

getHomeLocation

public static URL getHomeLocation(Class<?> cls)
                           throws MalformedURLException
Gets home location.

Returns:
home location
Throws:
MalformedURLException


Copyright © 2005-2009 Abstract Horizon. All Rights Reserved.