org.sandev.basics.structs
Class SandAttrVal

java.lang.Object
  extended byorg.sandev.basics.structs.SandAttrVal
All Implemented Interfaces:
SandInstanceMessage, SandMessage

public class SandAttrVal
extends java.lang.Object
implements SandInstanceMessage

A structure for representing a general attribute/value pair in string form. How the attrval is used depends on the context, so this is a dependent object and not persistent on its own. Conceptually an attribute/value representation can be thought of as raw input which requires processing to yield an object instance or instances.


Field Summary
protected  java.lang.String attr
          The attribute being referenced.
static java.lang.String FIELD_ATTR
          Name of the attr field.
static java.lang.String FIELD_VAL
          Name of the val field.
protected  java.lang.String val
          The value of the attribute.
 
Fields inherited from interface org.sandev.basics.structs.SandInstanceMessage
FIELDCHECK_INVALIDVAL, FIELDCHECK_NOTAREF, FIELDCHECK_NOTINRANGE, FIELDCHECK_NULLARRAY, FIELDCHECK_STRINGOVER, FIELDCHECK_UNKNOWNVAL, FIELDFLAG_BINARY, FIELDFLAG_ENCRYPT, FIELDFLAG_INTERNAL, FIELDFLAG_NOECHO, FIELDFLAG_OBFUSCATE, FIELDFLAG_STRINGPERSIST, FIELDFLAG_UNIQUE, GENMOD_ACTION_APPEND, GENMOD_ACTION_INSERT, GENMOD_ACTION_REMOVE, GENMOD_ACTION_SET
 
Constructor Summary
SandAttrVal()
          Default constructor.
SandAttrVal(java.lang.String attr, java.lang.String val)
          Full field initialization ctor.
 
Method Summary
 SandInstanceMessage cloneMessage()
          Return a deep copy of this message.
 SandAttrVal cloneSandAttrVal()
          Make a deep copy of this SandAttrVal
 SandInstanceMessage convertToSuperstructClass()
          If this class was generated from a struct which extends another struct, then this method converts an instance of this class to an instance of the message class of the superstruct.
 void copyFieldValue(java.lang.String fieldName, SandInstanceMessage other)
          Downcast the other message and copy the value of the specified field into this instance.
 java.lang.String debugDump(java.lang.String prefix)
          Returns a dump of this object.
 void defaultField(java.lang.String fieldName)
          Set the specified field to its default value.
 boolean fieldHasFlag(java.lang.String fieldname, int fieldflag)
          Return true if the named field declares the indicated flag, false otherwise.
 boolean fieldsValid()
          If all fields have valid values, return true.
 SandAttrVal[] fieldValidate(SandAttrVal[] checkFields)
          Return a collection of fieldname-status pairs.
 java.lang.Object generalAccessor(java.lang.String fieldspec)
          Given a field specification, return the value.
 SandAttrVal generalDereference(java.lang.String fieldspec)
          Given a field specification, return the reference field name and reference field value.
 void generalModifier(int action, java.lang.String field, int index, java.lang.Object val)
          Perform the general modification action specified.
 java.lang.String[] getAllFields()
          Return all the fields declared for this class.
 java.lang.String getAttr()
          Accessor for attr
static boolean getAttrFlag(int fieldflag)
           
 int getAttrLengthMax()
           
 int getAttrLengthNorm()
           
 java.lang.String getAttrMetatype()
           
 boolean getAttrNoEcho()
           
 SandCollectionMessage getCollectionMessage()
          If this message has a SandCollectionMessage verb form associated with it, then return a new instance.
 java.lang.String[] getDisplayFields()
          Get default description values.
 java.lang.String[] getDisplayValues()
          Returns the values corresponding to the declared display fields.
 SandQueryMessage getQueryMessage()
          If this message has a SandQueryMessage verb form associated with it, then return a new instance.
 java.lang.String getShortName()
          Returns the unqualified name of this message.
 SandStructMessage getStructMessage()
          If this message has a SandStructMessage base form, then return a new instance.
 SandUpdateMessage getUpdateMessage()
          If this message has a SandUpdateMessage verb form associated with it, then return a new instance.
 java.lang.String getVal()
          Accessor for val
static boolean getValFlag(int fieldflag)
           
 int getValLengthMax()
           
 int getValLengthNorm()
           
 java.lang.String getValMetatype()
           
 boolean getValNoEcho()
           
 boolean isEquivalent(SandMessage sm)
          Declared field equivalence check.
 void setAttr(java.lang.String attr)
          Mutator for attr
 void setVal(java.lang.String val)
          Mutator for val
 java.util.ArrayList validateFields()
          Validates field values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

