com.codestreet.messageforge
Class RFld

java.lang.Object
  extended bycom.codestreet.messageforge.RFld
All Implemented Interfaces:
RFldInterface, java.io.Serializable
Direct Known Subclasses:
RFldArray, RFldBean, RFldBool, RFldDatetime, RFldHashtable, RFldList, RFldMemo, RFldMoney, RFldMsgObj, RFldNumeric, RFldOpaque, RFldString, RFldTibrvIPAddr, RFldTibrvIPPort, RFldTibrvMsg, RFldXml

public abstract class RFld
extends java.lang.Object
implements RFldInterface

Abstract base class for fields in a RMsg.

Author:
Jawaid Hakim.
See Also:
Serialized Form

Field Summary
protected  java.lang.String desc_
          Field description.
protected  int fieldId_
          Field id.
protected  boolean locked_
          Lock flag -true indicated that the field is locked, false indicated that the field is not locked.
protected  java.lang.String name_
          Field name.
protected  boolean optional_
          Optional flag -true if this field is optional.
protected  java.lang.String propertyName_
          Property name.
protected  java.lang.String[] tags_
          Field tags.
protected  boolean transient_
          Transient flag -true if this field is transient.
protected  boolean valSet_
          Flag to check if value is set.
 
Constructor Summary
protected RFld()
          Default constructor.
protected RFld(java.lang.String name, int fieldId)
          Constructor.
protected RFld(java.lang.String name, int fieldId, java.lang.String desc)
          Constructor.
protected RFld(java.lang.String name, int fieldId, java.lang.String desc, boolean isOptional, boolean isTransient)
          Constructor.
protected RFld(java.lang.String name, int fieldId, java.lang.String desc, boolean isOptional, boolean isTransient, java.lang.String propertyName)
          Constructor.
 
Method Summary
 void addConstraint(RFldConstraint cons)
          Add a constraint.
static java.lang.String buildMinMaxConstraintKey(java.lang.Object min, java.lang.Object max)
           
abstract  boolean equals(java.lang.Object anObject)
          Check if another field is equal to this field.
protected  RFldConstraint getConstraint(int index)
          Get a specified constraint.
protected  int getConstraintCount()
          Get the number of constraints.
 java.lang.String getDesc()
          Get field description.
 int getId()
          Get field id.
 java.lang.String getName()
          Get field name.
 boolean getOptional()
          Check if this field is optional.
 java.lang.String getPropertyName()
          Get property name.
abstract  java.lang.String getTag()
          Get the XML tag for this field type.
 java.lang.String[] getTags()
          Get the tags for this field.
 boolean getTransient()
          Check if this field is transient.
abstract  RFldType getType()
          Get field type.
abstract  java.lang.String getValueAsString()
          Get the field value as a string.
abstract  int hashCode()
          Supply an implementation that is compatable with equals.
 boolean isConstrained()
          Check if the field value is constrained.
 boolean isLocked()
          Get Lock/Unlock property of the field object.
 boolean isProperty()
          Check if this field is a property.
 boolean isValSet()
          Check if the field value is set.
 void marshal(java.io.Writer writer, int indentLevel, java.lang.String indent, boolean newLines, boolean expandEmptyElements)
          Write the field as XML to target writer.
protected static void marshal(java.io.Writer writer, java.lang.String tag, java.lang.String name, java.lang.String val, java.lang.String type, int indentLevel, java.lang.String indent, boolean newLines, boolean expandEmptyElements)
          Write the field as XML to target writer.
abstract  void reset()
          Reset the field value.
abstract  RFld set(org.jdom.Element elem)
          Set the value of the field from a JDOM element.
abstract  RFld set(java.lang.Object newData)
          Set the value of the field from an Object.
 void setId(int fieldId)
          Set field id.
 void setLocked(boolean locked)
          Lock/Unlock the field object.
 void setName(java.lang.String name)
          Set field name.
 void setOptional(boolean optional)
          Set optional property.
 void setPropertyName(java.lang.String name)
          Set property name.
 void setTags(java.lang.String[] tags)
          Set the tags for this field.
 void setTransient(boolean isTransient)
          Set transient property.
static void setXmlAttrNames(java.lang.String name, java.lang.String val, java.lang.String id)
          Register custom XML attribute names.
static void setXmlTags(java.util.Map xmlTags)
          Register custom XML field tags.
abstract  void validate()
          Validate against constraints.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.codestreet.messageforge.RFldInterface
getValueAsHashtable, getValueAsObject
 

Field Detail

name_

protected java.lang.String name_
Field name.


fieldId_

protected int fieldId_
Field id.


desc_

protected java.lang.String desc_
Field description.


optional_

protected boolean optional_
Optional flag -true if this field is optional. Otherwise, false. Default is false.


