com.dtolabs.rundeck.core.utils
Class PropertyLookup

java.lang.Object
  extended by com.dtolabs.rundeck.core.utils.PropertyLookup
All Implemented Interfaces:
PropertyRetriever, IPropertyLookup

public class PropertyLookup
extends java.lang.Object
implements IPropertyLookup

Simple utiltiy class to lookup property info


Method Summary
protected  int countProperties()
          Counts number of properties currently in this object.
static PropertyLookup create(java.io.File propFile)
          Factory method to create a property lookup object
static PropertyLookup create(java.io.File propfile, IPropertyLookup defaultsLookup)
          Calls base constructor with data from IPropertyLookup paramater as defaults.
static PropertyLookup create(java.io.File propfile, java.util.Map defaults, IPropertyLookup defaultsLookup)
          Calls base constructor feeding defaults from Map and IPropertyLookup params
static PropertyLookup create(IPropertyLookup defaultsLookup)
           
static PropertyLookup create(java.util.Properties props)
           
protected  java.util.Properties difference(java.util.Map map)
          Reads map of input properties and returns a collection of those that are unique to that input set.
 PropertyLookup expand()
          Calls PropertyUtil.expand(Map) to expand all properties.
static java.util.Properties fetchProperties(java.io.File propFile)
          given a file reads in its properties
 java.util.Map getPropertiesMap()
          Retrieves map of property data
 java.lang.String getProperty(java.lang.String key)
          Get the property per specified key
 boolean hasProperty(java.lang.String key)
          Check if property exists in file
static boolean hasProperty(java.lang.String propKey, java.io.File propFile)
          Reads propFile and then checks if specified key exists.
 PropertyRetriever safe()
           
static PropertyRetriever safePropertyRetriever(IPropertyLookup lookup)
          Create a PropertyRetriever from a PropertyLookup that will not throw exception
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

create

public static PropertyLookup create(java.util.Properties props)

create

public static PropertyLookup create(IPropertyLookup defaultsLookup)

create

public static PropertyLookup create(java.io.File propFile)
Factory method to create a property lookup object

Parameters:
propFile - File where proeprty data is contained
Returns:

create

public static PropertyLookup create(java.io.File propfile,
                                    IPropertyLookup defaultsLookup)
Calls base constructor with data from IPropertyLookup paramater as defaults. Defaults data is read via the IPropertyLookup.getPropertiesMap() method.

Parameters:
propfile - File containing property data
defaultsLookup - IPropertyLookup of default properties

create

public static PropertyLookup create(java.io.File propfile,
                                    java.util.Map defaults,
                                    IPropertyLookup defaultsLookup)
Calls base constructor feeding defaults from Map and IPropertyLookup params

Parameters:
propfile - File containing property data
defaults - Map of default properties
defaultsLookup - IPropertyLookup of default properties

getProperty

public java.lang.String getProperty(java.lang.String key)
Get the property per specified key

Specified by:
getProperty in interface PropertyRetriever
Specified by:
getProperty in interface IPropertyLookup
Parameters:
key - name of the property
Returns:
Value of the property
Throws:
PropertyLookupException - thrown if lookup fails for specified key

safe

public PropertyRetriever safe()

safePropertyRetriever

public static PropertyRetriever safePropertyRetriever(IPropertyLookup lookup)
Create a PropertyRetriever from a PropertyLookup that will not throw exception

Parameters:
lookup -
Returns:

hasProperty

public boolean hasProperty(java.lang.String key)
Check if property exists in file

Specified by:
hasProperty in interface IPropertyLookup
Parameters:
key - Name of the property
Returns:
true if it exists; false otherwise

fetchProperties

public static java.util.Properties fetchProperties(java.io.File propFile)
given a file reads in its properties

Parameters:
propFile - File to read
Returns:
a Properties object with data filled from propFile
Throws:
PropertyLookupException - thrown if error loading property file

getPropertiesMap

public java.util.Map getPropertiesMap()
Retrieves map of property data

Specified by:
getPropertiesMap in interface IPropertyLookup
Returns:
Unmodifiable Map containing property key/value pair
Throws:
PropertyLookupException - thrown if loaderror

expand

public PropertyLookup expand()
Calls PropertyUtil.expand(Map) to expand all properties.


difference

protected java.util.Properties difference(java.util.Map map)
Reads map of input properties and returns a collection of those that are unique to that input set.

Parameters:
map - Map of key/value pairs
Returns:
Properties unique to map

countProperties

protected int countProperties()
Counts number of properties currently in this object.

Returns:
number of properties

hasProperty

public static boolean hasProperty(java.lang.String propKey,
                                  java.io.File propFile)
Reads propFile and then checks if specified key exists.

Parameters:
propKey - property name
propFile - property file
Returns:
file if a property with that name exists. If an exception occurs while reading the file, false is returned.