Package com.verisign.epp.codec.gen

## Class EPPCodec

- java.lang.Object
- - com.verisign.epp.codec.gen.EPPCodec

-     public class EPPCodec
      extends java.lang.Object

  Singleton class to encode and decode `EPPMessage` instances to and from DOM Documents. `EPPCodec` encapsulates the details of the EPP and is capable of handling new EPP Command Mappings through the use of `EPPFactory`.
  Utility methods are provided for decoding specific concrete `EPPMessages` including:
  - `EPPCommand` - EPP Command encoded by client and decoded by server
  - `EPPResponse` - EPP Response encoded by server and decoded by client
  - `EPPGreeting` - EPP Greeting encoded by server and decoded by client
  - `EPPHello` - EPP Hello encoded by client and decoded by server
  See Also:
    `EPPFactory`, `EPPMessage`, `EPPGreeting`, `EPPHello`, `EPPCommand`, `EPPResponse`

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static java.lang.String` | `NS` | XML namespace for EPP
    `static java.lang.String` | `NS_SCHEMA` | EPP general XML schema location.
    `static java.lang.String` | `VERSION` | version of the EPP.

  - ### Constructor Summary

    Constructors
    Modifier | Constructor | Description
    --- | --- | ---
    `protected` | `EPPCodec()` | allocates the Singleton `EPPCodec` instance.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `EPPMessage` | `decode​(org.w3c.dom.Document aDocument)` | decodes a DOM Document into a concrete `EPPMessage`.
    `EPPMessage` | `decode​(org.w3c.dom.Element root)` | decodes a DOM Element tree into a concrete `EPPMessage`.
    `EPPCommand` | `decodeCommand​(org.w3c.dom.Document aDocument)` | utility method that will decode a DOM Document and return an `EPPCommand` instance.
    `EPPGreeting` | `decodeGreeting​(org.w3c.dom.Document aDocument)` | utility method that will decode a DOM Document and return an `EPPGreeting` instance.
    `EPPHello` | `decodeHello​(org.w3c.dom.Document aDocument)` | utility method that will decode a DOM Document and return an `EPPHello` instance.
    `EPPResponse` | `decodeResponse​(org.w3c.dom.Document aDocument)` | utility method that will decode a DOM Document and return an `EPPResponse` instance.
    `org.w3c.dom.Document` | `encode​(EPPMessage aMessage)` | encodes a concrete `EPPMessage` into a DOM Document.
    `static EPPCodec` | `getInstance()` | gets the Singleton instance of `EPPCodec`.
    `void` | `init​(java.util.Vector<java.lang.String> someFactories)` | Initialize the Singleton instance.
    `void` | `init​(java.util.Vector<java.lang.String> someFactories, java.util.Vector<java.lang.String> extensionFactories)` | Initialize the Singleton instance.

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

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

- - ### Field Detail

    - #### VERSION

          public static final java.lang.String VERSION

      version of the EPP. This is mapped to the version of the general EPP Specification.
      See Also:
        Constant Field Values

    - #### NS

          public static final java.lang.String NS

      XML namespace for EPP
      See Also:
        Constant Field Values

    - #### NS_SCHEMA

          public static final java.lang.String NS_SCHEMA

      EPP general XML schema location.
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### EPPCodec

          protected EPPCodec()

      allocates the Singleton `EPPCodec` instance. The XML Parser used to construct the DOM Document is initialized to be namespace aware and to not validate. JAXP is used to instantiate the concrete XML Parser, and the XML Parser is only used during an `encode` operation.

  - ### Method Detail

    - #### getInstance

          public static EPPCodec getInstance()

      gets the Singleton instance of `EPPCodec`. `EPPCodec` follows the Singleton Design Pattern.
      Returns:
        Singleton instance of `EPPCodec`.

    - #### init

          public void init​(java.util.Vector<java.lang.String> someFactories)
                    throws EPPCodecException

      Initialize the Singleton instance. This method initializes all of the components used by `EPPCodec`.
      A `Vector` of concrete `EPPMapFactory` fully qualified class names are specified to initialize the `EPPCodec` with the supported EPP Command Mappings. For example, support for the Domain Command Mapping is added to `EPPCodec` by included the class name "com.verisign.epp.codec.domain.EPPDomainMapFactory" in the `someFactories` argument. The following code shows the steps to include the Domain Command Mapping and the Host Command Mapping in the `EPPCodec`.

           Vector theFactories = new Vector();
           theFactories.addElement("com.verisign.epp.codec.domain.EPPDomainMapFactory");
           theFactories.addElement("com.verisign.epp.codec.host.HostMapFactory");
           EPPCodec.getInstance().init(theFactories);

      Parameters:
        `someFactories` - a Vector of concrete `EPPMapFactory` fully qualified class names.
      Throws:
        `EPPCodecException` - Error initializing the `EPPCodec`

    - #### init

          public void init​(java.util.Vector<java.lang.String> someFactories,
                           java.util.Vector<java.lang.String> extensionFactories)
                    throws EPPCodecException

      Initialize the Singleton instance. This method initializes all of the components used by `EPPCodec`. A`Vector` of concrete `EPPCommandResponseExtension` of fully qualified class names are specified to initialize the `EPPCodec` with the supported Command Response Extensions. For example support for the Protocol Level Extensiosn and CommanResponse Extensions is added to `EPPCodec` by including the class names namely "com.verisign.epp.codec.gen.EPPProtocolExtensions", "com.verisign.epp.codec.gen.EPPCommandResponseExtensions" in the `extensionFactories` argument.The follwoign code shows the steps to the ProtcolExtensions and CommandResponse Extensions in the `EPPCodec`.

            Vector protocolExts = EPPEnv.getProtocolExtensions();
            Vector commandExts=EPPEnv.getCmdResponseExtensions();
            Vector extensionsVector=new Vector()
            extensionsVector.addElement((String)protocolExts.elementAt(i));
            extensionsVector.addElement((String)commandExts.elementAt(j));
            Now instantiate the Codec instance with both the mapfactories and extension factories
            EPPCodec.getInstance().init(EPPEnv.getMapFactories(),extensionsVector);

      Parameters:
        `someFactories` - a Vector of concrete `EPPMapFactory` fully qualified class names.
        `extensionFactories` - a Vector of concrete `EPPProtocolExtension` and `EPPCommandResponseExtesnsions`
      Throws:
        `EPPCodecException` - Error initializing the `EPPCodec`

    - #### encode

          public org.w3c.dom.Document encode​(EPPMessage aMessage)
                                      throws EPPEncodeException

      encodes a concrete `EPPMessage` into a DOM Document.
      Parameters:
        `aMessage` - Concrete `EPPMessage` to encode.
      Returns:
        Encoded DOM Document of representing the `EPPMessage`
      Throws:
        `EPPEncodeException` - Error encoding the `EPPMessage`.

    - #### decode

          public EPPMessage decode​(org.w3c.dom.Document aDocument)
                            throws EPPDecodeException

      decodes a DOM Document into a concrete `EPPMessage`.
      Parameters:
        `aDocument` - DOM Document to decode into a concrete `EPPMessage`.
      Returns:
        Encoded concrete `EPPMessage`.
      Throws:
        `EPPDecodeException` - Error decoding the DOM Document.

    - #### decode

          public EPPMessage decode​(org.w3c.dom.Element root)
                            throws EPPDecodeException,
                                   EPPComponentNotFoundException

      decodes a DOM Element tree into a concrete `EPPMessage`.
      Parameters:
        `root` - Root EPP element to decode from
      Returns:
        Encoded concrete `EPPMessage`.
      Throws:
        `EPPDecodeException` - Error decoding the DOM Document.
        `EPPComponentNotFoundException` - A component could not be found which could be a command, response, or extension component.

    - #### decodeCommand

          public EPPCommand decodeCommand​(org.w3c.dom.Document aDocument)
                                   throws EPPDecodeException

      utility method that will decode a DOM Document and return an `EPPCommand` instance. An `EPPDecodeException` will be thrown if the decoded `EPPMessage` is not an `EPPCommand`.
      Parameters:
        `aDocument` - DOM Document to decode into an `EPPCommand`.
      Returns:
        Encoded concrete `EPPCommand`.
      Throws:
        `EPPDecodeException` - Error decoding the DOM Document or `EPPMessage` is not an `EPPCommand`

    - #### decodeResponse

          public EPPResponse decodeResponse​(org.w3c.dom.Document aDocument)
                                     throws EPPDecodeException

      utility method that will decode a DOM Document and return an `EPPResponse` instance. An `EPPDecodeException` will be thrown if the decoded `EPPMessage` is not an `EPPResponse`.
      Parameters:
        `aDocument` - DOM Document to decode into an `EPPResponse`.
      Returns:
        Encoded concrete `EPPResponse`.
      Throws:
        `EPPDecodeException` - Error decoding the DOM Document or `EPPMessage` is not an `EPPResponse`

    - #### decodeGreeting

          public EPPGreeting decodeGreeting​(org.w3c.dom.Document aDocument)
                                     throws EPPDecodeException

      utility method that will decode a DOM Document and return an `EPPGreeting` instance. An `EPPDecodeException` will be thrown if the decoded `EPPMessage` is not an `EPPGreeting`.
      Parameters:
        `aDocument` - DOM Document to decode into an `EPPGreeting`.
      Returns:
        Encoded concrete `EPPGreeting`.
      Throws:
        `EPPDecodeException` - Error decoding the DOM Document or `EPPMessage` is not an `EPPGreeting`

    - #### decodeHello

          public EPPHello decodeHello​(org.w3c.dom.Document aDocument)
                               throws EPPDecodeException

      utility method that will decode a DOM Document and return an `EPPHello` instance. An `EPPDecodeException` will be thrown if the decoded `EPPMessage` is not an `EPPHello`.
      Parameters:
        `aDocument` - DOM Document to decode into an `EPPHello`.
      Returns:
        Encoded concrete `EPPHello`.
      Throws:
        `EPPDecodeException` - Error decoding the DOM Document or `EPPMessage` is not an `EPPHello`