Package net.sf.eBus.messages.type
Class ArrayType
- java.lang.Object
-
- net.sf.eBus.messages.type.DataType
-
- net.sf.eBus.messages.type.ArrayType
-
- All Implemented Interfaces:
java.lang.Comparable<DataType>
public final class ArrayType extends DataType
Provides binary serialization/de-serialization of an object collection. The collection must containEMessageObjectobjects of the same class type.Supports array sizes up to
DataType.MAX_ARRAY_SIZEitems.- Author:
- Charles Rapp
-
-
Field Summary
-
Fields inherited from class net.sf.eBus.messages.type.DataType
ADDRESS_TYPE, ARRAY_SUFFIX, CLASS_TYPE, DEFAULT_CHARSET, EMPTY_STRING, FIELD_MASK_SIZE, INDENT, INDENT1, KEY_TYPE, MAX_ARRAY_SIZE, MAX_BIG_INTEGER_SIZE, MAX_CLASS_NAME_LENGTH, MAX_FIELDS, MAX_FILE_NAME_LENGTH, MAX_STRING_LENGTH, MAX_ZONE_ID_LENGTH, mBuiltinFlag, mClass, mDefaultValue, mIsFixedSize, mSize, sClasses, sCompiledClasses, sTextTypes, STRING_TYPE, sVariableTypes, VARIABLE_SIZE
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcreateDeserializer(MessageType.MessageField field, java.lang.String fieldName, java.lang.String indent, java.util.Formatter output, boolean useBuilder)Generates the Java code for de-serializing an array.protected voidcreateSerializer(MessageType.MessageField field, java.lang.String fieldName, java.lang.String indent, java.util.Formatter output)Generates the array serialization code.java.lang.StringdataClassName()Returns the Java class name with "[]" appended.java.lang.Objectdeserialize(MessageType.MessageField field, java.nio.ByteBuffer buffer)Returns the de-serialized collection as anObject.booleanisInstance(java.lang.Object o)Returnstrueifois eithernullor aCollectioninstance;falseotherwise.voidserialize(java.lang.Object o, MessageType.MessageField field, java.nio.ByteBuffer buffer)Serializes this list to the buffer.DataTypesubtype()Returns the array subtype.java.lang.StringtoString()Returns the subtype Java class name followed by "[]".-
Methods inherited from class net.sf.eBus.messages.type.DataType
compareTo, dataClass, defaultValue, equals, fields, findCharset, findType, hashCode, isArray, isBoolean, isBoolean, isBuiltin, isEnum, isField, isFixedSize, isLocalOnly, isMessage, isPrimitive, maxAllowedTextSize, replyClasses, size
-
-
-
-
Constructor Detail
-
ArrayType
public ArrayType(java.lang.Class<?> jClass, DataType subtype)Creates an array type which encapsulates the specified data type. Arrays are homogeneous collections and considered a built-in type.- Parameters:
jClass- the Java array class.subtype- the array element type.
-
-
Method Detail
-
isInstance
public boolean isInstance(java.lang.Object o)
Returnstrueifois eithernullor aCollectioninstance;falseotherwise.- Overrides:
isInstancein classDataType- Parameters:
o- Check this object's type.- Returns:
trueifois eithernullor aCollectioninstance;falseotherwise.
-
serialize
public void serialize(java.lang.Object o, MessageType.MessageField field, java.nio.ByteBuffer buffer)Serializes this list to the buffer.- Specified by:
serializein classDataType- Parameters:
o- an object array.field- contains external information needed to serialize this message field.buffer- serialize array to this buffer.- Throws:
java.nio.BufferOverflowException- ifbufferoverflows.- See Also:
deserialize(net.sf.eBus.messages.type.MessageType.MessageField, java.nio.ByteBuffer)
-
deserialize
public java.lang.Object deserialize(MessageType.MessageField field, java.nio.ByteBuffer buffer)
Returns the de-serialized collection as anObject. If the array size is zero, then returns an empty collection. The returned value may be safely typecast tojava.util.Collection.- Specified by:
deserializein classDataType- Parameters:
field- contains information needed to de-serialize this message field.buffer- de-serialize the list object from thisByteBuffer.- Returns:
- the de-serialized
Collection. - Throws:
DeserializeException- if encoded array size is either < zero or > maximum allowed size.java.nio.BufferUnderflowException- ifbuffercontains an incomplete serialized array.- See Also:
serialize(java.lang.Object, net.sf.eBus.messages.type.MessageType.MessageField, java.nio.ByteBuffer)
-
createSerializer
protected void createSerializer(MessageType.MessageField field, java.lang.String fieldName, java.lang.String indent, java.util.Formatter output)
Generates the array serialization code.- Specified by:
createSerializerin classDataType- Parameters:
field- message field.fieldName- fully-qualified field name.indent- indent generated code by this spacing.output- place generated code into this formatter.
-
createDeserializer
protected void createDeserializer(MessageType.MessageField field, java.lang.String fieldName, java.lang.String indent, java.util.Formatter output, boolean useBuilder)
Generates the Java code for de-serializing an array.- Specified by:
createDeserializerin classDataType- Parameters:
field- message field.fieldName- the array message field name.indent- indent the code by this amount.output- append the code to this formatter.useBuilder- iftruethenfieldNameis a builder method name; otherwise a local variable.
-
toString
public java.lang.String toString()
Returns the subtype Java class name followed by "[]".
-
dataClassName
public java.lang.String dataClassName()
Returns the Java class name with "[]" appended.- Overrides:
dataClassNamein classDataType- Returns:
- Java class name.
-
subtype
public DataType subtype()
Returns the array subtype. All array items are of this type.- Returns:
- the array subtype.
-
-