edu.ksu.cis.projects.bogor.module.value
Class DefaultValueFactory

java.lang.Object
  extended by edu.ksu.cis.projects.bogor.module.event.AbstractEventProvider
      extended by edu.ksu.cis.projects.bogor.module.value.event.AbstractValueEventProvider
          extended by edu.ksu.cis.projects.bogor.module.value.DefaultValueFactory
All Implemented Interfaces:
ISelfDescribingModule, IEventProvider, IModule, IValueFactory, IValueEventProvider, Disposable

public class DefaultValueFactory
extends AbstractValueEventProvider
implements IValueFactory, ISelfDescribingModule

The default implementation of IValueFactory.

Version:
CVS $Revision: 1.14 $ $Date: 2005/05/26 18:23:14 $
Author:
Robby

Field Summary
protected  IBogorConfiguration bc
          Holds the Bogor configuration.
protected static String defaultValueFunction
           
protected  int elementsInRegion
           
protected  DefaultNullValue nullValue
          Holds the unique null value.
protected  SymbolTable symbolTable
          Holds the symbol table.
protected  TypeFactory tf
          Holds the type factory.
protected  IValueFactory vf
          Holds the value factory (for delegation).
 
Fields inherited from class edu.ksu.cis.projects.bogor.module.value.event.AbstractValueEventProvider
dvenBackward, dvenForward
 
Fields inherited from class edu.ksu.cis.projects.bogor.module.event.AbstractEventProvider
isForward, s, threadId
 
Constructor Summary
DefaultValueFactory()
          Default constructor.
 
Method Summary
 IMessageStore connect(IBogorConfiguration bc)
          Connects this modules to other modules.
 IValue createDefaultValue(Type type)
          Creates a default value of a type.
 void dispose()
          Remove references.
 String getCopyrightNotice()
          Returns the copyright notice for this module.
 Pair<Domain,Boolean> getOptionDomain(String id)
           
 Collection<Triple<String,Boolean,OptionScope>> getOptionIds()
           
 int getReferenceIdSeed()
          Gets the reference id seed.
 Collection<String> getSuggestedValues(String id, IBogorConfiguration bc, SymbolTable st)
           
 Type getType(IValue value)
          Gets the type of a value.
 IArrayValue newArrayValue(ArrayType arrayType, Type[] fieldTypes, int[] lengths)
          Creates an array value.
 IDoubleValue newDoubleValue(double d)
          Creates a double value.
 IExpASTValue newExpASTValue(Exp exp)
          Creates an exp AST value.
 IFloatValue newFloatValue(float f)
          Creates a float value.
 IIntValue newIntValue(int integer)
          Creates an integer value.
 IIntValue newIntValue(Type type, int integer)
          Creates an integer value.
 ILockValue newLockValue()
          Creates a new lock value.
 ILongValue newLongValue(long l)
          Creates a long value.
 ILongValue newLongValue(LongType type, long l)
          Creates an integer value.
 INullValue newNullValue()
          Creates a new null value.
 IRecordValue newRecordValue(RecordType recordType)
          Creates a new record value.
 int newReferenceId()
          Generates a new reference id.
 IStringValue newStringValue(String s)
          Creates a string value.
 IValueArray newUniformValueArray(IValue[] values)
          Creates a value array from an array of values.
 IValueArray newVariedValueArray(IValue[] values)
          Creates a value array from an array of values.
protected  IValue recurseNewArrayValue(ArrayType arrayType, Type[] fieldTypes, int[] lengths, int i)
          Creates an array value given for each dimension's length.
 IMessageStore setOptions(String key, Properties configuration)
          Sets the options for this module.
 void setReferenceIdSeed(int newSeed)
          Sets the reference id seed.
 void validate(IValue value)
          Validates a value.
 void validate(IValueArray valueArray)
          Validates a value array.
 boolean validate(String id, String value, IBogorConfiguration bc, SymbolTable st, Collection<FileMessage> errors)
          Checks whether the value of a configuration option is legal.
 
Methods inherited from class edu.ksu.cis.projects.bogor.module.value.event.AbstractValueEventProvider
getNotifier, getNotifier
 
Methods inherited from class edu.ksu.cis.projects.bogor.module.event.AbstractEventProvider
backward, forward, getState, getThreadId, isBackward, isForward, removeContext, setContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface edu.ksu.cis.projects.bogor.module.value.event.IValueEventProvider
getNotifier, getNotifier
 
Methods inherited from interface edu.ksu.cis.projects.bogor.module.event.IEventProvider
backward, forward, getState, getThreadId, isBackward, isForward, removeContext, setContext
 

Field Detail

defaultValueFunction

protected static final String defaultValueFunction
See Also:
Constant Field Values

nullValue

protected DefaultNullValue nullValue
Holds the unique null value. Non-null when connected.


symbolTable

