org.mmbase.bridge.util
Class FieldWrapper

java.lang.Object
  extended by org.mmbase.bridge.util.FieldWrapper
All Implemented Interfaces:
Comparable<Field>, Descriptor, Field
Direct Known Subclasses:
BasicField, VirtualNodeManagerField

public class FieldWrapper
extends Object
implements Field

Wraps another Field (and makes it unmodifiable). You can use this if you want to implement Field, and want to base that implementation on a existing Field instance. To implement a modifiable field, you need to override the setters too.

Since:
MMBase-1.8.1
Version:
$Id: FieldWrapper.java 41943 2010-04-16 17:18:19Z michiel $
Author:
Michiel Meeuwissen

Field Summary
protected  Field field
           
 
Fields inherited from interface org.mmbase.bridge.Field
STATE_PERSISTENT, STATE_SYSTEM, STATE_SYSTEM_VIRTUAL, STATE_UNKNOWN, STATE_VIRTUAL, TYPE_BINARY, TYPE_BOOLEAN, TYPE_BYTE, TYPE_DATETIME, TYPE_DECIMAL, TYPE_DOUBLE, TYPE_FLOAT, TYPE_INTEGER, TYPE_LIST, TYPE_LONG, TYPE_NODE, TYPE_STRING, TYPE_UNKNOWN, TYPE_XML
 
Constructor Summary
FieldWrapper(Field field)
           
 
Method Summary
 int compareTo(Field f)
           
 DataType<?> getDataType()
          Returns the data type this field contains.
 String getDescription()
          Returns the description of this object for the default locale.
 String getDescription(Locale locale)
          Returns the description of this object.
 int getEditPosition()
          Retrieve the position of the field when editing.
 Field getField()
           
 String getGUIName()
          Returns the GUI name for this object.
 String getGUIName(Locale locale)
          Returns the GUI name for this object in a specified preferred language.
 String getGUIType()
          Returns the GUI name for the data type this field contains.
 int getListItemType()
          If the type of this field is TYPE_LIST, this method returns the MMBase base type for the list elements.
 int getListPosition()
          Retrieve the position of the field when listing.
 LocalizedString getLocalizedDescription()
          Returns the set of (localized) descriptions of this object.
 LocalizedString getLocalizedGUIName()
          Returns the set of (localized) gui names of this object.
 int getMaxLength()
          Returns the maximum length of data this field can contain.
 String getName()
          Returns the name or 'key' of this object, or null if not applicable.
 NodeManager getNodeManager()
          Returns the node manager this field belongs to.
 int getSearchPosition()
          Retrieve the position of the field when searching.
 int getState()
          Returns this field's state identifier (Field.STATE_VIRTUAL, Field.STATE_PERSISTENT, Field.STATE_SYSTEM or Field.STATE_SYSTEM_VIRTUAL, in errorneous sitations it may return Field.STATE_UNKNOWN)
 int getStoragePosition()
          Retrieve the position of the field in the database table.
 int getType()
          Returns the identifier for the MMBase base type for this field.
 boolean hasIndex()
          Returns whether this field is a key field, meaning that the storage layer should define an index for it, allowing optimization with search and sort actions.
 boolean isReadOnly()
          Returns whether a field is 'read only' - that is, a user cannot edit it.
 boolean isRequired()
          Returns whether this field is required (should have content).
 boolean isUnique()
          Returns whether this field is part of a unique key (a set of fields whose combined content should occur only once).
 boolean isVirtual()
          A field's state is 'virtual' if it is not persistent in storage.
 void setDescription(String description)
          Sets the description of this object for the default locale.
 void setDescription(String description, Locale locale)
          Sets the description of this object.
 void setGUIName(String g)
          Sets the GUI name of this object for the default locale.
 void setGUIName(String g, Locale locale)
          Sets the GUI name of this object.
 String toString()
           
 Collection<String> validate(Object value)
          Checks whether a given value is valid for this field.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

field

protected final Field field
Constructor Detail

FieldWrapper

public FieldWrapper(Field field)
Method Detail

getNodeManager

