Module org.refcodes.serial
Package org.refcodes.serial
Class SectionComposite<ALLOC extends AllocSectionDecoratorSegment<CHILD>,CHILD extends Section>
- java.lang.Object
-
- org.refcodes.serial.SectionComposite<ALLOC,CHILD>
-
- Type Parameters:
ALLOC
- The type of theAllocSectionDecoratorSegment
describing the length of eachSection
element in the composite.CHILD
- The type of theSection
elements to be contained in theSectionComposite
.
- All Implemented Interfaces:
Serializable
,org.refcodes.mixin.ChildrenAccessor<CHILD[]>
,org.refcodes.mixin.LengthAccessor
,Section
,Section.SectionMixin
,Transmission
,Transmission.TransmissionMixin
,TransmissionComposite<CHILD>
public class SectionComposite<ALLOC extends AllocSectionDecoratorSegment<CHILD>,CHILD extends Section> extends Object implements Section, Section.SectionMixin, TransmissionComposite<CHILD>
ASectionComposite
is aSection
consisting ofSection
elements of a variable length each: EachSection
element in the composite need not be of the same size. This is achieved by wrapping eachSection
inside a dedicatedAllocSectionDecoratorSegment
being aSegment
providing the resultingSection
's length (with all the composite'sSection
instances).- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.ChildrenAccessor
org.refcodes.mixin.ChildrenAccessor.ChildrenBuilder<T extends Object,B extends org.refcodes.mixin.ChildrenAccessor.ChildrenBuilder<T,B>>, org.refcodes.mixin.ChildrenAccessor.ChildrenMutator<T extends Object>, org.refcodes.mixin.ChildrenAccessor.ChildrenProperty<T extends Object>
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.LengthAccessor
org.refcodes.mixin.LengthAccessor.LengthBuilder<B extends org.refcodes.mixin.LengthAccessor.LengthBuilder<B>>, org.refcodes.mixin.LengthAccessor.LengthMutator, org.refcodes.mixin.LengthAccessor.LengthProperty
-
Nested classes/interfaces inherited from interface org.refcodes.serial.Section
Section.SectionMixin
-
Nested classes/interfaces inherited from interface org.refcodes.serial.Transmission
Transmission.TransmissionMixin
-
-
Constructor Summary
Constructors Constructor Description SectionComposite(Class<ALLOC> aAllocSegmentClass, Class<CHILD> aSegmentClass)
Constructs aSectionComposite
.SectionComposite(Class<ALLOC> aAllocSegmentClass, Class<CHILD> aSegmentClass, CHILD... aSegmentArray)
Constructs aSectionComposite
containing the providedAllocSectionDecoratorSegment
elements.SectionComposite(org.refcodes.factory.TypeFactory<ALLOC> aAllocSegmentFactory, org.refcodes.factory.TypeFactory<CHILD> aSegmentFactory)
Constructs aSectionComposite
containing the providedAllocSectionDecoratorSegment
elements and using the provided factories for creatingSegment
andSection
instances.SectionComposite(org.refcodes.factory.TypeFactory<ALLOC> aAllocSegmentFactory, org.refcodes.factory.TypeFactory<CHILD> aSegmentFactory, CHILD... aSegmentArray)
Constructs aSectionComposite
containing the providedAllocSectionDecoratorSegment
elements and using the provided factories for creatingSegment
andSection
instances.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
fromTransmission(Sequence aSequence, int aOffset, int aLength)
(Re-)initializes this instance with the the givenSequence
data.CHILD[]
getChildren()
int
getLength()
Determines the overall length of thisTransmission
.void
receiveFrom(InputStream aInputStream, int aLength, OutputStream aReturnStream)
(Re-)initializes this instance by receiving the accordingSequence
from the givenInputStream
.protected void
setChildren(CHILD[] aChildren)
Hook for easily setting the children.Schema
toSchema()
Retrieves theSchema
representing theTransmission
.Sequence
toSequence()
Provides theSequence
representation of thisTransmission
.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.refcodes.serial.Section
fromTransmission, fromTransmission, fromTransmission, receiveFrom, receiveFrom
-
Methods inherited from interface org.refcodes.serial.Transmission
transmitTo, transmitTo
-
Methods inherited from interface org.refcodes.serial.Transmission.TransmissionMixin
transmitTo
-
Methods inherited from interface org.refcodes.serial.TransmissionComposite
toSimpleTypeMap
-
-
-
-
Constructor Detail
-
SectionComposite
public SectionComposite(org.refcodes.factory.TypeFactory<ALLOC> aAllocSegmentFactory, org.refcodes.factory.TypeFactory<CHILD> aSegmentFactory)
Constructs aSectionComposite
containing the providedAllocSectionDecoratorSegment
elements and using the provided factories for creatingSegment
andSection
instances.
-
SectionComposite
@SafeVarargs public SectionComposite(org.refcodes.factory.TypeFactory<ALLOC> aAllocSegmentFactory, org.refcodes.factory.TypeFactory<CHILD> aSegmentFactory, CHILD... aSegmentArray)
Constructs aSectionComposite
containing the providedAllocSectionDecoratorSegment
elements and using the provided factories for creatingSegment
andSection
instances.
-
SectionComposite
public SectionComposite(Class<ALLOC> aAllocSegmentClass, Class<CHILD> aSegmentClass)
Constructs aSectionComposite
. Instances for theSegment
andSection
elements are created using the providedClass
instances.
-
SectionComposite
@SafeVarargs public SectionComposite(Class<ALLOC> aAllocSegmentClass, Class<CHILD> aSegmentClass, CHILD... aSegmentArray)
Constructs aSectionComposite
containing the providedAllocSectionDecoratorSegment
elements. Instances for theSegment
andSection
elements are created using the providedClass
instances.
-
-
Method Detail
-
toSequence
public Sequence toSequence()
Provides theSequence
representation of thisTransmission
. In case of nestedTransmission
instances, allSequence
representations from all sub-segments are accumulated to the result as well. Caution, the Transmission (or its nestedTransmission
instances) may be backed by the returnedSequence
.- Specified by:
toSequence
in interfaceTransmission
- Specified by:
toSequence
in interfaceTransmissionComposite<ALLOC extends AllocSectionDecoratorSegment<CHILD>>
- Returns:
- The according instance's
Sequence
.
-
toSchema
public Schema toSchema()
Retrieves theSchema
representing theTransmission
. Retrieving aSchema
is useful when analyzing and debugging data structures such as aAllocSectionDecoratorSegment
instance to help document, learn and verify on the structure (as well as the content) of that veryAllocSectionDecoratorSegment
.- Specified by:
toSchema
in interfaceTransmission
- Specified by:
toSchema
in interfaceTransmissionComposite<ALLOC extends AllocSectionDecoratorSegment<CHILD>>
- Returns:
- The
Schema
representation of the implementing type for debugging and verification (or documentation) purposes.
-
getLength
public int getLength()
Determines the overall length of thisTransmission
. In case of nestedTransmission
instances, all length values from all sub-segments are accumulated to the result as well.- Specified by:
getLength
in interfaceorg.refcodes.mixin.LengthAccessor
- Specified by:
getLength
in interfaceTransmission
- Specified by:
getLength
in interfaceTransmissionComposite<ALLOC extends AllocSectionDecoratorSegment<CHILD>>
- Returns:
- The (overall) length of the
Transmission
(including any sub-segments).
-
getChildren
public CHILD[] getChildren()
- Specified by:
getChildren
in interfaceorg.refcodes.mixin.ChildrenAccessor<ALLOC extends AllocSectionDecoratorSegment<CHILD>>
-
fromTransmission
public void fromTransmission(Sequence aSequence, int aOffset, int aLength) throws TransmissionException
(Re-)initializes this instance with the the givenSequence
data.- Specified by:
fromTransmission
in interfaceSection
- Parameters:
aSequence
- TheSequence
data from which to (re-)initialize this instance.aOffset
- The offset where to start processing the providedSequence
.aLength
- The length of data assigned by theSequence
.- Throws:
TransmissionException
- thrown in case a givenSequence
cannot be processed.
-
receiveFrom
public void receiveFrom(InputStream aInputStream, int aLength, OutputStream aReturnStream) throws IOException, TransmissionException
(Re-)initializes this instance by receiving the accordingSequence
from the givenInputStream
. Implementations providing error correction methods use the provided feedbackOutputStream
to do some sort of "stop-and-wait ARQ" or apply similar methods to ensure correctness of the received data.- Specified by:
receiveFrom
in interfaceSection
- Specified by:
receiveFrom
in interfaceSection.SectionMixin
- Parameters:
aInputStream
- TheInputStream
from which to read the instance's (re-)initializationSequence
from.aLength
- The length of data assigned by the byte array.aReturnStream
- AnOutputStream
being the return channel to handle "stop-and-wait ARQ" or the like in case of a bidirectional connection. Can be null in case we have a unidirectional connection.- Throws:
IOException
- thrown in case reading data from theInputStream
caused problems.TransmissionException
- thrown in case a givenInputStream
bytes cannot be processed.
-
setChildren
protected void setChildren(CHILD[] aChildren)
Hook for easily setting the children.- Parameters:
aChildren
- The children to be set.
-
-