public abstract class DmcAttribute<VALUE> extends Object implements Cloneable, Serializable, Comparable<String>
To define a new type you need two parts, the VALUE class (which is supplied as the VALUE parameter to this class) and, by convention, a DmcType[VALUE] class that is derived from DmcAttribute. The DmcType[VALUE] class must implement four functions: typeCheck(), cloneValue(), serializeValue() and deserializeValue(). The DmcType[VALUE] class is abstract.
The remainder of the functionality required is generated as part of the Dark Matter Object (DMO) generation process. This process results in VALUE specific implementations of single-valued (SV), multi-valued(MV), mapped (MAP for HashMap and TreeMap)and set (SET for HashSet and TreeSet) to be created in your generated.types package for a particular schema. Each of these implementations is derived from your DmcType[VALUE] class and overload the appropriate methods defined in DmcAttribute.
The DmcAttribute merely provides a mechanism for constructing ID/VALUE pairs for single and multi-valued attributes. There are four primary modification interfaces on a DmcAttribute:
Retrieval of values is accomplished via:
| Modifier and Type | Field and Description |
|---|---|
protected DmcAttributeInfo |
attrInfo |
protected Integer |
ID |
| Modifier | Constructor and Description |
|---|---|
protected |
DmcAttribute()
Constructs a new attribute value holder.
|
protected |
DmcAttribute(DmcAttributeInfo ai)
Constructs a new attribute value holder.
|
| Modifier and Type | Method and Description |
|---|---|
VALUE |
add(Object value)
Adds the specified value to a multi-valued attribute.
|
protected void |
addModsMV(DmcTypeModifierMV mods,
DmcAttribute<?> existingValue,
DmcAdapterIF adapter) |
protected void |
addModsSV(DmcTypeModifierMV mods,
DmcAttribute<?> existingValue,
DmcAdapterIF adapter) |
abstract DmcAttribute<VALUE> |
cloneIt()
This method is overridden in the auto-generated classes to create a deep clone
of the attribute.
|
protected abstract VALUE |
cloneValue(VALUE original)
This method must be overridden to clone whatever value is stored in this attribute.
|
int |
compareTo(String o)
Compares the name of this attribute to the specified String for order.
|
boolean |
contains(Object obj)
If we have a multi-valued attribute, we checked to see it it contains the specified value.
|
boolean |
containsKey(Object key)
If we have a mapped attribute, we checked to see it it contains the specified key.
|
VALUE |
del(Object v)
Removes a value from a multi-valued attribute.
|
void |
deserializeIt(DmcInputStreamIF dis)
This method will deserialize this attribute from an input stream.
|
abstract VALUE |
deserializeValue(DmcInputStreamIF dis)
This method must be overridden to read a single value from the input stream.
|
protected String |
formatValue(VALUE value)
This method is called in toOIF() to format an attribute value.
|
protected void |
formatValueAsCompactJSON(StringBuffer sb)
This method may be overloaded to properly format attributes that refer directly
to DmcObjects or that are object references.
|
protected void |
formatValueAsJSON(StringBuffer sb,
int padding,
String indent)
This method may be overloaded to properly format attributes that refer directly
to DmcObjects or that are object references.
|
DmcAttributeInfo |
getAttributeInfo() |
VALUE |
getByKey(Object key)
This method is overloaded in DmcHashedAttribute - it returns null at this level.
|
Integer |
getID()
Returns the unique attribute ID.E
|
Iterator<VALUE> |
getMV()
Returns an Iterator over a multi-valued attribute's values.
|
VALUE |
getMVnth(int index)
A convenience function to return the nth value from a multi-valued attribute.
|
int |
getMVSize()
For a multi-valued attribute, this returns the number of values in the attribute.
|
String |
getName() |
protected abstract DmcAttribute<?> |
getNew()
Derived classes must return a new, empty version of themselves.
|
VALUE |
getSV()
Returns the single-valued attribute value.
|
boolean |
hasValue()
If we have an indexed, multi-valued attribute, this method will traverse all of the slots to determine if we still
have any non-null values.
|
String |
modifierFormat()
Returns this attribute as just "value" with no line feeds.
|
void |
serializeIt(DmcOutputStreamIF dos)
Serializes this attribute value.
|
abstract void |
serializeValue(DmcOutputStreamIF dos,
VALUE value)
This method must be overridden to serialize the specified value to the
output stream.
|
VALUE |
set(Object value)
Sets the value of a single-valued attribute.
|
void |
setAttributeInfo(DmcAttributeInfo ai)
Sets the attribute info associated with this attribute.
|
VALUE |
setMVnth(int index,
Object value)
For indexed, multi-valued attributes, we set the nth value as specified.
|
void |
toOIF(StringBuffer sb)
Returns this attribute in Object Instance Format (OIF) which is basically the attribute
name followed by the string representation of the value of the attribute.
|
void |
toOIF(StringBuffer sb,
int padding)
Returns this attribute in Object Instance Format (OIF) which is basically the attribute
name followed by the string representation of the value of the attribute.
|
protected abstract VALUE |
typeCheck(Object value)
Derived classes must overload this method to determine if the value passed
in conforms with their type criteria.
|
protected boolean |
valueChangedMV(DmcAttribute<?> existingValue,
DmcAdapterIF adapter) |
protected boolean |
valueChangedSV(DmcAttribute<?> existingValue,
DmcAdapterIF adapter) |
protected Integer ID
protected transient DmcAttributeInfo attrInfo
protected DmcAttribute()
protected DmcAttribute(DmcAttributeInfo ai)
public DmcAttributeInfo getAttributeInfo()
public void setAttributeInfo(DmcAttributeInfo ai)
ai - The attribute information.public Integer getID()
public String getName()
public int compareTo(String o)
compareTo in interface Comparable<String>protected abstract VALUE typeCheck(Object value) throws DmcValueException
value - the value to be checkedDmcValueException - if the value is incorrectprotected abstract VALUE cloneValue(VALUE original)
original - the original valuepublic abstract void serializeValue(DmcOutputStreamIF dos, VALUE value) throws Exception
dos - The output stream.value - The value to be serialized.Exception - if problems occurpublic abstract VALUE deserializeValue(DmcInputStreamIF dis) throws Exception
dis - the input stream.Exception - if problems occurprotected abstract DmcAttribute<?> getNew()
public VALUE set(Object value) throws DmcValueException
value - The value to be setDmcValueException - if the value is not compatible with the underlying type.public VALUE getSV()
public VALUE add(Object value) throws DmcValueException
value - The value to be addedDmcValueException - if the value is not compatible with the underlying type.public VALUE del(Object v)
v - The value to be removed.public Iterator<VALUE> getMV()
public int getMVSize()
public VALUE getMVnth(int index)
index - The value index.public VALUE setMVnth(int index, Object value) throws DmcValueException
index - The value index.value - The value to be set. if the value is null, that index location is nulled.DmcValueExceptionpublic VALUE getByKey(Object key)
key - the key valuepublic boolean contains(Object obj)
obj - The object we're looking for.public boolean containsKey(Object key)
key - The key we're looking for.public boolean hasValue()
public abstract DmcAttribute<VALUE> cloneIt()
public void serializeIt(DmcOutputStreamIF dos) throws Exception
dos - The stream to which we're serialized.IOException - if IO problems occurDmcValueException - if value problems occurExceptionpublic void deserializeIt(DmcInputStreamIF dis) throws Exception
dis - The input stream.Exception - if you've tried to store a non-DmcHashedAttribute derivative as HASHMAPPED or TREEMAPPED.protected String formatValue(VALUE value)
public void toOIF(StringBuffer sb)
sb - the string buffer to which we writepublic void toOIF(StringBuffer sb, int padding)
sb - The string buffer to which we append the attribute valuespadding - The amount of padding to provide for the "left-justified" attribute name.public String modifierFormat()
protected void addModsSV(DmcTypeModifierMV mods, DmcAttribute<?> existingValue, DmcAdapterIF adapter)
protected boolean valueChangedSV(DmcAttribute<?> existingValue, DmcAdapterIF adapter)
protected void addModsMV(DmcTypeModifierMV mods, DmcAttribute<?> existingValue, DmcAdapterIF adapter)
protected boolean valueChangedMV(DmcAttribute<?> existingValue, DmcAdapterIF adapter)
protected void formatValueAsJSON(StringBuffer sb, int padding, String indent)
sb - the string buffer we write topadding - the paddingindent - the indentprotected void formatValueAsCompactJSON(StringBuffer sb)
sb - the string buffer we write toCopyright © 2023. All rights reserved.