org.mobicents.protocols.smpp.util
Class AbstractAPIConfig

java.lang.Object
  extended by org.mobicents.protocols.smpp.util.AbstractAPIConfig
All Implemented Interfaces:
APIConfig
Direct Known Subclasses:
PropertiesAPIConfig

public abstract class AbstractAPIConfig
extends Object
implements APIConfig

Abstract base class for APIConfig instances. Provides some basic functionality useful across all APIConfig instances.

Boolean values: Any of the strings "true", "on" or "yes" will evaluate to a boolean true. The strings "false", "off" or "no" will all evaluate to a boolean false. Additionally, booleans can be numeric, where zero is evaluated as false and a non-zero value is evaluated as true.

Numbers: Numbers can be specified in any of decimal, hexadecimal, binary or octal notations. Decimal is the default. Prefixing a number with "0x" causes it to be parsed as hexadecimal. Prefixing a number with '0' causes it to be parsed as octal. Suffixing the number with a 'b' causes it to be parsed as binary. For example:

Decimal numbers may also be modified with a multiplier. Suffixing the letters 'k' or 'm' at the end of a decimal number multiples it by 1024 and 1048576 respectively. This is useful for specifying a number or kilobytes or megabytes. For example

Version:
$Id: AbstractAPIConfig.java 477 2009-07-12 18:00:20Z orank $

Field Summary
 
Fields inherited from interface org.mobicents.protocols.smpp.util.APIConfig
BIND_TIMEOUT, DEFAULT_ALPHABET, DEFAULT_VERSION, EVENT_DISPATCHER_CLASS, EVENT_THREAD_POOL_SIZE, LAX_VERSIONS, LINK_AUTO_FLUSH, LINK_AUTOCLOSE_SNOOP, LINK_BUFFERSIZE_IN, LINK_BUFFERSIZE_OUT, LINK_TIMEOUT, SEGMENT_SIZE, TOO_MANY_IO_EXCEPTIONS
 
Constructor Summary
AbstractAPIConfig()
           
 
Method Summary
protected  long convertToNumber(String num)
          Convert a number string into a long, taking into account base and multiplication specifiers.
 boolean getBoolean(String property)
          Get a property as a boolean value.
 boolean getBoolean(String property, boolean defaultValue)
          Get a property as a boolean value.
<T> T
getClassInstance(String property, Class<T> type)
          Instantiate a new instance of a class whose class name is specified in property.
<T> T
getClassInstance(String property, Class<T> type, T defaultValue)
          Instantiate a new instance of a class whose class name is specified in property, returning a default value if the property is not set.
 int getInt(String property)
          Get the value for a property, parsed as a Java int.
 int getInt(String property, int defaultValue)
          Get the value for a property, parsed as a Java int.
 long getLong(String property)
          Get the value for a property, parsed as a Java long.
 long getLong(String property, long defaultValue)
          Get the value for a property, parsed as a Java long.
 String getProperty(String property, String defaultValue)
          Get the value for a property or return a default value if it is not set.
 short getShort(String property)
          Get the value for a property, parsed as a Java short.
 short getShort(String property, short defaultValue)
          Get the value of a property, parsed as a short.
 boolean isSet(String property)
          Determine if a property is set in the configuration.
protected  boolean toBoolean(String value)
          Convert a string value to a boolean.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.mobicents.protocols.smpp.util.APIConfig
getProperty, initialise, reloadAPIConfig
 

Constructor Detail

AbstractAPIConfig

public AbstractAPIConfig()
Method Detail

isSet

public boolean isSet(String property)
Description copied from interface: APIConfig
Determine if a property is set in the configuration.

Specified by:
isSet in interface APIConfig
Parameters:
property - The name of the property to test.
Returns:
true if the property is set, false if not.

getProperty

public String getProperty(String property,
                          String defaultValue)
Description copied from interface: APIConfig
Get the value for a property or return a default value if it is not set.

Specified by:
getProperty in interface APIConfig
Parameters:
property - The name of the property to retrieve.
defaultValue - The value to return if property is not set.
Returns:
The value for property.

getShort

public short getShort(String property)
               throws InvalidConfigurationException,
                      PropertyNotFoundException
Description copied from interface: APIConfig
Get the value for a property, parsed as a Java short.

Specified by:
getShort in interface APIConfig
Parameters:
property - the name of the property to retrive.
Returns:
The value of property.
Throws:
InvalidConfigurationException - if the value is not a valid short.
PropertyNotFoundException - if property is not found in the configuration.

getShort

public short getShort(String property,
                      short defaultValue)
Description copied from interface: APIConfig
Get the value of a property, parsed as a short. If the property is not set, the default value is returned.

