Class EncodableList<E>

  • Type Parameters:
    E - list element type.
    All Implemented Interfaces:
    Encodable, Iterable<E>, Collection<E>, List<E>

    public abstract class EncodableList<E>
    extends Object
    implements List<E>, Encodable

    Generic implementation of a list structure that can be stored in SLEE CMP fields with sensible serialisation semantics. This class essentially provides a layer on top of some other list implementation, delegating method calls on the List interface through to the underlying list implementation, while handling the serialisation and deserialisation of the list’s state via the contract provided by the Encodable interface.

    In order to use this list, a subclass must be implemented that:

    • Provides at least a public constructor satisfying the contract of the Encodable interface.

    • Implements the abstract newInstance, writeValue, and readValue methods defined in this class.

    This implementation provides the ability to specify what type of list structure to use as a backing store from a set of predefined types. A subclass may use an alternative list implementation by:

    Since:
    Rhino 2.4.0
    • Constructor Detail

      • EncodableList

        public EncodableList​(EncodableList.BackingStore backingStore)

        Create an EncodableList using the specified backing store.

        Parameters:
        backingStore - the backing store to use.
      • EncodableList

        protected EncodableList​(EncodableList.BackingStore backingStore,
                                List<E> list)

        Create an EncodableList using the specified backing store and list. This constructor exists primarily to facilitate the implementation of subList(int, int), but may also be used to create an EncodableList that wraps a pre-existing list.

        Parameters:
        backingStore - the backing store to use.
        list - the initial list state.
      • EncodableList

        protected EncodableList​(DataInput in,
                                ClassLoader cl,
                                DecoderUtils utils)
                         throws IOException

        Creates an EncodableList with state restored from the specified input stream.

        Parameters:
        in - the input stream to read list state from.
        cl - classloader that can be used to resolve class dependencies.
        utils - additional utility decoding functions.
        Throws:
        IOException - if an I/O error occurs.
    • Method Detail

      • fromStream

        protected void fromStream​(DataInput in,
                                  ClassLoader cl,
                                  DecoderUtils utils)
                           throws IOException

        Populate list elements with state restored from the specified input stream. This method typically would only be used after the list has been cleared, and can be used to recycle the underlying list object.

        Warning: This method can only be used to deserialise a list serialised using the toStream(DataOutput, EncoderUtils) method. It will not work with a list serialised using the encode(DataOutput, EncoderUtils) method.

        Parameters:
        in - the input stream to read list state from.
        cl - classloader that can be used to resolve class dependencies.
        utils - additional utility decoding functions.
        Throws:
        IOException - if an I/O error occurs.
      • encode

        public void encode​(DataOutput out,
                           EncoderUtils utils)
                    throws IOException
        Description copied from interface: Encodable

        Encode the state of this object to the given data output stream.

        Specified by:
        encode in interface Encodable
        Parameters:
        out - the data output stream to encode the value to.
        utils - additional utility encoding functions that may be useful to the encoder.
        Throws:
        IOException - if an I/O error occurs.
      • add

        public boolean add​(E e)
        Specified by:
        add in interface Collection<E>
        Specified by:
        add in interface List<E>
      • addAll

        public boolean addAll​(int index,
                              Collection<? extends E> c)
        Specified by:
        addAll in interface List<E>
      • get

        public E get​(int index)
        Specified by:
        get in interface List<E>
      • set

        public E set​(int index,
                     E element)
        Specified by:
        set in interface List<E>
      • add

        public void add​(int index,
                        E element)
        Specified by:
        add in interface List<E>
      • remove

        public E remove​(int index)
        Specified by:
        remove in interface List<E>
      • subList

        public List<E> subList​(int fromIndex,
                               int toIndex)
        Specified by:
        subList in interface List<E>
      • newListInstance

        protected List<E> newListInstance​(EncodableList.BackingStore backingStore)

        Create a new list instance for the backing store. The default behaviour of this method simply returns the value of backingStore.createList().

        Parameters:
        backingStore - the backing store originally passed in to the class constructor when the EncodableList was first created.
        Returns:
        a list.
      • newInstance

        protected abstract EncodableList<E> newInstance​(EncodableList.BackingStore backingStore,
                                                        List<E> list)

        Create a new instance of this EncodableList wrapping the specified list.

        Parameters:
        backingStore - the backing store originally passed in to the class constructor when this EncodableList was first created.
        list - the list that the new EncodableList instance should wrap.
        Returns:
        a new EncodableList instance wrapping the list
      • writeElement

        protected abstract void writeElement​(E element,
                                             DataOutput out,
                                             EncoderUtils utils)
                                      throws IOException

        Serialise the specified list element to the output stream.

        Parameters:
        element - the list element, may be null if the underlying list supports null keys and manageNullElements() return false.
        out - the output stream to write the element state to.
        utils - additional utility encoding functions that may be useful when serialising the element.
        Throws:
        IOException - if an I/O error occurs.
      • readElement

        protected abstract E readElement​(DataInput in,
                                         ClassLoader cl,
                                         DecoderUtils utils)
                                  throws IOException

        Deserialise a list element from the input stream.

        Parameters:
        in - the input stream to read the element state from.
        cl - classloader that can be used to resolve class dependencies.
        utils - additional utility decoding functions that may be useful when deserialising the element.
        Returns:
        a list element.
        Throws:
        IOException - if an I/O error occurs.