com.opensymphony.module.propertyset
Interface PropertySet

All Known Implementing Classes:
AbstractPropertySet, CachingPropertySet

public interface PropertySet

A PropertySet is designed to be associated with other entities in the system for storing key/value property pairs.

A key can only contain one value and a key is unique across all types. If a property is set using the same key and an already existing property of the SAME type, the new value will overwrite the old. However, if a property of DIFFERENT type attempts to overwrite the existing value, a DuplicatePropertyKeyException should be thrown.

If a property is set of a type that is not allowed, a IllegalPropertyException should be thrown.

If a property is retrieved that exists but contains a value of different type, a InvalidPropertyTypeException should be thrown.

If a property is retrieved that does not exist, null (or the primitive equivalent) is returned.

If an Exception is encountered in the actual implementation of the PropertySet that needs to be rethrown, it should be wrapped in a PropertyImplementationException .

Some PropertySet implementations may not store along side the data the original type it was set as. This means that it could be retrieved using a get method of a different type without throwing an InvalidPropertyTypeException (so long as the original type can be converted to the requested type.

Typed PropertySet Example

propertySet.setString("something","99");
x = propertySet.getString("something"); // throws InvalidPropertyTypeException

Untyped PropertySet Example

propertySet.setString("something","99");
x = propertySet.getString("something"); // returns 99.

Typically (unless otherwise stated), an implementation is typed. This can be checked by calling the supportsTypes() method of the implementation.

Not all PropertySet implementations need to support setter methods (i.e. they are read only) and not all have to support storage/retrieval of specific types. The capabilities of the specific implementation can be determined by calling supportsType(int) and #isSettable() .

Version:
$Revision: 1.14 $
Author:
Joe Walnes

Field Summary
static int BOOLEAN
          Value-type boolean
static int DATA
          Value-type byte[]
static int DATE
          Value-type Date
static int DOUBLE
          Value-type double
static int INT
          Value-type int
static int LONG
          Value-type long
static int OBJECT
          Value-type serializable Object
static int PROPERTIES
          Value-type Properties
static int STRING
          Value-type String (max length 255)
static int TEXT
          Value-type text (unlimited length String)
static int XML
          Value-type XML Document
 
Method Summary
 boolean exists(java.lang.String key)
          Determine if property exists.
 boolean getBoolean(java.lang.String key)
           
 byte[] getData(java.lang.String key)
           
 java.util.Date getDate(java.lang.String key)
           
 double getDouble(java.lang.String key)
           
 int getInt(java.lang.String key)
           
 java.util.Collection getKeys()
          List all keys.
 java.util.Collection getKeys(int type)
          List all keys of certain type.
 java.util.Collection getKeys(java.lang.String prefix)
          List all keys starting with supplied prefix.
 java.util.Collection getKeys(java.lang.String prefix, int type)
          List all keys starting with supplied prefix of certain type.
 long getLong(java.lang.String key)
           
 java.lang.Object getObject(java.lang.String key)
           
 java.util.Properties getProperties(java.lang.String key)
           
 PropertySetSchema getSchema()
           
 java.lang.String getString(java.lang.String key)
          String of maximum 255 chars.
 java.lang.String getText(java.lang.String key)
          String of unlimited length.
 int getType(java.lang.String key)
          Returns type of value.
 org.w3c.dom.Document getXML(java.lang.String key)
           
 boolean isSettable(java.lang.String property)
          Whether this PropertySet implementation allows values to be set (as opposed to read-only).
 void remove(java.lang.String key)
          Removes property.
 void setAsActualType(java.lang.String key, java.lang.Object value)
           
 void setBoolean(java.lang.String key, boolean value)
           
 void setData(java.lang.String key, byte[] value)
           
 void setDate(java.lang.String key, java.util.Date value)
           
 void setDouble(java.lang.String key, double value)
           
 void setInt(java.lang.String key, int value)
           
 void setLong(java.lang.String key, long value)
           
 void setObject(java.lang.String key, java.lang.Object value)
           
 void setProperties(java.lang.String key, java.util.Properties value)
           
 void setSchema(PropertySetSchema schema)
           
 void setString(java.lang.String key, java.lang.String value)
           
 void setText(java.lang.String key, java.lang.String value)
           
 void setXML(java.lang.String key, org.w3c.dom.Document value)
           
 boolean supportsType(int type)
          Whether this PropertySet implementation allows the type specified to be stored or retrieved.
 boolean supportsTypes()
          Whether this PropertySet implementation supports types when storing values (i.e.
 

Field Detail

BOOLEAN

public static final int BOOLEAN
Value-type boolean

INT

public static final int INT
Value-type int

LONG

public static final int LONG
Value-type long

DOUBLE

public static final int DOUBLE
Value-type double

STRING

public static final int STRING
Value-type String (max length 255)

TEXT

public static final int TEXT
Value-type text (unlimited length String)

DATE

public static final int DATE
Value-type Date

OBJECT

public static final int OBJECT
Value-type serializable Object

XML

public static final int XML
Value-type XML Document

DATA

public static final int DATA
Value-type byte[]

PROPERTIES

public static final int PROPERTIES
Value-type Properties
Method Detail

getBoolean

public boolean getBoolean(java.lang.String key)
                   throws PropertyException

setBoolean

public void setBoolean(java.lang.String key,
                       boolean value)
                throws PropertyException

getInt

public int getInt(java.lang.String key)
           throws PropertyException

setInt

public void setInt(java.lang.String key,
                   int value)
            throws PropertyException

getLong

public long getLong(java.lang.String key)
             throws PropertyException

setLong

public void setLong(java.lang.String key,
                    long value)
             throws PropertyException

getDouble

public double getDouble(java.lang.String key)
                 throws PropertyException

setDouble

public void setDouble(java.lang.String key,
                      double value)
               throws PropertyException

getString

public java.lang.String getString(java.lang.String key)
                           throws PropertyException
String of maximum 255 chars.

setString

public void setString(java.lang.String key,
                      java.lang.String value)
               throws PropertyException

getText

public java.lang.String getText(java.lang.String key)
                         throws PropertyException
String of unlimited length.

setText

public void setText(java.lang.String key,
                    java.lang.String value)
             throws PropertyException

getDate

public java.util.Date getDate(java.lang.String key)
                       throws PropertyException

setDate

public void setDate(java.lang.String key,
                    java.util.Date value)
             throws PropertyException

getObject

public java.lang.Object getObject(java.lang.String key)
                           throws PropertyException

setObject

public void setObject(java.lang.String key,
                      java.lang.Object value)
               throws PropertyException

getXML

public org.w3c.dom.Document getXML(java.lang.String key)
                            throws PropertyException

setXML

public void setXML(java.lang.String key,
                   org.w3c.dom.Document value)
            throws PropertyException

getData

public byte[] getData(java.lang.String key)
               throws PropertyException

setData

public void setData(java.lang.String key,
                    byte[] value)
             throws PropertyException

setAsActualType

public void setAsActualType(java.lang.String key,
                            java.lang.Object value)
                     throws PropertyException

getProperties

public java.util.Properties getProperties(java.lang.String key)
                                   throws PropertyException

setProperties

public void setProperties(java.lang.String key,
                          java.util.Properties value)
                   throws PropertyException

setSchema

public void setSchema(PropertySetSchema schema)
               throws PropertyException

getSchema

public PropertySetSchema getSchema()
                            throws PropertyException

exists

public boolean exists(java.lang.String key)
               throws PropertyException
Determine if property exists.

remove

public void remove(java.lang.String key)
            throws PropertyException
Removes property.

getType

public int getType(java.lang.String key)
            throws PropertyException
Returns type of value.
Returns:
Type of value. See static class variables.

getKeys

public java.util.Collection getKeys()
                             throws PropertyException
List all keys.
Returns:
Unmodifiable Collection of Strings.

getKeys

public java.util.Collection getKeys(int type)
                             throws PropertyException
List all keys of certain type.
Parameters:
type - Type to list. See static class variables. If null, then all types shall be returned.
Returns:
Unmodifiable Collection of Strings.

getKeys

public java.util.Collection getKeys(java.lang.String prefix)
                             throws PropertyException
List all keys starting with supplied prefix.
Parameters:
prefix - String that keys must start with. If null, than all keys shall be returned.
Returns:
Unmodifiable Collection of Strings.

getKeys

public java.util.Collection getKeys(java.lang.String prefix,
                                    int type)
                             throws PropertyException
List all keys starting with supplied prefix of certain type. See statics.
Parameters:
prefix - String that keys must start with. If null, than all keys shall be returned.
type - Type to list. See static class variables. If null, then all types shall be returned.
Returns:
Unmodifiable Collection of Strings.

supportsTypes

public boolean supportsTypes()
Whether this PropertySet implementation supports types when storing values (i.e. the type of data is stored as well as the actual value).

supportsType

public boolean supportsType(int type)
Whether this PropertySet implementation allows the type specified to be stored or retrieved.

isSettable

public boolean isSettable(java.lang.String property)
Whether this PropertySet implementation allows values to be set (as opposed to read-only).

See www.opensymphony.com for more information.