com.iplanet.jato.model
Class DefaultModel

java.lang.Object
  |
  +--com.iplanet.jato.model.DefaultModel
All Implemented Interfaces:
ContextualModel, DatasetModel, Model, java.io.Serializable
Direct Known Subclasses:
ResultSetModelBase

public class DefaultModel
extends java.lang.Object
implements ContextualModel, DatasetModel, java.io.Serializable

A simple, in-memory Model implementation which supports multiple rows of arbitrary data. If display fields are not bound to another type of model, they should normally be bound to a DefaultModel instance. Each container view has an implicit DefaultModel instance that should be used for this purpose.

Version:
JATO/1.2.2 $Id: DefaultModel.java,v 1.22 2002/03/16 03:26:30 todd Exp $
See Also:
Serialized Form

Inner Class Summary
protected static class DefaultModel.Context
          Encapsulates all the state for a context.
protected static class DefaultModel.RowValueArrayList
          An array list for storing rows of values.
 
Field Summary
static java.lang.String DEFAULT_CONTEXT_NAME
           
static int UNDEFINED_ROW_INDEX
           
 
Constructor Summary
DefaultModel()
          Construct an empty model
DefaultModel(java.lang.String name)
          Construct an empty model with the given name
 
Method Summary
protected  DefaultModel.Context addContext(java.lang.String name)
          Adds an additional named context to this model
 void appendRow()
          Append an empty row of data
 void beforeFirst()
          Moves the internal location iterator to a special position such that a call to next() will position the location at the first row (if available).
protected  boolean checkRowIndex()
          Check that the current row index is within the bounds of the model's data.
 void clear()
          Clears all values (from all rows) in this model
protected  void clearModelData()
          Remove all existing model data and reset to the "before first" state
protected  java.util.Map createValueMap()
          Allocates a new map object to store row data.
 void dumpValues(java.io.PrintStream out)
          This method can be used during debugging to print all values in this model to the specified stream.
 void dumpValues(java.io.PrintWriter out)
          This method can be used during debugging to print all values in this model to the specified stream.
protected  void ensureRow(int row)
          Ensures that the specified row exists in the model's data store.
 boolean first()
          Moves the internal location iterator to the first available row.
protected  DefaultModel.Context getContext(java.lang.String name)
          Returns the named context object
 java.lang.String[] getContextNames()
          Returns the full set of context names available in this model
protected  DefaultModel.Context getCurrentContext()
          Returns the currently selected context object
 java.lang.String getCurrentContextName()
          Returns the currently active context name
 java.lang.Object getDefaultValue(java.lang.String name)
          Returns a named value from this model
protected  java.util.Map getDefaultValueMap()
          Returns the default value map
 java.lang.Object[] getDefaultValues(java.lang.String name)
          Returns a named set of values from this model
 int getLocation()
          Returns the current row index
 int getLocationOffset()
          Returns the offset of the first row of data
 java.lang.String getName()
          Returns the logical instance name of this model.
 int getNumRows()
          Returns the curren number of rows in this model
 int getRowIndex()
          Returns the current row index, or location
protected  java.util.List getRowList()
          Returns the internal list used to store rows of data.
 int getSize()
          Return the number of available rows
 java.lang.Object getValue(java.lang.String name)
          Returns a named value from this model
protected  java.util.Map getValueMap()
          Returns the value map for the current row.
protected  java.util.Map getValueMap(int row)
          Returns the value map for the specified row.
 java.lang.Object[] getValues(java.lang.String name)
          Returns a named set of values from this model
 boolean hasValue(java.lang.String name)
          Returns whether a value exists for the specified name
protected  void initializeDefaultContext()
          Initializes the default context.
 void insertRow()
          Insert an empty row of data at the current location
 boolean isDefaultContext()
          Checks if the current context is the default context
 boolean isUseDefaultValues()
          Indicates whether this model instance will use default values for empty fields.
 boolean last()
          Moves the internal location iterator to the last available row.
 boolean next()
          Moves the internal location iterator to the next available row
 boolean previous()
          Moves the internal location iterator to the previous available row
protected  void removeContext(java.lang.String name)
          Removes the named context from this model
 void selectContext(java.lang.String name)
          Change the current context to the specified context
 void selectDefaultContext()
          Change the current context to the default context
 void setDefaultValue(java.lang.String name, java.lang.Object value)
          Sets a named value in this model.
 void setDefaultValues(java.lang.String name, java.lang.Object[] value)
          Sets a named set of values in this model
 void setLocation(int location)
          Sets the current row index
 void setName(java.lang.String value)
          Sets the logical name of this model
 void setNumRows(int value)
          Sets the current number of rows
 void setRowIndex(int value)
          Sets the current row index, or location
protected  void setRowList(java.util.List value)
          Sets the internal list used to store rows of data.
 void setSize(int value)
          Sets the number of available rows.
 void setUseDefaultValues(boolean value)
          Sets whether this model instance will use default values for empty fields.
 void setValue(java.lang.String name, java.lang.Object value)
          Sets a named value in this model.
 void setValues(java.lang.String name, java.lang.Object[] value)
          Sets a named set of values in this model
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNDEFINED_ROW_INDEX