Specified by:
getShort in interface APIConfig
Parameters:
property - The name of the property to retrieve the value for.
defaultValue - The default value to return if the property is not set.
Returns:
The value for property.

getInt

public int getInt(String property)
           throws InvalidConfigurationException,
                  PropertyNotFoundException
Description copied from interface: APIConfig
Get the value for a property, parsed as a Java int.

Specified by:
getInt in interface APIConfig
Parameters:
property - the name of the property to retrive.
Returns:
The value of property.
Throws:
InvalidConfigurationException - if the value is not a valid integer.
PropertyNotFoundException - if property is not found in the configuration.

getInt

public int getInt(String property,
                  int defaultValue)
Description copied from interface: APIConfig
Get the value for a property, parsed as a Java int. If the property is not found, the default value is returned.

Specified by:
getInt in interface APIConfig
Parameters:
property - the name of the property to retrive.
defaultValue - the value to return if the property does not exist.
Returns:
The value of property.

getLong

public long getLong(String property)
             throws InvalidConfigurationException,
                    PropertyNotFoundException
Description copied from interface: APIConfig
Get the value for a property, parsed as a Java long.

Specified by:
getLong in interface APIConfig
Parameters:
property - the name of the property to retrive.
Returns:
The value of property.
Throws:
InvalidConfigurationException - if the value is not a valid long.
PropertyNotFoundException - if property is not found in the configuration.

getLong

public long getLong(String property,
                    long defaultValue)
Description copied from interface: APIConfig
Get the value for a property, parsed as a Java long. If the property is not found, the default value is returned.

Specified by:
getLong in interface APIConfig
Parameters:
property - the name of the property to retrieve.
defaultValue - the value to return if the property does not exist.
Returns:
The value of property.

getBoolean

public boolean getBoolean(String property)
                   throws InvalidConfigurationException,
                          PropertyNotFoundException
Description copied from interface: APIConfig
Get a property as a boolean value. See the description of APIConfig.getBoolean(String, boolean) for details of how a boolean value can be specified.

Specified by:
getBoolean in interface APIConfig
Parameters:
property - The name of the property to retrieve.
Returns:
The value of property.
Throws:
InvalidConfigurationException - if the property has a value that cannot be parsed or interpreted as boolean.
PropertyNotFoundException - if property is not found in the configuration.

getBoolean

public boolean getBoolean(String property,
                          boolean defaultValue)
Description copied from interface: APIConfig
Get a property as a boolean value. Any of 'on', 'yes' or 'true' (irrelevant of case) will evaluate to true. Any of 'off', 'no' or 'false' will evaluate to false. Boolean parameters may also be specified as a number, where zero will equate to false while non-zero will equate to true. All other words will result in an InvalidConfigurationException being thrown.

Specified by:
getBoolean in interface APIConfig
Parameters:
property - the name of the property to look up.
defaultValue - the value to return if the property does not exist.
Returns:
The value of property.

getClassInstance

public <T> T getClassInstance(String property,
                              Class<T> type)
Description copied from interface: APIConfig
Instantiate a new instance of a class whose class name is specified in property.

Specified by:
getClassInstance in interface APIConfig
Type Parameters:
T - The expected type of the instantiated class.
Parameters:
property - The name of a property whose value is the fully qualified name of a class to instantiate.
type - The expected type of the instantiated class. This may specify a super-class or interface of the actually instantiated class.
Returns:
The new object instance.

getClassInstance

public <T> T getClassInstance(String property,
                              Class<T> type,
                              T defaultValue)
Description copied from interface: APIConfig
Instantiate a new instance of a class whose class name is specified in property, returning a default value if the property is not set.

Specified by:
getClassInstance in interface APIConfig
Type Parameters:
T - The expected type of the instantiated class.
Parameters:
property - The name of a property whose value is the fully qualified name of a class to instantiate.
type - The expected type of the instantiated class. This may specify a super-class or interface of the actually instantiated class.
Returns:
The new object instance, or defaultValue if property is not set.

toBoolean

protected boolean toBoolean(String value)
Convert a string value to a boolean.

Parameters:
value - The value to determine a boolean value for.
Returns:
A boolean value.
Throws:
InvalidConfigurationException - If value is not a valid boolean value.

convertToNumber

protected long convertToNumber(String num)
                        throws NumberFormatException
Convert a number string into a long, taking into account base and multiplication specifiers.

Parameters:
num - The String representing the number.
Returns:
The parsed number.
Throws:
NumberFormatException - If the String cannot be parsed as a number.


Copyright © 2011 Mobicents. All Rights Reserved.