transient_

protected boolean transient_
Transient flag -true if this field is transient. Otherwise, false. Default is false.


locked_

protected boolean locked_
Lock flag -true indicated that the field is locked, false indicated that the field is not locked.


valSet_

protected boolean valSet_
Flag to check if value is set. true indicates that the field's value has been set. false indicates that the field's value has not been set.


propertyName_

protected java.lang.String propertyName_
Property name. Should be set for fields that have been tagged as properties.


tags_

protected java.lang.String[] tags_
Field tags.

Constructor Detail

RFld

protected RFld()
Default constructor.


RFld

protected RFld(java.lang.String name,
               int fieldId)
Constructor.

Parameters:
name - Field name.
fieldId - Field id. Field ids must be either 0 to indicate that there is no id on the field, or greater. In addition, field ids must be unique within a messages - no two fields are allowed to have the same field id.

RFld

protected RFld(java.lang.String name,
               int fieldId,
               java.lang.String desc)
Constructor.

Parameters:
name - Field name.
fieldId - Field id. Field ids must be either 0 to indicate that there is no id on the field, or greater. In addition, field ids must be unique within a messages - no two fields are allowed to have the same field id.
desc - Field description.
See Also:
RFldType

RFld

protected RFld(java.lang.String name,
               int fieldId,
               java.lang.String desc,
               boolean isOptional,
               boolean isTransient)
Constructor.

Parameters:
name - Field name.
fieldId - Field id. Field ids must be either 0 to indicate that there is no id on the field, or greater. In addition, field ids must be unique within a messages - no two fields are allowed to have the same field id.
desc - Field description.
isOptional - true to indicate if the field is optional. Otherwise false.
isTransient - true to indicate if the field is transient. Otherwise false.

RFld

protected RFld(java.lang.String name,
               int fieldId,
               java.lang.String desc,
               boolean isOptional,
               boolean isTransient,
               java.lang.String propertyName)
Constructor.

Parameters:
name - Field name.
fieldId - Field id. Field ids must be either 0 to indicate that there is no id on the field, or greater. In addition, field ids must be unique within a messages - no two fields are allowed to have the same field id.
desc - Field description.
isOptional - true to indicate if the field is optional. Otherwise false.
isTransient - true to indicate if the field is transient. Otherwise false.
propertyName - Property name for field. Set to null if field is nto a property. When property fields are marshaled to some protocols - e.g. JMS - their values are added as properties to the message in addition to the payload.
Method Detail

getName

public final java.lang.String getName()
Get field name.

Specified by:
getName in interface RFldInterface
Returns:
Field name.

setName

public final void setName(java.lang.String name)
Set field name.

Parameters:
name - Field name.

getId

public final int getId()
Get field id.

Specified by:
getId in interface RFldInterface
Returns:
Field id.

setId

public final void setId(int fieldId)
Set field id.

Parameters:
fieldId - Field id.

getDesc

public final java.lang.String getDesc()
Get field description.

Specified by:
getDesc in interface RFldInterface
Returns:
Field description.

getOptional

public final boolean getOptional()
Check if this field is optional.

Returns:
true if field is optional. Otherwise, return false.
See Also:
setOptional(boolean)

setOptional

public final void setOptional(boolean optional)
Set optional property.

Parameters:
optional - Optional flag -true if this field is optional, otherwise false. Default is false.

getTransient

public final boolean getTransient()
Check if this field is transient.

Returns:
true if field is transient. Otherwise, return false.
See Also:
setTransient(boolean)

setTransient

public final void setTransient(boolean isTransient)
Set transient property.

Parameters:
isTransient - Transient flag -true if this field is transient, otherwise false. Default is false.

isLocked

public final boolean isLocked()
Get Lock/Unlock property of the field object. If a message is locked then all the setter methods are disabled.

Specified by:
isLocked in interface RFldInterface
Returns:
Returns true if field is locked. Otherwise, returns false.

setLocked

public final void setLocked(boolean locked)
Lock/Unlock the field object.

Parameters:
locked - true to lock the field. Otherwise, false to unlock the field.

getTags

public final java.lang.String[] getTags()
Get the tags for this field. Each field can have one or more associated tags.

Returns:
Tags for the field. Returns null if this field does not have any associated tags.

setTags

public final void setTags(java.lang.String[] tags)
Set the tags for this field. Each field can have one or more tags.

Parameters:
tags - Tags for this field.

addConstraint

public final void addConstraint(RFldConstraint cons)
                         throws FieldValidationException
Add a constraint.

Parameters:
cons - Constraint.
Throws:
java.lang.IllegalArgumentException - if constraint is null.
FieldValidationException

getConstraintCount

protected final int getConstraintCount()
Get the number of constraints.