public static final int UNDEFINED_ROW_INDEX

DEFAULT_CONTEXT_NAME

public static final java.lang.String DEFAULT_CONTEXT_NAME
Constructor Detail

DefaultModel

public DefaultModel()
Construct an empty model

DefaultModel

public DefaultModel(java.lang.String name)
Construct an empty model with the given name
Method Detail

getName

public java.lang.String getName()
Returns the logical instance name of this model. This name can be any arbitrary string. This name may only be useful at certain times; for example, the ModelManager may assign a name to a model based on user request.
Specified by:
getName in interface Model
Returns:
The opaque, arbitrary name of this model

setName

public void setName(java.lang.String value)
Sets the logical name of this model
Specified by:
setName in interface Model
Parameters:
name - The new name of this model

isUseDefaultValues

public boolean isUseDefaultValues()
Indicates whether this model instance will use default values for empty fields. Default values are the first values set for a given field.
Returns:
True if a default value will be used for a field when its value is null

setUseDefaultValues

public void setUseDefaultValues(boolean value)
Sets whether this model instance will use default values for empty fields. Default values are the first values set for a given field.
Parameters:
value - Set to true if a default value should be used for a field when its value is null

clear

public void clear()
Clears all values (from all rows) in this model

clearModelData

protected final void clearModelData()
Remove all existing model data and reset to the "before first" state

dumpValues

public void dumpValues(java.io.PrintStream out)
This method can be used during debugging to print all values in this model to the specified stream.
Parameters:
out - The stream to which to write the debug value information

dumpValues

public void dumpValues(java.io.PrintWriter out)
This method can be used during debugging to print all values in this model to the specified stream.
Parameters:
out - The stream to which to write the debug value information

getSize

public int getSize()
            throws ModelControlException
Return the number of available rows
Specified by:
getSize in interface DatasetModel
Returns:
The number of available rows
Throws:
ModelControlException - Thrown if an error occurrs determining the number of rows

setSize

public void setSize(int value)
             throws ModelControlException
Sets the number of available rows. Values on newly allocated rows will be null.
Specified by:
setSize in interface DatasetModel
Throws:
ModelControlException - Thrown if an error occurrs setting the number of rows

getLocationOffset

public int getLocationOffset()
                      throws ModelControlException
Returns the offset of the first row of data
Specified by:
getLocationOffset in interface DatasetModel
Returns:
This method always returns zero (0) in this implementation

getLocation

public int getLocation()
                throws ModelControlException
Returns the current row index
Specified by:
getLocation in interface DatasetModel
Throws:
ModelControlException - Thrown if an error occurrs determining the current location

setLocation

public void setLocation(int location)
                 throws ModelControlException
Sets the current row index
Specified by:
setLocation in interface DatasetModel
Throws:
ModelControlException - Thrown if an error occurrs setting the current location

beforeFirst

public void beforeFirst()
                 throws ModelControlException
Moves the internal location iterator to a special position such that a call to next() will position the location at the first row (if available). Normally, a call to getLocation() after this method is called should return negative one (-1).
Specified by:
beforeFirst in interface DatasetModel
Throws:
ModelControlException - Thrown if an error occurrs setting the location to this special position

first

public boolean first()
              throws ModelControlException
Moves the internal location iterator to the first available row. Normally, a call to getLocation() after this method is called should return zero (0).
Specified by:
first in interface DatasetModel
Returns:
True if now positioned at a valid row, false if there is no available row
Throws:
ModelControlException - Thrown if an error occurrs moving to the first dataset

last

public boolean last()
             throws ModelControlException
Moves the internal location iterator to the last available row. Normally, a call to getLocation() after this method is called should return getSize()-1.
Specified by:
last in interface DatasetModel
Returns:
True if now positioned at a valid row, false if there is no available row
Throws:
ModelControlException - Thrown if an error occurrs moving to the last row

next

public boolean next()
             throws ModelControlException
Moves the internal location iterator to the next available row
Specified by:
next in interface DatasetModel
Returns:
True if now positioned at a valid row, false if there are no more rows
Throws:
ModelControlException - Thrown if an error occurrs positioning at the next row

previous

public boolean previous()
                 throws ModelControlException
Moves the internal location iterator to the previous available row
Specified by:
previous in interface DatasetModel
Returns:
True if now positioned at a valid row, false if there are no more rows
Throws:
ModelControlException - Thrown if an error occurrs positioning at the previous row

getNumRows

public int getNumRows()
Returns the curren number of rows in this model

setNumRows

public void setNumRows(int value)
Sets the current number of rows
Parameters:
value - The new number of rows this model should contain. If the value is greater than the current number of rows in the mode, the values of newly allocated rows are allocated to null. If the specified value is smaller than the number of current rows, the row data is truncated to the number specified.

getRowIndex

public int getRowIndex()
Returns the current row index, or location
See Also:
getLocation()

setRowIndex

public void setRowIndex(int value)
Sets the current row index, or location
See Also:
setLocation(int)

