public interface

PropertySet

com.opensymphony.module.propertyset.PropertySet
Known Indirect Subclasses

Class Overview

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(String) .

Summary

Constants
int BOOLEAN Value-type boolean
int DATA Value-type byte[]
int DATE Value-type java.util.Date
int DOUBLE Value-type double
int INT Value-type int
int LONG Value-type long
int OBJECT Value-type serializable Object
int PROPERTIES Value-type java.util.Properties
int STRING Value-type String (max length 255)
int TEXT Value-type text (unlimited length String)
int XML Value-type XML org.w3c.dom.Document
Public Methods
boolean exists(String key)
Determine if property exists.
Object getAsActualType(String key)
boolean getBoolean(String key)
byte[] getData(String key)
Date getDate(String key)
double getDouble(String key)
int getInt(String key)
Collection getKeys()
List all keys.
Collection getKeys(int type)
List all keys of certain type.
Collection getKeys(String prefix)
List all keys starting with supplied prefix.
Collection getKeys(String prefix, int type)
List all keys starting with supplied prefix of certain type.
long getLong(String key)
Object getObject(String key)
Properties getProperties(String key)
PropertySetSchema getSchema()
String getString(String key)
String of maximum 255 chars.
String getText(String key)
String of unlimited length.
int getType(String key)
Returns type of value.
Document getXML(String key)
void init(Map config, Map args)
boolean isSettable(String property)
Whether this PropertySet implementation allows values to be set (as opposed to read-only).
void remove()
Remove the propertyset and all it associated keys.
void remove(String key)
Removes property.
void setAsActualType(String key, Object value)
void setBoolean(String key, boolean value)
void setData(String key, byte[] value)
void setDate(String key, Date value)
void setDouble(String key, double value)
void setInt(String key, int value)
void setLong(String key, long value)
void setObject(String key, Object value)
void setProperties(String key, Properties value)
void setSchema(PropertySetSchema schema)
void setString(String key, String value)
void setText(String key, String value)
void setXML(String key, 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.

Constants

public static final int BOOLEAN

Value-type boolean

Constant Value: 1 (0x00000001)

public static final int DATA

Value-type byte[]

Constant Value: 10 (0x0000000a)

public static final int DATE

Value-type java.util.Date

Constant Value: 7 (0x00000007)

public static final int DOUBLE

Value-type double

Constant Value: 4 (0x00000004)

public static final int INT

Value-type int

Constant Value: 2 (0x00000002)

public static final int LONG

Value-type long

Constant Value: 3 (0x00000003)

public static final int OBJECT

Value-type serializable Object

Constant Value: 8 (0x00000008)

public static final int PROPERTIES

Value-type java.util.Properties

Constant Value: 11 (0x0000000b)

public static final int STRING

Value-type String (max length 255)

Constant Value: 5 (0x00000005)

public static final int TEXT

Value-type text (unlimited length String)

Constant Value: 6 (0x00000006)

public static final int XML

Value-type XML org.w3c.dom.Document

Constant Value: 9 (0x00000009)

Public Methods

public boolean exists (String key)

Determine if property exists.

public Object getAsActualType (String key)

public boolean getBoolean (String key)

public byte[] getData (String key)

public Date getDate (String key)

public double getDouble (String key)

public int getInt (String key)

public Collection getKeys ()

List all keys.

Returns

public Collection getKeys (int type)

List all keys of certain type.

Parameters
type Type to list. See static class variables. If null, then all types shall be returned.
Returns

public Collection getKeys (String prefix)

List all keys starting with supplied prefix.

Parameters
prefix String that keys must start with. If null, than all keys shall be returned.
Returns

public Collection getKeys (String prefix, int type)

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

public long getLong (String key)

public Object getObject (String key)

public Properties getProperties (String key)

public PropertySetSchema getSchema ()

public String getString (String key)

String of maximum 255 chars.

public String getText (String key)

String of unlimited length.

public int getType (String key)

Returns type of value.

Returns
  • Type of value. See static class variables.

public Document getXML (String key)

public void init (Map config, Map args)

public boolean isSettable (String property)

Whether this PropertySet implementation allows values to be set (as opposed to read-only).

public void remove ()

Remove the propertyset and all it associated keys.

Throws
PropertyException if there is an error removing the propertyset.

public void remove (String key)

Removes property.

public void setAsActualType (String key, Object value)

public void setBoolean (String key, boolean value)

public void setData (String key, byte[] value)

public void setDate (String key, Date value)

public void setDouble (String key, double value)

public void setInt (String key, int value)

public void setLong (String key, long value)

public void setObject (String key, Object value)

public void setProperties (String key, Properties value)

public void setSchema (PropertySetSchema schema)

public void setString (String key, String value)

public void setText (String key, String value)

public void setXML (String key, Document value)

public boolean supportsType (int type)

Whether this PropertySet implementation allows the type specified to be stored or retrieved.

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).