com.sibvisions.util.type
Class ResourceUtil

java.lang.Object
  extended by com.sibvisions.util.type.ResourceUtil

public final class ResourceUtil
extends Object

The ResourceUtil contains resource and class dependent utility methods.


Method Summary
static boolean getAccessibleBoolean(String pName, boolean pDefaultValue)
          Gets the boolean value of a system property, if the property is accessible.
static String getAccessibleProperty(String pName, String pDefaultValue)
          Gets the string value of a system property, if the property is accessible.
static File getFileForClass(String pClassName)
          Searches the file in which a class is stored.
static String getFqClassName(Object pScope)
          Returns the full qualified class name for an object.
static String getLocationForClass(String pClassName)
          Searches the location where a class is stored.
static String getName(Class<?> pClass)
          Gets the name of a class.
static String getPackage(Class<?> pClass)
          Gets the package name from a class independent of Class.getPackage().
static String getPathForClass(String pClassName)
          Searches the directory where a class is stored.
static InputStream getResourceAsStream(String pResource)
          Finds a resource with a given name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getResourceAsStream

public static InputStream getResourceAsStream(String pResource)
Finds a resource with a given name. The search strategy is
  1. search a file with pResource as absolute path
  2. extract the filename of pResource, if it's an absolute path, and search in the classes or lib directory where this util class is stored
  3. delegate the search to the ClassLoader

Parameters:
pResource - one of the following: /package/<classname>.class, C:\temp\config.xml, /tmp/config.xml
Returns:
the resource stream or null if no resource with this name is found

getPathForClass

public static String getPathForClass(String pClassName)
Searches the directory where a class is stored. If the class is part of a jar archive then the directory in which the jar is stored will be used.

Parameters:
pClassName - z.B.: /package/<class>.class
Returns:
directory in which the class is stored or null if the class cann not be found

getLocationForClass

public static String getLocationForClass(String pClassName)
Searches the location where a class is stored. It can be a directory or jar file.

Parameters:
pClassName - z.B.: /package/<class>.class
Returns:
diretory, jar file or null if the class can not be found in the classpath

getFileForClass

public static File getFileForClass(String pClassName)
Searches the file in which a class is stored. It can be a class- or jar file.

Parameters:
pClassName - z.B.: /package/<class>.class
Returns:
class-, jar file or null if the class can not be found in the classpath

getFqClassName

public static String getFqClassName(Object pScope)
Returns the full qualified class name for an object.

Parameters:
pScope - a class or object instance
Returns:
the full qualified class name e.g. /package/<class>.class

getName

public static String getName(Class<?> pClass)
Gets the name of a class. It checks if the class is an anonymous or inner class.

Parameters:
pClass - class from which you want the name
Returns:
full qualified class name e.g. com.sibvisions.rad.util.type.ResourceUtil

getAccessibleProperty

public static String getAccessibleProperty(String pName,
                                           String pDefaultValue)
Gets the string value of a system property, if the property is accessible. Some properties are not accessible in applets. In that case the default value will be returned.

Parameters:
pName - the name of the system property
pDefaultValue - the default value if the property is null or is not accessible
Returns:
the value of the system property, if accessible and not is null, otherwise the pDefaultValue

getAccessibleBoolean

public static boolean getAccessibleBoolean(String pName,
                                           boolean pDefaultValue)
Gets the boolean value of a system property, if the property is accessible. Some properties are not accessible in applets. In that case the default value will be returned.

Parameters:
pName - the name of the system property
pDefaultValue - the default value if the property is null or is not accessible
Returns:
the value of the system property, if accessible and not is null, otherwise the pDefaultValue

getPackage

public static String getPackage(Class<?> pClass)
Gets the package name from a class independent of Class.getPackage().

Parameters:
pClass - the loaded class
Returns:
the package name for the class


Copyright © 2009 SIB Visions GmbH. All Rights Reserved.