Class Util

java.lang.Object
  extended by Util

public class Util
extends Object

Contains tools useful for XML-based configuration file handling as well as file zipping.

Author:
fhogenboom

Field Summary
private static org.slf4j.Logger _log
           
private static HashMap<String,org.quartz.JobDataMap> config
           
private static String config_src
           
private static int writers
           
 
Constructor Summary
Util()
          Constructor.
 
Method Summary
static Integer getInteger(Object object)
          Parses an Object to an Integer.
static String getString(Object object)
          Parses an Object to a String.
static org.quartz.JobDataMap loadDataMap(org.quartz.JobExecutionContext context)
          Loads configurations for local component elements stored in a JobDataMap, which is available during runtime of the component.
static Object parseXMLelement(String element1, String element2)
          Parses an XML-based configuration file and looks for the value of a (sub)element.
private static Object parseXMLelement(String element1, String element2, boolean list)
          Parses an XML-based configuration file and looks for one or more values of a (sub)element.
static Object parseXMLelements(String element1, String element2)
          Parses an XML-based configuration file and looks for multiple values of a (sub)element.
static Object parseXMLid(String id, String element1, String element2)
          Parses an XML-based configuration file and looks for the value of a (sub)element with a specific ID.
private static Object parseXMLid(String id, String element1, String element2, boolean list)
          Parses an XML-based configuration file and looks for one or more values of a (sub)element with a specific ID.
static Object parseXMLids(String id, String element1, String element2)
          Parses an XML-based configuration file and looks for multiple values of a (sub)element with a specific ID.
static TreeMap<Object,Object> parseXMLparameter(String element1, String parameter1, String parameter2)
          Parses an XML-based configuration file and looks for the values of the parameters of an element.
static void setConfig(String src)
          Sets location of the configuration file to be used.
static void storeDataMap(org.quartz.JobExecutionContext context, org.quartz.JobDataMap dataMap)
          Stores configurations for local component elements in a JobDataMap, which is available during runtime of the component.
static void zipFile(String name, String path, String file, String ext, int buffer)
          Zips a file of a given name and extension in a given folder.
static void zipFiles(String name, String path, String file, String ext, int buffer, int max_files)
          Zips files of a given extension in a given folder to a single file with a given name.
private static void zipLock()
          Locks the zipping process in order to prevent asynchronous writing.
private static void zipUnlock()
          Releases the lock on the zipping process that is used in order to prevent asynchronous writing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

config

private static HashMap<String,org.quartz.JobDataMap> config

writers

private static int writers

config_src

private static String config_src

_log

private static org.slf4j.Logger _log
Constructor Detail

Util

public Util()
Constructor.

Method Detail

setConfig

public static void setConfig(String src)
Sets location of the configuration file to be used.

Parameters:
src - Path and file name of configuration file to be used.

loadDataMap

public static org.quartz.JobDataMap loadDataMap(org.quartz.JobExecutionContext context)
Loads configurations for local component elements stored in a JobDataMap, which is available during runtime of the component.

Parameters:
context - Execution context of the component.
Returns:
JobDataMap representing component configuration.

storeDataMap

public static void storeDataMap(org.quartz.JobExecutionContext context,
                                org.quartz.JobDataMap dataMap)
Stores configurations for local component elements in a JobDataMap, which is available during runtime of the component.

Parameters:
context - Execution context of the component.
dataMap - Component configuration.

getInteger

public static Integer getInteger(Object object)
Parses an Object to an Integer.

Parameters:
object - Object to be parsed.
Returns:
Integer value representing the Object to be parsed.

getString

public static String getString(Object object)
Parses an Object to a String.

Parameters:
object - Object to be parsed.
Returns:
String value representing the Object to be parsed.

parseXMLelement

private static Object parseXMLelement(String element1,
                                      String element2,
                                      boolean list)
Parses an XML-based configuration file and looks for one or more values of a (sub)element.