public NodeManager getNodeManager()
Description copied from interface: Field
Returns the node manager this field belongs to.

Specified by:
getNodeManager in interface Field
Returns:
the node manager this field belongs to

getState

public int getState()
Description copied from interface: Field
Returns this field's state identifier (Field.STATE_VIRTUAL, Field.STATE_PERSISTENT, Field.STATE_SYSTEM or Field.STATE_SYSTEM_VIRTUAL, in errorneous sitations it may return Field.STATE_UNKNOWN)

Specified by:
getState in interface Field
Returns:
an int which identifies the state of this field
See Also:
Field.isReadOnly();

getDataType

public DataType<?> getDataType()
Description copied from interface: Field
Returns the data type this field contains.

Specified by:
getDataType in interface Field
Returns:
a DataType object describing the constraints on this field.

isUnique

public boolean isUnique()
Description copied from interface: Field
Returns whether this field is part of a unique key (a set of fields whose combined content should occur only once). Note that MMBase lets the storage layer handle this. If your storage implementation or configuration does not support this the uniqueness may not be enforced.

Specified by:
isUnique in interface Field
Returns:
true if the field is part of a unique key

hasIndex

public boolean hasIndex()
Description copied from interface: Field
Returns whether this field is a key field, meaning that the storage layer should define an index for it, allowing optimization with search and sort actions. Note that MMBase lets the storage layer decide whether an index is actually defined. Some implementations or configurations may not do this. Note: Currently, this method only returns true if the field is the primary key (number field) or a Node field.

Specified by:
hasIndex in interface Field
Returns:
true if the field has a key defined

getType