attr

protected java.lang.String attr
The attribute being referenced. How this is translated back into an object field depends on the usage context.


val

protected java.lang.String val
The value of the attribute. In some instances the value may be a match expression which corresponds roughly to a SQL "where" clause without the attribute references. So to search for 18 to 25 year olds, you would specify >= 18 AND <= 25 .


FIELD_ATTR

public static final java.lang.String FIELD_ATTR
Name of the attr field.

See Also:
Constant Field Values

FIELD_VAL

public static final java.lang.String FIELD_VAL
Name of the val field.

See Also:
Constant Field Values
Constructor Detail

SandAttrVal

public SandAttrVal()
Default constructor.


SandAttrVal

public SandAttrVal(java.lang.String attr,
                   java.lang.String val)
Full field initialization ctor.

Method Detail

getAttr

public java.lang.String getAttr()
Accessor for attr


setAttr

public void setAttr(java.lang.String attr)
Mutator for attr


getVal

public java.lang.String getVal()
Accessor for val


setVal

public void setVal(java.lang.String val)
Mutator for val


validateFields

public java.util.ArrayList validateFields()
Validates field values. Returns a list of all fields with invalid values.


getAttrLengthMax

public int getAttrLengthMax()

getAttrLengthNorm

public int getAttrLengthNorm()

getAttrNoEcho

public boolean getAttrNoEcho()

getValLengthMax

public int getValLengthMax()

getValLengthNorm

public int getValLengthNorm()

getValNoEcho

public boolean getValNoEcho()

isEquivalent

public boolean isEquivalent(SandMessage sm)
Declared field equivalence check. See interface declaration for full description and notes on equivalence testing.

Specified by:
isEquivalent in interface SandMessage

getShortName

public java.lang.String getShortName()
Returns the unqualified name of this message.

Specified by:
getShortName in interface SandMessage

getQueryMessage

public SandQueryMessage getQueryMessage()
Description copied from interface: SandMessage
If this message has a SandQueryMessage verb form associated with it, then return a new instance. Otherwise return null.

Specified by:
getQueryMessage in interface SandMessage

getCollectionMessage

public SandCollectionMessage getCollectionMessage()
Description copied from interface: SandMessage
If this message has a SandCollectionMessage verb form associated with it, then return a new instance. Otherwise return null.

Specified by:
getCollectionMessage in interface SandMessage

getUpdateMessage

public SandUpdateMessage getUpdateMessage()
Description copied from interface: SandMessage
If this message has a SandUpdateMessage verb form associated with it, then return a new instance. Otherwise return null.

Specified by:
getUpdateMessage in interface SandMessage

getStructMessage

public SandStructMessage getStructMessage()
Description copied from interface: SandMessage
If this message has a SandStructMessage base form, then return a new instance. Otherwise return null.

Specified by:
getStructMessage in interface SandMessage

generalModifier

public void generalModifier(int action,
                            java.lang.String field,
                            int index,
                            java.lang.Object val)
                     throws SandException
Description copied from interface: SandInstanceMessage
Perform the general modification action specified. Parameters:

Notes on use:

An exception is thrown if anything goes wrong.

Specified by:
generalModifier in interface SandInstanceMessage
Throws:
SandException

generalDereference

public SandAttrVal generalDereference(java.lang.String fieldspec)
Description copied from interface: SandInstanceMessage
Given a field specification, return the reference field name and reference field value. Return null if the field cannot be found. So for example this method might return "uniqueID"|"43" for a long reference, or "someField"|"somevalue" for a String reference.

To support access to array fields, this method also accepts field specifications with the array index specified. So for example if you want to retrieve the third element from an array field called myrefs, you would specify myrefs[2] as the fieldspec.

This method is intended for use with UI programming and other general object access situations where normal access is difficult due to generalized interfaces.

Specified by:
generalDereference in interface SandInstanceMessage

generalAccessor

public java.lang.Object generalAccessor(java.lang.String fieldspec)
Description copied from interface: SandInstanceMessage
Given a field specification, return the value. Return null if the field cannot be found, or if the value is null.

To support access to array fields, this method also accepts field specifications with the array index specified. So for example if you want to retrieve the third element from an array called myobjects, you would specify myobjects[2] as the fieldspec.

This method is intended for use with UI programming and other general object access situations where normal access is difficult due to generalized interfaces.

Specified by:
generalAccessor in interface SandInstanceMessage