protected SymbolTable symbolTable
Holds the symbol table. Non-null when connected.


tf

protected TypeFactory tf
Holds the type factory. Non-null when connected.


vf

protected IValueFactory vf
Holds the value factory (for delegation).


bc

protected IBogorConfiguration bc
Holds the Bogor configuration.


elementsInRegion

protected int elementsInRegion
Constructor Detail

DefaultValueFactory

public DefaultValueFactory()
Default constructor.

Method Detail

getCopyrightNotice

public String getCopyrightNotice()
Description copied from interface: IModule
Returns the copyright notice for this module.

Specified by:
getCopyrightNotice in interface IModule
Returns:
The copyright notice for this module. Returns null if no additional notice is necessary.

setOptions

public IMessageStore setOptions(String key,
                                Properties configuration)
Description copied from interface: IModule
Sets the options for this module.

Specified by:
setOptions in interface IModule
Parameters:
key - The key (prefix) for this module options. Must be non-null. The key is used for module specific options.
configuration - The options for all modules. Must be non-null.

setReferenceIdSeed

public void setReferenceIdSeed(int newSeed)
Description copied from interface: IValueFactory
Sets the reference id seed.

Specified by:
setReferenceIdSeed in interface IValueFactory
Parameters:
newSeed - The new seed.

getReferenceIdSeed

public int getReferenceIdSeed()
Description copied from interface: IValueFactory
Gets the reference id seed.

Specified by:
getReferenceIdSeed in interface IValueFactory
Returns:
The reference id seed.

getType

public Type getType(IValue value)
Description copied from interface: IValueFactory
Gets the type of a value.

Specified by:
getType in interface IValueFactory
Parameters:
value - The value whose type to be retrieved. Must be non-null.
Returns:
The type of the value. Non-null.

connect

public IMessageStore connect(IBogorConfiguration bc)
Description copied from interface: IModule
Connects this modules to other modules.

Specified by:
connect in interface IModule
Parameters:
bc - The Bogor configuration containing modules to connect to. Must be non-null.

createDefaultValue

public IValue createDefaultValue(Type type)
Description copied from interface: IValueFactory
Creates a default value of a type.

Specified by:
createDefaultValue in interface IValueFactory
Parameters:
type - The type whose default value to be created. If the type is a range type that does not include zero in its range, then the low limit of the range type is the default value. Must be either a primitive type or a non-primitive type.
Returns:
The default value of the type. Non-null.

dispose

public void dispose()
Description copied from interface: Disposable
Remove references. Once called, avoid using this object.

Specified by:
dispose in interface Disposable

newArrayValue

public IArrayValue newArrayValue(ArrayType arrayType,
                                 Type[] fieldTypes,
                                 int[] lengths)
Description copied from interface: IValueFactory
Creates an array value.

Specified by:
newArrayValue in interface IValueFactory
Parameters:
arrayType - The array type whose value to be created.
fieldTypes - The array fields' types. Must be non-null. Each element must be non-null.
lengths - The lengths of dimensions of the new array. The number of lenghts must be at most equal to the array rank. Must contain at least one element. Each length must be at least zero.
Returns:
A new array value. Non-null. The array's elements and fields are assigned to their default values.

newDoubleValue

public IDoubleValue newDoubleValue(double d)
Description copied from interface: IValueFactory
Creates a double value.

Specified by:
newDoubleValue in interface IValueFactory
Parameters:
d - The double of the double value.
Returns:
A new double value. Non-null.

newExpASTValue

public IExpASTValue newExpASTValue(Exp exp)
Description copied from interface: IValueFactory
Creates an exp AST value.

Specified by:
newExpASTValue in interface IValueFactory
Parameters:
exp - The exp AST of the exp AST value. Must be non-null.
Returns:
A new exp AST value. Non-null.

newFloatValue

public IFloatValue newFloatValue(float f)
Description copied from interface: IValueFactory
Creates a float value.

Specified by:
newFloatValue in interface IValueFactory
Parameters:
f - The float of the float value.
Returns:
A new float value. Non-null.

newIntValue

public IIntValue newIntValue(Type type,
                             int integer)
Description copied from interface: IValueFactory
Creates an integer value.

Specified by:
newIntValue in interface IValueFactory
Parameters:
type - The type of this integer. Must be instance of IntType or BooleanType.
integer - The integer of this integer value.
Returns:
A new integer value whose type is given. Non-null.

newIntValue

public IIntValue newIntValue(int integer)
Description copied from interface: IValueFactory
Creates an integer value.

Specified by:
newIntValue in interface IValueFactory
Parameters:
integer - The integer of the integer value.
Returns:
A new integer value with IntType as its type. Non-null.

newLockValue

public ILockValue newLockValue()
Description copied from interface: IValueFactory
Creates a new lock value.

Specified by:
newLockValue in interface IValueFactory
Returns:
A new lock value. Non-null.

