Class AbstractPropertiesBasedFactory<T,​N extends NamedNumber<?,​?>>

    • Method Summary

      Modifier and Type Method Description
      protected abstract java.lang.String getStaticFactoryMethodName()  
      protected abstract java.lang.Class<? extends T> getTargetClass​(N number)  
      protected abstract java.lang.Class<? extends T> getUnknownClass()  
      protected abstract T newIllegalData​(byte[] rawData, int offset, int length, IllegalRawDataException cause)
      This method is called when IllegalRawDataException is thrown during instantiating a class getTargetClass(N) or getUnknownClass() return and create an object representing an illegal packet or packet field.
      T newInstance​(byte[] rawData, int offset, int length, N... numbers)
      A factory method to build a packet or a packet field.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AbstractPropertiesBasedFactory

        public AbstractPropertiesBasedFactory()
    • Method Detail

      • newInstance

        public T newInstance​(byte[] rawData,
                             int offset,
                             int length,
                             N... numbers)
        Description copied from interface: PacketFactory
        A factory method to build a packet or a packet field. The numbers are used as hints during the build. If no number is given, this method usually return an object which just wraps the specified part of the rawData without dissection. If one or more numbers are given, this method attempts to find a concrete class corresponding to the number for each of them in the order given. The class this method first find will be instantiated and returned. If no class is found, this method behaves in the same way as no number was given.

        This method doesn't throw IllegalRawDataException. Instead, if an IllegalRawDataException occurred during a packet dissection, this instantiates IllegalRawDataPacket (if T is Packet) or IllegalRawDataHolder (if T is not Packet) and returns it.

        Specified by:
        newInstance in interface PacketFactory<T,​N extends NamedNumber<?,​?>>
        Parameters:
        rawData - a byte array including data this method will use for building a T instance.
        offset - offset of the data in the rawData.
        length - length of the data. The object to be returned is not required to use or represent entire data. It means this length is not required to be exactly same as the returning object's length, but is required to be not smaller than it.
        numbers - NamedNumber instances this method will refer to in order to decide which concrete class to instantiate during building a T instance.
        Returns:
        a new packet or packet field object.
      • getTargetClass

        protected abstract java.lang.Class<? extends T> getTargetClass​(N number)
        Parameters:
        number - number
        Returns:
        the class that is supposed to be instantiated for the given number.
      • getUnknownClass

        protected abstract java.lang.Class<? extends T> getUnknownClass()
        Returns:
        the class that is supposed to be instantiated for numbers this factory doesn't support.
      • getStaticFactoryMethodName

        protected abstract java.lang.String getStaticFactoryMethodName()
        Returns:
        the name of the static factory method to instantiate classes getTargetClass(N) and getUnknownClass() return.
      • newIllegalData

        protected abstract T newIllegalData​(byte[] rawData,
                                            int offset,
                                            int length,
                                            IllegalRawDataException cause)
        This method is called when IllegalRawDataException is thrown during instantiating a class getTargetClass(N) or getUnknownClass() return and create an object representing an illegal packet or packet field.
        Parameters:
        rawData - rawData
        offset - offset
        length - length
        cause - cause
        Returns:
        a new object.