Returns:
Number of constraints.
See Also:
getConstraint(int)

getConstraint

protected final RFldConstraint getConstraint(int index)
Get a specified constraint.

Parameters:
index - Index of constraint.
Returns:
Specified constraint.
Throws:
java.lang.NullPointerException - if no constraints have been set on this field.
See Also:
getConstraintCount()

isValSet

public final boolean isValSet()
Check if the field value is set.

Specified by:
isValSet in interface RFldInterface
Returns:
true if the field value has been set. Otherwise, returns false.

isConstrained

public final boolean isConstrained()
Check if the field value is constrained.

Specified by:
isConstrained in interface RFldInterface
Returns:
true if the field value has constraints. Otherwise, returns false.

isProperty

public boolean isProperty()
Check if this field is a property.

Specified by:
isProperty in interface RFldInterface
Returns:
Returns true if this field is a property.
See Also:
getPropertyName()

getPropertyName

public java.lang.String getPropertyName()
Get property name.

Specified by:
getPropertyName in interface RFldInterface
Returns:
Returns property name if this field is a property. Returns null if this field is not a property.
See Also:
isProperty()

setPropertyName

public void setPropertyName(java.lang.String name)
Set property name.

Parameters:
name - Property name.
See Also:
getPropertyName(), isProperty()

getType

public abstract RFldType getType()
Get field type.

Specified by:
getType in interface RFldInterface
Returns:
Field type.
See Also:
RFldType

validate

public abstract void validate()
                       throws FieldValidationException
Validate against constraints. A field is valid if either it's value is set and satisfies all constraints, or the the field is optional.

Throws:
FieldValidationException

equals

public abstract boolean equals(java.lang.Object anObject)
Check if another field is equal to this field. Equality is defined as the fields having the same value.

Parameters:
anObject - Another object.
Returns:
true if another message is equal to this message. Otherwise, returns false.

hashCode

public abstract int hashCode()
Supply an implementation that is compatable with equals.

Returns:
hash code of the field.

set

public abstract RFld set(org.jdom.Element elem)
                  throws FieldValidationException
Set the value of the field from a JDOM element.

Specified by:
set in interface RFldInterface
Parameters:
elem - New field value.
Returns:
Reference to self so method chaining can be used.
Throws:
FieldValidationException

set

public abstract RFld set(java.lang.Object newData)
                  throws FieldValidationException
Set the value of the field from an Object.

Specified by:
set in interface RFldInterface
Parameters:
newData - New field value.
Returns:
Reference to self so method chaining can be used.
Throws:
FieldValidationException

reset

public abstract void reset()
                    throws FieldValidationException
Reset the field value.

Throws:
FieldValidationException
See Also:
isValSet()

getValueAsString

public abstract java.lang.String getValueAsString()
Get the field value as a string.

Returns:
Field value as a string. Returns null if the field value is not set.

getTag

public abstract java.lang.String getTag()
Get the XML tag for this field type.

Returns:
XML tag for this field type.

marshal

public void marshal(java.io.Writer writer,
                    int indentLevel,
                    java.lang.String indent,
                    boolean newLines,
                    boolean expandEmptyElements)
             throws ConverterException
Write the field as XML to target writer.

Specified by:
marshal in interface RFldInterface
Parameters:
writer - Output target.
indent - Indentation.
newLines - Newlines are inserted after each element if true.
expandEmptyElements - Empty elements - elements with no content - are expanded if true.
Throws:
ConverterException

setXmlTags

public static final void setXmlTags(java.util.Map xmlTags)
                             throws FieldValidationException
Register custom XML field tags.

Parameters:
xmlTags - A mapping of old tags to new custom tags.
Throws:
FieldValidationException

setXmlAttrNames

public static final void setXmlAttrNames(java.lang.String name,
                                         java.lang.String val,
                                         java.lang.String id)
Register custom XML attribute names.

Parameters:
name - New name of the field name attribute.
val - New name of the field value attribute.
id - New name of the id field attribute.

buildMinMaxConstraintKey

public static final java.lang.String buildMinMaxConstraintKey(java.lang.Object min,
                                                              java.lang.Object max)

marshal

protected static final void marshal(java.io.Writer writer,
                                    java.lang.String tag,
                                    java.lang.String name,
                                    java.lang.String val,
                                    java.lang.String type,
                                    int indentLevel,
                                    java.lang.String indent,
                                    boolean newLines,
                                    boolean expandEmptyElements)
                             throws ConverterException
Write the field as XML to target writer.

Parameters:
writer - Output target.
indent - Indentation.
newLines - Newlines are inserted after each element if true.
expandEmptyElements - Empty elements - elements with no content - are expanded if true.
Throws:
ConverterException


Copyright © 2003-2006 CodeStreet. All Rights Reserved.