2.17.2: 2011-06-17

net.sf.basedb.core
Class ExtendedProperty

java.lang.Object
  extended by net.sf.basedb.core.ExtendedProperty
All Implemented Interfaces:
ToTransferable<ExtendedPropertyInfo>
Direct Known Subclasses:
RawDataProperty

public class ExtendedProperty
extends Object
implements ToTransferable<ExtendedPropertyInfo>

Holds information about an extended property for a class.

Version:
2.0
Author:
Nicklas, Samuel
See Also:
ExtendableData

Field Summary
private  Formula.AverageMethod averageMethod
           
private  String column
           
private  String description
           
private  boolean insertable
           
private  int length
           
private  List<ExtendedPropertyLinker> linkers
           
private  String name
           
private  boolean nullable
           
private  String title
           
private  Type type
           
private  boolean updateable
           
private static Pattern valid
          A regexp checking for invalid characters.
 
Constructor Summary
ExtendedProperty(String name, String title, String description, String column, Type type, int length, boolean nullable, boolean insertable, boolean updateable, Formula.AverageMethod averageMethod, List<ExtendedPropertyLinker> linkers)
          Create a new extended property.
 
Method Summary
 Formula.AverageMethod getAverageMethod()
          Which method to use when calculating the average of a set of values.
 String getColumn()
          Get the database column of the extended property.
 String getDescription()
          Get a description of the extended property.
 int getLength()
          Get the maximum allowed length of the property value.
 String getName()
          Get the name of the extended property.
 String getTitle()
          Get the title of the extended property.
 Type getType()
          Get the type of the extended property.
 String getUrl(Object value)
          Create a link for this extended property.
 boolean isAveragable()
          If it makes sense to take the average of multiple values for this property or not.
 boolean isInsertable()
          Check if the value of this property should be inserted into the datbase when creating new items.
 boolean isNullable()
          Check if the property allows null values or not.
 boolean isUpdateable()
          Check if the value of this property should be updated in the database when an item is updated.
static boolean isValidName(String name)
          Check that the name only contains a-zA-Z0-9_ and starts with a letter or underscore.
 Object parseString(String value)
          Parse a string and return an object of the correct type for this property.
 Object parseString(String value, NumberFormat numberFormat)
          Deprecated. Use parseString(String, NumberFormat, boolean) instead
 Object parseString(String value, NumberFormat numberFormat, boolean nullIfException)
          Parse a string and return an object of the correct type for this property.
 ExtendedPropertyInfo toTransferable(ExtendedPropertyInfo info)
          Transfer the internal state to a transferable object.
 void validateValue(Object value)
          Check if an object is valid according to the specifications of this property.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

valid

private static final Pattern valid
A regexp checking for invalid characters.


name

private final String name

type

private final Type type

column

private final String column

title

private final String title

description

private final String description

length

private final int length

nullable

private final boolean nullable

insertable

private final boolean insertable

updateable

private final boolean updateable

averageMethod

private final Formula.AverageMethod averageMethod

linkers

private final List<ExtendedPropertyLinker> linkers
Constructor Detail

ExtendedProperty

ExtendedProperty(String name,
                 String title,
                 String description,
                 String column,
                 Type type,
                 int length,
                 boolean nullable,
                 boolean insertable,
                 boolean updateable,
                 Formula.AverageMethod averageMethod,
                 List<ExtendedPropertyLinker> linkers)
Create a new extended property. See the getter methods for a description of the parameters.

Method Detail

isValidName

public static boolean isValidName(String name)
Check that the name only contains a-zA-Z0-9_ and starts with a letter or underscore.

Parameters:
name - Name to check
Returns:
TRUE if valid, FALSE otherwise
Since:
2.4

getName

public String getName()
Get the name of the extended property. This is the name that is used in queries and for the name parameter of the getExtended/setExtended methods to get or set the value of the property of an Extendable item.

Returns:
A string with the name
See Also:
ExtendableData.getExtended, ExtendableData.setExtended

getTitle

