com.boylesoftware.cb2.commons.property
Class PropertySharedBLO

java.lang.Object
  extended bycom.boylesoftware.cb2.BLObject
      extended bycom.boylesoftware.cb2.commons.property.PropertySharedBLO
All Implemented Interfaces:
java.io.Serializable

public class PropertySharedBLO
extends BLObject

Generic BLO for managing database-stored application properties, that are used by the application context via com.boylesoftware.cb2.appProperties.query property. This BLO can be deployed as a shared BLO since does not contain any session specific data. The BLO needs a number of initialization parameters that name the database table, which contains additional application properties, the column in the table, which contains property names, and the column, which contains property values. Here is how the BLO can be deployed in the blo-config.xml file:

 <blo name="property" shared="true">
   <init-param>
     <param-name>table</param-name>
     <param-value>Property</param-value>
   </init-param>
   <init-param>
     <param-name>nameColumn</param-name>
     <param-value>name</param-value>
   </init-param>
   <init-param>
     <param-name>valueColumn</param-name>
     <param-value>value</param-value>
   </init-param>
 </blo>

Note, that if the application does not use database-stored application properties, that is com.boylesoftware.cb2.appProperties.query is not set, the init method of this BLO throws an exception.

Version:
$Id: PropertySharedBLO.java,v 1.3 2004/04/29 19:32:47 levahim Exp $
Author:
Lev Himmelfarb
See Also:
Serialized Form

Field Summary
protected  java.lang.String dataSourceName
          Name of the data source corresponding to the database where the properties are stored.
protected  java.lang.String nameColumn
          Name of the column, which contains application property names.
protected static BTreeMap NONCHANGABLE_PROPS
          Set of name prefixes for application properties that cannot be stored in the database and can be specified only in the cb2app.properties file.
static int PROPTYPE_BASIC
          Property type, returned by getPropertyType method, which indicates that the property comes from the cb2app.properties file.
static int PROPTYPE_DB
          Property type, returned by getPropertyType method, which indicates that the property comes from the database.
static int PROPTYPE_IMMUTABLE
          Property type, returned by getPropertyType method, which indicates that the property comes from the cb2app.properties file and its value cannot be changed, because it is used by the application context before it processes additional properties from the database.
static int PROPTYPE_OVERRIDDEN
          Property type, returned by getPropertyType method, which indicates that the property comes from the cb2app.properties file, but its value has been overridden by a property with the same name stored in the database.
static int PROPTYPE_UNKNOWN
          This value is returned by getPropertyType method when type of a non existant property is requested.
protected  java.lang.String table
          Name of the database table, which contains application properties.
protected  java.lang.String valueColumn
          Name of the column, which contains application property values.
 
Fields inherited from class com.boylesoftware.cb2.BLObject
bloc, log
 
Constructor Summary
PropertySharedBLO()
           
 
Method Summary
 java.util.SortedMap getProperties()
          Gets all application properties as a sorted map.
 int getPropertyType(java.lang.String name)
          Tells the specified application property's type, which is where its value comes from.
protected  void init()
          Initializes the BLO.
 void resetProperty(java.lang.String name)
          Resets an application property's value.
 void saveProperties(java.util.Properties newProps)
          Saves properties from the specified set of properties that have different from current application properties values to the database.
 
Methods inherited from class com.boylesoftware.cb2.BLObject
activate, destroy, getApplicationContext, getBLO, getBLOContainer, getDAO, getDAO, getDAOConfig, getDAOConfig, getDeploymentName, getInitParameter, getLastErrors, isRollbackOnly, setErrors, setRollbackOnly
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPTYPE_UNKNOWN

public static final int PROPTYPE_UNKNOWN
This value is returned by getPropertyType method when type of a non existant property is requested.

See Also:
Constant Field Values

PROPTYPE_IMMUTABLE

public static final int PROPTYPE_IMMUTABLE
Property type, returned by getPropertyType method, which indicates that the property comes from the cb2app.properties file and its value cannot be changed, because it is used by the application context before it processes additional properties from the database.

See Also:
Constant Field Values

PROPTYPE_BASIC

public static final int PROPTYPE_BASIC
Property type, returned by getPropertyType method, which indicates that the property comes from the cb2app.properties file.

See Also:
Constant Field Values

PROPTYPE_OVERRIDDEN

public static final int PROPTYPE_OVERRIDDEN
Property type, returned by getPropertyType method, which indicates that the property comes from the cb2app.properties file, but its value has been overridden by a property with the same name stored in the database.

See Also:
Constant Field Values

PROPTYPE_DB

public static final int PROPTYPE_DB
Property type, returned by getPropertyType method, which indicates that the property comes from the database.

See Also:
Constant Field Values

NONCHANGABLE_PROPS

protected static final BTreeMap NONCHANGABLE_PROPS
Set of name prefixes for application properties that cannot be stored in the database and can be specified only in the cb2app.properties file.


dataSourceName

protected java.lang.String dataSourceName
Name of the data source corresponding to the database where the properties are stored. Set in the init method from com.boylesoftware.cb2.appProperties.dataSource application property. If the property is not defined, set to "default".


table

protected java.lang.String table
Name of the database table, which contains application properties. Set in the init method from the "table" BLO initialization parameter.


nameColumn

protected java.lang.String nameColumn
Name of the column, which contains application property names. Set in the init method from the "nameColumn" BLO initialization parameter.


valueColumn

protected java.lang.String valueColumn
Name of the column, which contains application property values. Set in the init method from the "valueColumn" BLO initialization parameter.

Constructor Detail

PropertySharedBLO

public PropertySharedBLO()
Method Detail

init

protected void init()
             throws BLException
Initializes the BLO.

Overrides:
init in class BLObject
Throws:
BLException - if the BLO cannot be initialized.

getPropertyType

public int getPropertyType(java.lang.String name)
Tells the specified application property's type, which is where its value comes from.

Parameters:
name - the application property's name.
Returns:
one of PROPTYPE_xxx values.

getProperties

public java.util.SortedMap getProperties()
Gets all application properties as a sorted map.

Returns:
map with all application properties sorted by their names.

saveProperties

public void saveProperties(java.util.Properties newProps)
                    throws BLException
Saves properties from the specified set of properties that have different from current application properties values to the database. It also saves properties that are not currently defined at all. This method can insert new values into the database, and it can update existing values. When all database operations have been finished successfully, the method calls setProperty on the applicatrion context for all changed properties.

Parameters:
newProps - collection of application property values.
Throws:
BLException - if a database error happens, or in case of an attempt to change an immutable property.

resetProperty

public void resetProperty(java.lang.String name)
                   throws BLException
Resets an application property's value. This method deletes the value from the database, which in the case of a database property removes it from the set of application properties, and in the case of an overridden basic property resets its value to the original one as defined in the cb2app.properties file. This method has no effect if the property is not stored in the database and it calls setProperty on the application context if any change has been made.

Parameters:
name - the application property's name.
Throws:
BLException - if a database error happens.


Copyright © 2002,2003,2004 - Boyle Software, Inc.