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
,org.refcodes.mixin.Schemable
,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>
A
SectionComposite
is a Section
consisting of Section
elements of a variable length each: Each Section
element in the
composite need not be of the same size. This is achieved by wrapping each
Section
inside a dedicated AllocSectionDecoratorSegment
being
a Segment
providing the resulting Section
's length (with all
the composite's Section
instances).- See Also:
-
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
ConstructorDescriptionSectionComposite
(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
Modifier and TypeMethodDescriptionvoid
fromTransmission
(Sequence aSequence, int aOffset, int aLength) (Re-)initializes this instance with the the givenSequence
data.CHILD[]
int
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.toSchema()
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 Details
-
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
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 Details
-
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
- Specified by:
toSchema
in interfaceorg.refcodes.mixin.Schemable
- Specified by:
toSchema
in interfaceTransmission
- Specified by:
toSchema
in interfaceTransmissionComposite<ALLOC extends AllocSectionDecoratorSegment<CHILD>>
-
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
- 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
Hook for easily setting the children.- Parameters:
aChildren
- The children to be set.
-