appendRow

public void appendRow()
Append an empty row of data

insertRow

public void insertRow()
Insert an empty row of data at the current location

checkRowIndex

protected boolean checkRowIndex()
Check that the current row index is within the bounds of the model's data. If the row index is invalid, it is repositioned to the appropriate location.
Returns:
True if the row index is valid, or false if it was repositioned

ensureRow

protected void ensureRow(int row)
Ensures that the specified row exists in the model's data store.
Parameters:
row - The index of the row up to which the data store will be initialized

getRowList

protected java.util.List getRowList()
Returns the internal list used to store rows of data. For internal use only.

setRowList

protected void setRowList(java.util.List value)
Sets the internal list used to store rows of data. For internal use only.

createValueMap

protected java.util.Map createValueMap()
Allocates a new map object to store row data. This method can be overridden to provide a special map type, though this would generally be a very rare necessity.

getValueMap

protected java.util.Map getValueMap()
Returns the value map for the current row.

getValueMap

protected java.util.Map getValueMap(int row)
Returns the value map for the specified row. If the model is in the "before first" state when this method is called, it automatically moves to the first (0th) row, creating it if necessary.

getDefaultValueMap

protected java.util.Map getDefaultValueMap()
Returns the default value map

getValue

public java.lang.Object getValue(java.lang.String name)
Returns a named value from this model
Specified by:
getValue in interface Model
Parameters:
name - The name of the value to return
Returns:
The specified value. If the model has multiple values for the specified name, the first value is returned. If there is no value for the specified name, this method returns null.

setValue

public void setValue(java.lang.String name,
                     java.lang.Object value)
Sets a named value in this model. This method overwrites any current value or values. If multiple values were present previously, they are all discarded.
Specified by:
setValue in interface Model
Parameters:
name - The name of the value to set
value - The value to set in this model

getValues

public java.lang.Object[] getValues(java.lang.String name)
Returns a named set of values from this model
Specified by:
getValues in interface Model
Parameters:
name - The name of the value set to return
Returns:
The specified set of values. If there is no value for the specified name, this method returns an array of zero length.

setValues

public void setValues(java.lang.String name,
                      java.lang.Object[] value)
Sets a named set of values in this model
Specified by:
setValues in interface Model
Parameters:
name - The name of the value set to set in the model
values - The set of values to set in this model

hasValue

public boolean hasValue(java.lang.String name)
Returns whether a value exists for the specified name
Parameters:
The - name of the value to test
Returns:
True if the named value is present

getDefaultValue

public java.lang.Object getDefaultValue(java.lang.String name)
Returns a named value from this model
Parameters:
name - The name of the value to return
Returns:
The specified value. If the model has multiple values for the specified name, the first value is returned. If there is no value for the specified name, this method returns null.

setDefaultValue

public void setDefaultValue(java.lang.String name,
                            java.lang.Object value)
Sets a named value in this model. This method overwrites any current value or values. If multiple values were present previously, they are all discarded.
Parameters:
name - The name of the value to set
value - The value to set in this model

getDefaultValues

public java.lang.Object[] getDefaultValues(java.lang.String name)
Returns a named set of values from this model
Parameters:
name - The name of the value set to return
Returns:
The specified set of values. If there is no value for the specified name, this method returns an array of zero length.

setDefaultValues

public void setDefaultValues(java.lang.String name,
                             java.lang.Object[] value)
Sets a named set of values in this model
Parameters:
name - The name of the value set to set in the model
values - The set of values to set in this model

getCurrentContextName

public java.lang.String getCurrentContextName()
Returns the currently active context name
Specified by:
getCurrentContextName in interface ContextualModel
Returns:
The current context name

getContextNames

public java.lang.String[] getContextNames()
Returns the full set of context names available in this model
Specified by:
getContextNames in interface ContextualModel

selectContext

public void selectContext(java.lang.String name)
                   throws InvalidContextException
Change the current context to the specified context
Specified by:
selectContext in interface ContextualModel
Following copied from interface: com.iplanet.jato.model.ContextualModel
Throws:
InvalidContextException - Thrown if the provided context name does not represent an available context

selectDefaultContext

public void selectDefaultContext()
                          throws InvalidContextException
Change the current context to the default context
Specified by:
selectDefaultContext in interface ContextualModel
Following copied from interface: com.iplanet.jato.model.ContextualModel
Throws:
InvalidContextException - Thrown if the provided context name does not represent an available context

isDefaultContext

public boolean isDefaultContext()
Checks if the current context is the default context
Specified by:
isDefaultContext in interface ContextualModel

initializeDefaultContext

protected void initializeDefaultContext()
Initializes the default context. For internal use only.

getCurrentContext

protected DefaultModel.Context getCurrentContext()
Returns the currently selected context object

addContext

protected DefaultModel.Context addContext(java.lang.String name)
Adds an additional named context to this model

getContext

protected DefaultModel.Context getContext(java.lang.String name)
Returns the named context object

removeContext

protected void removeContext(java.lang.String name)
Removes the named context from this model