com.h3c.of.lib.mp

## Class MpBodyFactory

- java.lang.Object
- - com.h3c.of.lib.AbstractFactory
  - - com.h3c.of.lib.mp.MpBodyFactory

-     public class MpBodyFactory
      extends AbstractFactory

  Provides facilities for parsing, creating and encoding `MultipartBody` instances.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `DESC_STR_LEN` Description string field length.
    `static int` | `SERIAL_NUM_LEN` Serial number string field length.
    `static int` | `TABLE_NAME_LEN` Table name string field length.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static MultipartBody` | `createReplyBody(ProtocolVersion pv, MultipartType type)` Creates the mutable multipart reply body for the given type and protocol version.
    `static MultipartBody` | `createReplyBodyElement(ProtocolVersion pv, MultipartType type)` Creates the mutable multipart reply body array element for the given type and protocol version.
    `static MultipartBody` | `createRequestBody(ProtocolVersion pv, MultipartType type)` Creates the mutable multipart request body for the given type, for the given protocol version.
    `static void` | `encodeReplyBody(MultipartBody body, OfPacketWriter pkt)` Encodes a multipart reply body (if it is not null), writing it into the supplied buffer.
    `static void` | `encodeRequestBody(MultipartBody body, OfPacketWriter pkt)` Encodes a multipart request body (if it is not null), writing it into the supplied buffer.
    `static MultipartType` | `getType(MultipartBody body)` Returns the multipart-type corresponding to the specified multipart body instance.
    `static MultipartBody` | `parseReplyBody(MultipartType type, OfPacketReader pkt, ProtocolVersion pv)` Parses a multipart reply message body from the supplied buffer.
    `static MultipartBody` | `parseRequestBody(MultipartType type, OfPacketReader pkt, ProtocolVersion pv)` Parses a multipart request message body from the supplied buffer.
    `static void` | `setReplyType(OfmMutableMultipartReply msg, MultipartType type)` Sets the type in the message header, and adds the appropriate body.
    `static void` | `setRequestType(OfmMutableMultipartRequest msg, MultipartType type)` Sets the type in the message header, and adds the appropriate body, if any.
    `protected String` | `tag()` Returns an identifying tag for the multipart body factory.

    - ### Methods inherited from class com.h3c.of.lib.AbstractFactory

      `mpe, mpe, mpe, mpe`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### DESC_STR_LEN

          public static final int DESC_STR_LEN

      Description string field length.
      See Also:
        Constant Field Values

    - #### SERIAL_NUM_LEN

          public static final int SERIAL_NUM_LEN

      Serial number string field length.
      See Also:
        Constant Field Values

    - #### TABLE_NAME_LEN

          public static final int TABLE_NAME_LEN

      Table name string field length.
      See Also:
        Constant Field Values

  - ### Method Detail

    - #### tag

          protected String tag()

      Returns an identifying tag for the multipart body factory.
      Specified by:
        `tag` in class `AbstractFactory`
      Returns:
        an identifying tag

    - #### parseRequestBody

          public static MultipartBody parseRequestBody(MultipartType type,
                                       OfPacketReader pkt,
                                       ProtocolVersion pv)
                                                throws MessageParseException

      Parses a multipart request message body from the supplied buffer. Note that this method causes the reader index of the underlying packet reader to be advanced by the length of the body.
      Parameters:
        `type` - the type of request body to parse
        `pkt` - the data buffer
        `pv` - the protocol version
      Returns:
        a parsed request message body
      Throws:
        `MessageParseException` - if unable to parse the body

    - #### parseReplyBody

          public static MultipartBody parseReplyBody(MultipartType type,
                                     OfPacketReader pkt,
                                     ProtocolVersion pv)
                                              throws MessageParseException

      Parses a multipart reply message body from the supplied buffer. Note that this method causes the reader index of the underlying packet reader to be advanced by the length of the body.
      Parameters:
        `type` - the type of reply body to parse
        `pkt` - the data buffer
        `pv` - the protocol version
      Returns:
        a parsed reply message body
      Throws:
        `MessageParseException` - if unable to parse the body

    - #### setRequestType

          public static void setRequestType(OfmMutableMultipartRequest msg,
                            MultipartType type)

      Sets the type in the message header, and adds the appropriate body, if any.
      Parameters:
        `msg` - the mutable request
        `type` - its required type

    - #### setReplyType

          public static void setReplyType(OfmMutableMultipartReply msg,
                          MultipartType type)

      Sets the type in the message header, and adds the appropriate body.
      Parameters:
        `msg` - the mutable request
        `type` - its required type

    - #### createRequestBody

          public static MultipartBody createRequestBody(ProtocolVersion pv,
                                        MultipartType type)

      Creates the mutable multipart request body for the given type, for the given protocol version.
      Parameters:
        `pv` - the protocol version
        `type` - the required multipart request type
      Returns:
        the mutable body
      Throws:
        `VersionNotSupportedException` - if the version is not supported
        `NullPointerException` - either parameter is null
        `IllegalArgumentException` - if the type does not have a body

    - #### createReplyBody

          public static MultipartBody createReplyBody(ProtocolVersion pv,
                                      MultipartType type)

      Creates the mutable multipart reply body for the given type and protocol version.
      Parameters:
        `pv` - the protocol version
        `type` - the required multipart reply type
      Returns:
        the mutable body
      Throws:
        `NullPointerException` - if either paramter is null
        `VersionNotSupportedException` - if the version is not supported

    - #### createReplyBodyElement

          public static MultipartBody createReplyBodyElement(ProtocolVersion pv,
                                             MultipartType type)

      Creates the mutable multipart reply body array element for the given type and protocol version.
      Parameters:
        `pv` - the protocol version
        `type` - the required multipart reply element type
      Returns:
        the mutable element
      Throws:
        `NullPointerException` - if either paramter is null
        `VersionNotSupportedException` - if the version is not supported

    - #### encodeRequestBody

          public static void encodeRequestBody(MultipartBody body,
                               OfPacketWriter pkt)
                                        throws IncompleteStructureException

      Encodes a multipart request body (if it is not null), writing it into the supplied buffer. Note that this method causes the writer index of the underlying `PacketBuffer` to be advanced by the length of the body.
      Parameters:
        `body` - the body (may be null)
        `pkt` - the buffer into which the body is to be written
      Throws:
        `IncompleteStructureException` - if the body is incomplete

    - #### encodeReplyBody

          public static void encodeReplyBody(MultipartBody body,
                             OfPacketWriter pkt)
                                      throws IncompleteStructureException

      Encodes a multipart reply body (if it is not null), writing it into the supplied buffer. Note that this method causes the writer index of the underlying `PacketBuffer` to be advanced by the length of the body.
      Parameters:
        `body` - the body (may be null)
        `pkt` - the buffer into which the body is to be written
      Throws:
        `IncompleteStructureException` - if encoding encounters incomplete or malformed structure

    - #### getType

          public static MultipartType getType(MultipartBody body)

      Returns the multipart-type corresponding to the specified multipart body instance. If the body is an `array`, returns the type corresponding to the elements of the array.
      Parameters:
        `body` - the body instance
      Returns:
        the corresponding type constant

Copyright © 2014. All Rights Reserved.