newLongValue

public ILongValue newLongValue(LongType type,
                               long l)
Description copied from interface: IValueFactory
Creates an integer value.

Specified by:
newLongValue in interface IValueFactory
Parameters:
type - The type of the long value. Must be non-null.
l - The long of the long value.
Returns:
A new integer value whose type is given. Non-null.

newLongValue

public ILongValue newLongValue(long l)
Description copied from interface: IValueFactory
Creates a long value.

Specified by:
newLongValue in interface IValueFactory
Parameters:
l - The long of the long value.
Returns:
A new long value with LongType as its type. Non-null.

newNullValue

public INullValue newNullValue()
Description copied from interface: IValueFactory
Creates a new null value.

Specified by:
newNullValue in interface IValueFactory
Returns:
A new null value. Non-null.

newRecordValue

public IRecordValue newRecordValue(RecordType recordType)
Description copied from interface: IValueFactory
Creates a new record value.

Specified by:
newRecordValue in interface IValueFactory
Parameters:
recordType - The record type whose value to be created. Must be non-null.
Returns:
A new record value. Non-null. The record's fields are assigned to their default values.

newReferenceId

public int newReferenceId()
Description copied from interface: IValueFactory
Generates a new reference id.

Specified by:
newReferenceId in interface IValueFactory
Returns:
A new reference id.

newStringValue

public IStringValue newStringValue(String s)
Description copied from interface: IValueFactory
Creates a string value.

Specified by:
newStringValue in interface IValueFactory
Parameters:
s - The string of the string value. Must be non-null.
Returns:
A new string value. Non-null.

newUniformValueArray

public IValueArray newUniformValueArray(IValue[] values)
Description copied from interface: IValueFactory
Creates a value array from an array of values.

Specified by:
newUniformValueArray in interface IValueFactory
Parameters:
values - The array of values. Must be non-null. Each element must be non-null. Each element must be of the same type.
Returns:
The new value array.

newVariedValueArray

public IValueArray newVariedValueArray(IValue[] values)
Description copied from interface: IValueFactory
Creates a value array from an array of values.

Specified by:
newVariedValueArray in interface IValueFactory
Parameters:
values - The array of values. Must be non-null. Each element must be non-null.
Returns:
The new value array.

validate

public void validate(IValue value)
Description copied from interface: IValueFactory
Validates a value.

Specified by:
validate in interface IValueFactory
Parameters:
value - The value to be validated. Must be non-null.

validate

public void validate(IValueArray valueArray)
Description copied from interface: IValueFactory
Validates a value array.

Specified by:
validate in interface IValueFactory
Parameters:
valueArray - The value array to be validated. Must be non-null.

recurseNewArrayValue

protected IValue recurseNewArrayValue(ArrayType arrayType,
                                      Type[] fieldTypes,
                                      int[] lengths,
                                      int i)
Creates an array value given for each dimension's length.

Parameters:
arrayType - The array type for the new array value. Non-null.
fieldTypes - The field types of an array types. Non-null. Each element is non-null.
lengths - The array that contains the length of each dimension. At least one element. Each element must be at least zero.
i - The current dimension to create. At most equal to rank. At least zero.

getOptionIds

public Collection<Triple<String,Boolean,OptionScope>> getOptionIds()
Specified by:
getOptionIds in interface ISelfDescribingModule
Returns:
a set of tuples whose first element says the name of the option, and whose second element says whether the option is required, and whose third element says whether the option is private to this module (and thus prefixed by the interface implemented, e.g., edu.ksu.cis.projects.bogor.module.ISearcher) or global in scope (and thus no qualifier is prepended).

getOptionDomain

public Pair<Domain,Boolean> getOptionDomain(String id)
Specified by:
getOptionDomain in interface ISelfDescribingModule
Returns:
a tuple whose first element says the domain of the option values, and whose second element says whether the option is multivalued (that is, a comma-separated list)

getSuggestedValues

public Collection<String> getSuggestedValues(String id,
                                             IBogorConfiguration bc,
                                             SymbolTable st)
Specified by:
getSuggestedValues in interface ISelfDescribingModule

validate

public boolean validate(String id,
                        String value,
                        IBogorConfiguration bc,
                        SymbolTable st,
                        Collection<FileMessage> errors)
Description copied from interface: ISelfDescribingModule
Checks whether the value of a configuration option is legal.

Specified by:
validate in interface ISelfDescribingModule
Parameters:
id - the option's name, as returned by the first tuple element of an item returned by ISelfDescribingModule.getOptionIds()
value - the value of the option, or null if unconfigued
st - the symbol table for the BIR model
errors - a container into which errors should be put. Implementors should not assume that errors is empty upon entry into this method; it may aggregate the results of calling validate on many ISelfDescribingModule instances.
Returns:
true iff the option is supported and its value is legal