Parameters:
element1 - Main element to be parsed.
element2 - Sub-element to be parsed.
list - Boolean value indicating whether one (false) or multiple ( true) values are desired
Returns:
Object representing the value(s) of the (sub)element to be parsed. Depending on the value of list this is either an Object or an ArrayList of Object instances.

parseXMLelement

public static Object parseXMLelement(String element1,
                                     String element2)
Parses an XML-based configuration file and looks for the value of a (sub)element.

Parameters:
element1 - Main element to be parsed.
element2 - Sub-element to be parsed.
Returns:
Object representing the value of the (sub)element to be parsed.

parseXMLelements

public static Object parseXMLelements(String element1,
                                      String element2)
Parses an XML-based configuration file and looks for multiple values of a (sub)element.

Parameters:
element1 - Main element to be parsed.
element2 - Sub-element to be parsed.
Returns:
Object representing the values of the (sub)element to be parsed.

parseXMLid

private static Object parseXMLid(String id,
                                 String element1,
                                 String element2,
                                 boolean list)
Parses an XML-based configuration file and looks for one or more values of a (sub)element with a specific ID.

Parameters:
id - Unique id of the (sub)element to be parsed.
element1 - Main element to be parsed.
element2 - Sub-element to be parsed.
list - Boolean value indicating whether one (false) or multiple ( true) values are desired
Returns:
Object representing the value(s) of the (sub)element to be parsed. Depending on the value of list this is either an Object or an ArrayList of Object instances.

parseXMLid

public static Object parseXMLid(String id,
                                String element1,
                                String element2)
Parses an XML-based configuration file and looks for the value of a (sub)element with a specific ID.

Parameters:
id - Unique id of the (sub)element to be parsed.
element1 - Main element to be parsed.
element2 - Sub-element to be parsed.
Returns:
Object representing the value of the (sub)element to be parsed.

parseXMLids

public static Object parseXMLids(String id,
                                 String element1,
                                 String element2)
Parses an XML-based configuration file and looks for multiple values of a (sub)element with a specific ID.

Parameters:
id - Unique id of the (sub)element to be parsed.
element1 - Main element to be parsed.
element2 - Sub-element to be parsed.
Returns:
Object representing the values of the (sub)element to be parsed.

parseXMLparameter

public static TreeMap<Object,Object> parseXMLparameter(String element1,
                                                       String parameter1,
                                                       String parameter2)
Parses an XML-based configuration file and looks for the values of the parameters of an element.

Parameters:
element1 - Main element to be parsed.
parameter1 - First parameter to be parsed.
parameter2 - Second parameter to be parsed.
Returns:
TreeMap of Object instances representing the values of the parameters of the element to be parsed.

zipFile

public static void zipFile(String name,
                           String path,
                           String file,
                           String ext,
                           int buffer)
Zips a file of a given name and extension in a given folder. After completion, target file is removed. File name is equal to the name of the file to be zipped.

Parameters:
name - Name of the storage initiating zip action.
path - Path of the file to be zipped.
file - Name of the file to be zipped.
ext - Extension of the file to be zipped.
buffer - Buffer used when zipping.

zipFiles

public static void zipFiles(String name,
                            String path,
                            String file,
                            String ext,
                            int buffer,
                            int max_files)
Zips files of a given extension in a given folder to a single file with a given name. After completion, target files are removed.

Parameters:
name - Name of the storage initiating zip action.
path - Path of the files to be zipped.
file - Name of the resulting zip file.
ext - Extension of the files to be zipped.
buffer - Buffer used when zipping.
max_files - Maximum number of files to be added to the zip file.

zipLock

private static void zipLock()
                     throws InterruptedException
Locks the zipping process in order to prevent asynchronous writing. If a writing task is in process, a wait instruction is issued before the lock is generated.

Throws:
InterruptedException - An exception that indicates the waiting process has been interrupted.

zipUnlock

private static void zipUnlock()
Releases the lock on the zipping process that is used in order to prevent asynchronous writing. After the lock has been released, all waiting processes (if any) are notified.