getDisplayFields

public java.lang.String[] getDisplayFields()
Description copied from interface: SandInstanceMessage
Get default description values. If this struct has @display and @displayadd declarations, then return an array of the fields used for those declarations.

Specified by:
getDisplayFields in interface SandInstanceMessage

getDisplayValues

public java.lang.String[] getDisplayValues()
Description copied from interface: SandInstanceMessage
Returns the values corresponding to the declared display fields.

Specified by:
getDisplayValues in interface SandInstanceMessage

cloneMessage

public SandInstanceMessage cloneMessage()
Description copied from interface: SandInstanceMessage
Return a deep copy of this message.

Specified by:
cloneMessage in interface SandInstanceMessage

copyFieldValue

public void copyFieldValue(java.lang.String fieldName,
                           SandInstanceMessage other)
Description copied from interface: SandInstanceMessage
Downcast the other message and copy the value of the specified field into this instance. The other instance must be of the same class.

Specified by:
copyFieldValue in interface SandInstanceMessage

getAllFields

public java.lang.String[] getAllFields()
Description copied from interface: SandInstanceMessage
Return all the fields declared for this class. This includes fields inherited from other structs.

Specified by:
getAllFields in interface SandInstanceMessage

defaultField

public void defaultField(java.lang.String fieldName)
Description copied from interface: SandInstanceMessage
Set the specified field to its default value. Useful for filtering data based on authorization.

Specified by:
defaultField in interface SandInstanceMessage

convertToSuperstructClass

public SandInstanceMessage convertToSuperstructClass()
Description copied from interface: SandInstanceMessage
If this class was generated from a struct which extends another struct, then this method converts an instance of this class to an instance of the message class of the superstruct. For example if ResourceStruct extends ReaderStruct, calling this method on a Resource would return a Reader.

The return value is a new object instance with fields initialized appropriately, or null if this is a root level struct.

Specified by:
convertToSuperstructClass in interface SandInstanceMessage

debugDump

public java.lang.String debugDump(java.lang.String prefix)
Description copied from interface: SandInstanceMessage
Returns a dump of this object. This dumps out multiple lines with one field per line. If a prefix is specified it is prepended to each line. This is to support debugging or log output where it is helpful see what the instance is composed of.

Specified by:
debugDump in interface SandInstanceMessage

fieldHasFlag

public boolean fieldHasFlag(java.lang.String fieldname,
                            int fieldflag)
Description copied from interface: SandInstanceMessage
Return true if the named field declares the indicated flag, false otherwise. The FIELDFLAG* constants define the supported fieldflag values that can be queried.

Specified by:
fieldHasFlag in interface SandInstanceMessage

fieldValidate

public SandAttrVal[] fieldValidate(SandAttrVal[] checkFields)
Description copied from interface: SandInstanceMessage
Return a collection of fieldname-status pairs. The field name is the name as it is declared in the struct definition. The status is one of the constant FIELDCHECK_* string values defined here or the empty string "" if the field has a valid value. If checkFields is null or empty, then the returned array will contain all the fields.

While the FIELDCHECK keys are meant to be human readable, they are also constant strings and can be used to look up localized or other custom text within a UI. This method is in support of level 2 message validation, where the levels are:

  1. Raw input conversion: converting raw character input into actual field types.
  2. Field validation: making sure the field value is valid given the declarations for the field.
  3. Inter-field validation and business logic: Making sure the values of the fields make sense together.
  4. Persistent state validation: validation of uniqueness constraints and other persistent information.

Other validation methods may leverage the same SandAttrVal[] structure, adding their own status constants. This method supports at least the checking provided by the SAND field tags. The FIELDCHECK_* constants are not intended to be full error descriptions. Level 1 validation will already need to provide information about what kinds of input is valid, so it would be redundent to put it here as well. This method principally enforces the contract between validation levels 1 and 3.

Specified by:
fieldValidate in interface SandInstanceMessage

fieldsValid

public boolean fieldsValid()
Description copied from interface: SandInstanceMessage
If all fields have valid values, return true. Otherwise return false.

Specified by:
fieldsValid in interface SandInstanceMessage

getAttrFlag

public static boolean getAttrFlag(int fieldflag)

getValFlag

public static boolean getValFlag(int fieldflag)

getAttrMetatype

public java.lang.String getAttrMetatype()

getValMetatype

public java.lang.String getValMetatype()

cloneSandAttrVal

public SandAttrVal cloneSandAttrVal()
Make a deep copy of this SandAttrVal