public String getTitle()
Get the title of the extended property. The title is not used by the core but can be used by client applications for example to display a column header.

Returns:
A string with the title

getDescription

public String getDescription()
Get a description of the extended property. The description is not used by the core but can be used by client applications.

Returns:
A string with the description

getColumn

public String getColumn()
Get the database column of the extended property. This is the name of the column in the database which holds the value.

Returns:
a String

getType

public Type getType()
Get the type of the extended property. The value returned is one of the defined constants by the Type enumeration.

Returns:
a Type enumeration.

getLength

public int getLength()
Get the maximum allowed length of the property value. This is only useful if it a string property.

Returns:
The maximum allowed length

isNullable

public boolean isNullable()
Check if the property allows null values or not.

Returns:
TRUE if null values are allowed, FALSE otherwise

isInsertable

public boolean isInsertable()
Check if the value of this property should be inserted into the datbase when creating new items.

Returns:
TRUE if the value should be inserted, FALSE otherwise

isUpdateable

public boolean isUpdateable()
Check if the value of this property should be updated in the database when an item is updated.

Returns:
TRUE if the value should be updated, FALSE otherwise

isAveragable

public boolean isAveragable()
If it makes sense to take the average of multiple values for this property or not. For example, it doesn't make sense to average over position coordinates, but it does make sense to average over intensity values. By default all numerical values are averagable.

Returns:
TRUE if it makes sense to take the average, FALSE otherwise
See Also:
getAverageMethod()

getAverageMethod

public Formula.AverageMethod getAverageMethod()
Which method to use when calculating the average of a set of values. Prior to 2.4 only arithmetic mean was supported.

Returns:
The average method to use
Since:
2.4

parseString

public Object parseString(String value)
                   throws InvalidDataException
Parse a string and return an object of the correct type for this property.

Parameters:
value - The value to parse
Returns:
An object
Throws:
InvalidDataException - If the string cannot be converted to the correct type
See Also:
getType()

parseString

public Object parseString(String value,
                          NumberFormat numberFormat)
Deprecated. Use parseString(String, NumberFormat, boolean) instead

Parse a string and return an object of the correct type for this property. Numeric properties are parsed with the specified number format.

Parameters:
value - The value to parse
numberFormat - The number format, or null to use Double.valueOf
Returns:
An object
Throws:
InvalidDataException - If the string cannot be converted to the correct type
Since:
2.2
See Also:
getType()

parseString

public Object parseString(String value,
                          NumberFormat numberFormat,
                          boolean nullIfException)
Parse a string and return an object of the correct type for this property. Numeric properties are parsed with the specified number format. If the nullIfException parameter is TRUE null is returned if the string can't be parsed. Otherwise an exception is thrown.

Parameters:
value - The value to parse
numberFormat - The number format, or null to use Double.valueOf
nullIfException - TRUE to return null in case the string can't be parsed, FALSE to throw an exception
Returns:
An object or null
Throws:
InvalidDataException - If the string cannot be converted to the correct type and the nullIfException parameter is false
Since:
2.4
See Also:
getType()

validateValue

public void validateValue(Object value)
                   throws InvalidDataException
Check if an object is valid according to the specifications of this property. The checks include checking for null values if the property not isNullable(), check that the object is of the correct getType() and the maximum getLength() of a string.

Parameters:
value - The value to check
Throws:
InvalidDataException

getUrl

public String getUrl(Object value)
Create a link for this extended property. This method checks the linkers in the order they are defined. The first one to return a non-null value is the winner.

Parameters:
value - The value to link
Returns:
The URL, or null if no matching linker could be found

toTransferable

public ExtendedPropertyInfo toTransferable(ExtendedPropertyInfo info)
Description copied from interface: ToTransferable
Transfer the internal state to a transferable object. The method should return the same object that is passed in as an argument.

Specified by:
toTransferable in interface ToTransferable<ExtendedPropertyInfo>
Parameters:
info - The transferable object to use
Returns:
The transferable object with values set.

2.17.2: 2011-06-17