Class FlistToXML

java.lang.Object
com.portal.pcm.FlistToXML
All Implemented Interfaces:
XMLConstants

public abstract class FlistToXML extends Object implements XMLConstants
FlistToXML converts an flist to XML document. To use, get an instance of converter and specify the flist to convert to xml via convert. The XML document can be retrieved as a org.w3c.dom.Document object using getXMLDoc, as a string using getXMLDocAsString or written to a file using serializeToFile. Note: This converter currently supports two formats: PIN_XML_BY_SHORT_NAME and PIN_XML_TYPE. It is also possible to invoke this converter from the command line. See main method for usage.
  • Field Details

    • mDoc

      protected Document mDoc
    • INPUT_FLIST

      public static final int INPUT_FLIST
      Used in the convert() method - indicates that the given FList is the input FList for the given opcode.
      See Also:
    • OUTPUT_FLIST

      public static final int OUTPUT_FLIST
      Used in the convert() method - indicates that the given FList is the output FList for the given opcode.
      See Also:
    • NEWLINE

      protected static final String NEWLINE
      See Also:
  • Constructor Details

    • FlistToXML

      protected FlistToXML()
    • FlistToXML

      protected FlistToXML(Map<String,String> fieldMap)
      Instantiate Flist to XML converter. The constructor is protected, use getInstance factory method to get an appropriate instance.

      Flists can be converted to two XML formats: XMLConstants.PIN_XML_BY_SHORT_NAME and XMLConstants.PIN_XML_TYPE. XML types are defined in XMLConstants. *

      See Also:
  • Method Details

    • getInstance

      public static FlistToXML getInstance()
      Factory method to get an instance of the converter to default, PIN_XML_BY_SHORT_NAME, XML format.
    • getInstance

      public static FlistToXML getInstance(int xmlType)
      Factory method to get an instance of the converter for specified, XML format.
      Parameters:
      xmlType - Known XML types are defined in XMLConstants. Two XML formats are currently supports: XMLConstants.PIN_XML_BY_SHORT_NAME and XMLConstants.PIN_XML_TYPE
    • getInstance

      public static FlistToXML getInstance(Map<String,String> fieldMap)
      Factory method to get an instance of the converter for specified, XML format.
      Parameters:
      fieldMap - A mapping between PIN_FLD names and custom names. To be used during XML transformation.
    • getInstance

      public static FlistToXML getInstance(int xmlType, Map<String,String> fieldMap)
      Factory method to get an instance of the converter for specified, XML format.
      Parameters:
      xmlType - Known XML types are defined in XMLConstants. Two XML formats are currently supports: XMLConstants.PIN_XML_BY_SHORT_NAME and XMLConstants.PIN_XML_TYPE
      fieldMap - A mapping between PIN_FLD names and custom names. To be used during XML transformation.
    • convert

      public void convert(FList f) throws ParserConfigurationException, EBufException
      Convert the specified flist to XML.
      Parameters:
      f - The FList to convert to XML
      Throws:
      ParserConfigurationException
      EBufException
    • convertNew

      public void convertNew(FList f) throws ParserConfigurationException, EBufException
      Convert the specified flist to XML, with New schema
      Parameters:
      f - The FList to convert to XML
      Throws:
      ParserConfigurationException
      EBufException
    • convert

      public void convert(FList f, String opcode, int type) throws ParserConfigurationException, EBufException
      Convert the specified flist to XML. If the opcode name is specified, the output XML will contain a reference to the schema for that opcode which will enable the XML to be validated.
      Parameters:
      f - The FList to convert to XML
      opcode - The opcode this FList is for - may be null. If null then a schema reference is not generated
      type - Either FlistToXML.INPUT_FLIST or FlistToXML.OUTPUT_FLIST to indicate if the FList is the input or output FList for the opcode.
      Throws:
      ParserConfigurationException
      EBufException
    • convertNew

      public void convertNew(FList f, String opcode, int type) throws ParserConfigurationException, EBufException
      Convert the specified flist to XML with New Schema.
      Parameters:
      f - The FList to convert to XML
      opcode - The opcode this FList is for - may be null. If null then a schema reference is not generated
      type - Either FlistToXML.INPUT_FLIST or FlistToXML.OUTPUT_FLIST to indicate if the FList is the input or output FList for the opcode.
      Throws:
      ParserConfigurationException
      EBufException
    • getXMLDoc

      public Document getXMLDoc()
      Returns the created XML document as org.w3c.dom.Document object.
      Returns:
      XML document created from the flist.
    • getXMLDocAsString

      public String getXMLDocAsString()
      Returns the created XML document as a string.
      Returns:
      String of the XML document created from the flist or null if problems are encountered.
    • serializeToFile

      public void serializeToFile(File file) throws TransformerException
      Serialize XML document to a file.
      Parameters:
      file - Where to serialize
      Throws:
      TransformerException
    • createElement

      protected abstract Element createElement(Field field, int is_new)
      This method should create an element for a flist field. Since the content of elements vary based on the type of XML format constructed, subclasses override this method and output correct contents.
      Parameters:
      field - Flist field for which an element node is being created
      is_new - int to specify which schema to use, (=1 for new schema).
      Returns:
      DOM Element object for the field. The contents are then added to the element.
      See Also:
      • FlistToXMLByType
      • FlistToXMLShortName
      • FlistToXMLNotification
    • main

      public static void main(String[] args)
      Invokes the flist to XML converter from the command line. Outputs the XML to the console and writes it to file. The output filename is the input filename with ".bytype.txt" or ".byshortname.txt" appended to it.

      Usage: java com.portal.pcm.FlistToXML [-n]ew [-type|-shortname] flistfilename

    • getNameXMLForm

      protected String getNameXMLForm(String source)
      This method converts the input name to Hungarian notation and also removes the prefix 'PIN_', like PCM_ABC_XYZ to AbcXyz
      Parameters:
      source - Input date in srcFormat
      Returns:
      converted String in XML notation
    • setArrayAttributes

      protected void setArrayAttributes(Element arrayElem, int arrayIndex)
      Method to set attributes for Array element.
      Parameters:
      arrayElem - Array element being processed.
      arrayIndex - Index of the array element.
    • setByteBufferAttributes

      protected void setByteBufferAttributes(Element elem, ByteBuffer bb)
      Method to set attributes for ByteBuffer Buffer field type.
      Parameters:
      elem - ByteBuffer Element.
      bb - ByteBuffer value.
    • setFileBufferAttributes

      protected void setFileBufferAttributes(Element elem, FileBuffer fb)
      Method to set attributes for FileBuffer Buffer type.
      Parameters:
      elem - FileBuffer element.
      fb - FileBuffer value.
    • getMappedFieldName

      protected String getMappedFieldName(String pinFldName)
      This method checks to see if the given field is specified in a map
      Parameters:
      pinFldName - Field name of the form PIN_FLD_NAME.
      Returns:
      Returns the mapped tag for the input PIN_FLD field name.