public int getType()
Description copied from interface: Field
Returns the identifier for the MMBase base type for this field. This represents one of field type constants. This basic type determines how data is stored in MMBase. Note that it is possible that the datatype for a field (used for validation and in/out put) can be of a different basic type than how it is stored in the database. This shoudl not occur often, but is possible in some cases, such as when you use older clod models (which used INTEGER fields for dates). In general this should not prove a [problem - however you shoudl not assumeto know the classtype iof data of a field based on this method. To acquire the datatype's type, use getDataType.getBaseType() instead.

Specified by:
getType in interface Field
Returns:
an int which identifies the base type

getListItemType

public int getListItemType()
Description copied from interface: Field
If the type of this field is TYPE_LIST, this method returns the MMBase base type for the list elements. This represents one of field type constants. This basic type determines how data is stored in MMBase. For any field types other that TYPE_LIST, this method returns TYPE_UNKNOWN.

Specified by:
getListItemType in interface Field
Returns:
an int which identifies the base type

getSearchPosition

public int getSearchPosition()
Description copied from interface: Field
Retrieve the position of the field when searching. A value of -1 indicates the field is unavailable during search.

Specified by:
getSearchPosition in interface Field
Returns:
position of the field when searching

getListPosition

public int getListPosition()
Description copied from interface: Field
Retrieve the position of the field when listing. A value of -1 indicates the field is unavailable in a list.

Specified by:
getListPosition in interface Field
Returns:
position of the field when listing

getEditPosition

public int getEditPosition()
Description copied from interface: Field
Retrieve the position of the field when editing. A value of -1 indicates the field cannot be edited.

Specified by:
getEditPosition in interface Field
Returns:
position of the field when editing

getStoragePosition

public int getStoragePosition()
Description copied from interface: Field
Retrieve the position of the field in the database table.

Specified by:
getStoragePosition in interface Field
Returns:
position in the database table

getGUIType

public String getGUIType()
Description copied from interface: Field
Returns the GUI name for the data type this field contains.

Specified by:
getGUIType in interface Field
Returns:
the GUI name
See Also:
Field.getDataType()

isRequired

public boolean isRequired()
Description copied from interface: Field
Returns whether this field is required (should have content). Note that MMBase does not generally enforce required fields to be filled - If not provided, a default value (generally an empty string or the integer value -1) is filled in by the system. As such, isRequired will mostly be used as an indicator for (generic) editors.

Specified by:
isRequired in interface Field
Returns:
true if the field is required

getMaxLength

public int getMaxLength()
Description copied from interface: Field
Returns the maximum length of data this field can contain. For example if a field contains characters the size indicates the maximum number of characters it can contain. If the field is a numeric field (such as an integer), the result is -1. For a 'decimal' type though, this returns the same as the precision of the associated datatype.

Specified by:
getMaxLength in interface Field
Returns:
the maximum length of data this field can contain

validate

public Collection<String> validate(Object value)
Description copied from interface: Field
Checks whether a given value is valid for this field.

Specified by:
validate in interface Field
Parameters:
value - value to validate
Returns:
Collection of error-strings (describing the problem) in the current locale, or an empty collection if the value is ok.

isVirtual

public boolean isVirtual()
Description copied from interface: Field
A field's state is 'virtual' if it is not persistent in storage.

Specified by:
isVirtual in interface Field
Returns:
true when a field is virtual

isReadOnly

public boolean isReadOnly()
Description copied from interface: Field
Returns whether a field is 'read only' - that is, a user cannot edit it. In general, fields with state SYSTEM or SYSTEM_VIRTUAL are defined as read only, while others are not. It is possible to override this behaviour per field.

Specified by:
isReadOnly in interface Field
Returns:
true when a field is read only

getName

public String getName()
Description copied from interface: Descriptor
Returns the name or 'key' of this object, or null if not applicable.

Specified by:
getName in interface Descriptor
Returns:
the name as a String

getGUIName

public String getGUIName()
Description copied from interface: Descriptor
Returns the GUI name for this object.

Specified by:
getGUIName in interface Descriptor
Returns:
the GUI name for this object

getGUIName

public String getGUIName(Locale locale)
Description copied from interface: Descriptor
Returns the GUI name for this object in a specified preferred language.

Specified by:
getGUIName in interface Descriptor
Parameters:
locale - the locale that determines the language for the GUI name
Returns:
the GUI name for this object

getLocalizedGUIName

public LocalizedString getLocalizedGUIName()
Description copied from interface: Descriptor
Returns the set of (localized) gui names of this object.

Specified by:
getLocalizedGUIName in interface Descriptor
Returns:
the description as a LocalizedString

setGUIName

public void setGUIName(String g,
                       Locale locale)
Description copied from interface: Descriptor
Sets the GUI name of this object.

Specified by:
setGUIName in interface Descriptor
Parameters:
g - the description as a String
locale - The locale for which this is valid, or null for the default locale.

setGUIName

public void setGUIName(String g)
Description copied from interface: Descriptor
Sets the GUI name of this object for the default locale.

Specified by:
setGUIName in interface Descriptor
Parameters:
g - the description as a String

getLocalizedDescription

public LocalizedString getLocalizedDescription()
Description copied from interface: Descriptor
Returns the set of (localized) descriptions of this object.

Specified by:
getLocalizedDescription in interface Descriptor
Returns:
the description as a LocalizedString

getDescription

public String getDescription(Locale locale)
Description copied from interface: Descriptor
Returns the description of this object.

Specified by:
getDescription in interface Descriptor
Parameters:
locale - The locale for which this must be returned, or null for a default locale. If no fitting description for the given locale is available, getName() can be returned.
Returns:
the description as a String

getDescription

public String getDescription()
Description copied from interface: Descriptor
Returns the description of this object for the default locale.

Specified by:
getDescription in interface Descriptor
Returns:
the description as a String

setDescription

public void setDescription(String description,
                           Locale locale)
Description copied from interface: Descriptor
Sets the description of this object.

Specified by:
setDescription in interface Descriptor
Parameters:
description - the description as a String
locale - The locale for which this is valid, or null for a default locale.

setDescription

public void setDescription(String description)
Description copied from interface: Descriptor
Sets the description of this object for the default locale.

Specified by:
setDescription in interface Descriptor
Parameters:
description - the description as a String

compareTo

public int compareTo(Field f)
Specified by:
compareTo in interface Comparable<Field>

getField

public Field getField()

toString

public String toString()
Overrides:
toString in class Object


MMBase 2.0-SNAPSHOT - null