com.twelvemonkeys.lang
Class SystemUtil

java.lang.Object
  extended by com.twelvemonkeys.lang.SystemUtil

public final class SystemUtil
extends Object

A utility class with some useful system-related functions.

NOTE: This class is not considered part of the public API and may be changed without notice

Version:
$Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/lang/SystemUtil.java#3 $
Author:
Harald Kuhr, last modified by $Author: haku $

Field Summary
static String STD_PROPERTIES
          ".properties"
static String XML_PROPERTIES
          ".xml"
 
Method Summary
static Object clone(Cloneable pObject)
           
static boolean isClassAvailable(String pClassName)
          Tests if a named class is generally available.
static boolean isClassAvailable(String pClassName, Class pFromClass)
          Tests if a named class is available from another class.
static boolean isFieldAvailable(String pClassName, String pFieldName)
           
static boolean isFieldAvailable(String pClassName, String pFieldName, Class pFromClass)
           
static boolean isMethodAvailable(String pClassName, String pMethodName)
           
static boolean isMethodAvailable(String pClassName, String pMethodName, Class[] pParams)
           
static boolean isMethodAvailable(String pClassName, String pMethodName, Class[] pParams, Class pFromClass)
           
static Properties loadProperties(Class pClass)
          Utility method for loading a properties-file for a given class.
static Properties loadProperties(Class pClass, String pName)
          Utility method for loading a named properties-file for a class.
static Properties loadProperties(String pName)
          Utility method for loading a named properties-file.
static void main(String[] args)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

XML_PROPERTIES

public static String XML_PROPERTIES
".xml"


STD_PROPERTIES

public static String STD_PROPERTIES
".properties"

Method Detail

loadProperties

public static Properties loadProperties(Class pClass,
                                        String pName)
                                 throws IOException
Utility method for loading a named properties-file for a class.

The properties-file is loaded through either:

  1. The given class' class loader (from classpath)
  2. Or, the system class loader (from classpath)
  3. Or, if it cannot be found in the classpath, an attempt to read from the current directory (or full path if given).

Both normal java.util.Properties and com.twelvemonkeys.util.XMLProperties are supported (XML-properties must have ".xml" as its file extension).

Parameters:
pClass - The class to load properties for. If this parameter is null, the method will work exactly as loadProperties(String)
pName - The name of the properties-file. If this parameter is null, the method will work exactly as loadProperties(Class)
Returns:
A Properties mapping read from the given file or for the given class.
Throws:
NullPointerException - if both pName and pClass paramters are null
IOException - if an error occurs during load.
FileNotFoundException - if no properties-file could be found.
See Also:
loadProperties(String), loadProperties(Class), ClassLoader.getResourceAsStream(java.lang.String), ClassLoader.getSystemResourceAsStream(java.lang.String)

loadProperties

public static Properties loadProperties(Class pClass)
                                 throws IOException
Utility method for loading a properties-file for a given class. The properties are searched for on the form "com/package/ClassName.properties" or "com/package/ClassName.xml".

The properties-file is loaded through either:

  1. The given class' class loader (from classpath)
  2. Or, the system class loader (from classpath)
  3. Or, if it cannot be found in the classpath, an attempt to read from the current directory (or full path if given).

Both normal java.util.Properties and com.twelvemonkeys.util.XMLProperties are supported (XML-properties must have ".xml" as its file extension).

Parameters:
pClass - The class to load properties for
Returns:
A Properties mapping for the given class.
Throws:
NullPointerException - if the pClass paramters is null
IOException - if an error occurs during load.
FileNotFoundException - if no properties-file could be found.
See Also:
loadProperties(String), loadProperties(Class, String), ClassLoader.getResourceAsStream(java.lang.String), ClassLoader.getSystemResourceAsStream(java.lang.String)

loadProperties

public static Properties loadProperties(String pName)
                                 throws IOException
Utility method for loading a named properties-file.

The properties-file is loaded through either:

  1. The system class loader (from classpath)
  2. Or, if it cannot be found in the classpath, an attempt to read from the current directory.

Both normal java.util.Properties and com.twelvemonkeys.util.XMLProperties are supported (XML-properties must have ".xml" as its file extension).

Parameters:
pName - The name of the properties-file.
Returns:
A Properties mapping read from the given file.
Throws:
NullPointerException - if the pName paramters is null
IOException - if an error occurs during load.
FileNotFoundException - if no properties-file could be found.
See Also:
loadProperties(Class), loadProperties(Class, String), ClassLoader.getSystemResourceAsStream(java.lang.String)

clone

public static Object clone(Cloneable pObject)
                    throws CloneNotSupportedException
Throws:
CloneNotSupportedException

main

public static void main(String[] args)
                 throws CloneNotSupportedException
Throws:
CloneNotSupportedException

isClassAvailable

public static boolean isClassAvailable(String pClassName)
Tests if a named class is generally available. If a class is considered available, a call to Class.forName(pClassName) will not result in an exception.

Parameters:
pClassName - the class name to test
Returns:
true if available

isClassAvailable

public static boolean isClassAvailable(String pClassName,
                                       Class pFromClass)
Tests if a named class is available from another class. If a class is considered available, a call to Class.forName(pClassName, true, pFromClass.getClassLoader()) will not result in an exception.

Parameters:
pClassName - the class name to test
pFromClass - the class to test from
Returns:
true if available

isFieldAvailable

public static boolean isFieldAvailable(String pClassName,
                                       String pFieldName)

isFieldAvailable

public static boolean isFieldAvailable(String pClassName,
                                       String pFieldName,
                                       Class pFromClass)

isMethodAvailable

public static boolean isMethodAvailable(String pClassName,
                                        String pMethodName)

isMethodAvailable

public static boolean isMethodAvailable(String pClassName,
                                        String pMethodName,
                                        Class[] pParams)

isMethodAvailable

public static boolean isMethodAvailable(String pClassName,
                                        String pMethodName,
                                        Class[] pParams,
                                        Class pFromClass)


Copyright © 2014. All Rights Reserved.