home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Java / Java.zip / mqaoad21.zip / EpicMessageExt.java < prev    next >
Text File  |  2003-01-13  |  14KB  |  551 lines

  1. package com.ibm.extricity.adapters.mqseries.mqak;
  2.  
  3. /**
  4.  * EpicMessageExt.java 1.0      10/6/2000
  5.  *
  6.  * The EpicMessageExt is derived from <EM>EpicMessage</EM> class.
  7.  * This class is used to extend teh ePic message for use with Extricity
  8.  *
  9.  * OCO Source Materials
  10.  *
  11.  * 5799-RNK
  12.  *
  13.  * (C) Copyright IBM Corp. 2000
  14.  *
  15.  * The source code for this program is not published
  16.  * or otherwise divested of its trade secrets,
  17.  * irrespective of what has been deposited with the
  18.  * U. S. Copyright Office.
  19.  *
  20.  * @author Thomas W. Jaworski
  21. **/
  22. public class EpicMessageExt extends com.ibm.epic.adapters.eak.mcs.EpicMessage
  23. {
  24.  
  25.    private static final char[] _HEXTBL = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' };
  26.    private static final byte[] _NO_ID = { 0x4e, 0x4f, 0x4e, 0x45 };
  27.    public static final int LMS_CORELATION_ID_MAXLEN = 24;
  28.    public static final String LMS_CORELATION_ID_NONE = null;
  29.    public static final int LMS_MESSAGE_ID_MAXLEN = 24;     // Extended transport attributes
  30.    public static final String LMS_MESSAGE_ID_NONE = null;
  31.    private String lmsCorrelationID = NO_EXTRICITYPROCESSID;
  32.    private String lmsMessageID = LMS_MESSAGE_ID_NONE;
  33.    private boolean lmsMessageIDEncoded = false;
  34.    public static final String NO_BOCORRELATIONID = new String(_NO_ID);
  35.    public static final String NO_EXTRICITYPROCESSID = new String(_NO_ID);
  36.  
  37. /**
  38.  * Parses the XML string and sets the field attribute values from the XML header.
  39.  * The xml document in string format should contain an EPIC_HEADER element.
  40.  *
  41.  * @param epicXMLMessage XML String to read all the message parameters from
  42.  *
  43.  * @exception AdapterException catch parser errors
  44.  **/
  45. public EpicMessageExt(String epicXMLMessage) throws com.ibm.epic.adapters.eak.common.AdapterException
  46. {
  47.    super(epicXMLMessage);
  48. }
  49.  
  50. /**
  51.  * Creates an empty message and sets the source ID and the message type from the input params.
  52.  * The message can be further initialized by calling any of the setXXX() methods on this
  53.  * instance.
  54.  *
  55.  * @param srcID The source application name that is considered to be sending this message
  56.  * @param messageType The type of message - may be null. This s the message type returned by getMessageType()
  57.  *
  58.  * @exception AdapterException  catch invalid initializations
  59.  * of attributes. Catch exceptions reading configuration file.
  60.  *
  61.  * @see #getMsgType()
  62.  *
  63.  **/
  64. public EpicMessageExt(String srcID,String messageType)
  65.    throws com.ibm.epic.adapters.eak.common.AdapterException
  66. {
  67.    super(srcID,messageType);
  68. }
  69.  
  70. /**
  71.  * The purpose of this constructor is to create an Epic message given a specified
  72.  * body type, body category and body data.  Body category and Body type are required,
  73.  * while Body data is optional.  As an example, Body category = event and body type =
  74.  * status change might be an event which requires no data.
  75.  *
  76.  * @param applicationName The application name creating and sending the message
  77.  * @param msgType The type of message being created (e.g. Application), may be null to use default
  78.  * @param bodyType The type of body for the message (e.g.sync_salesorder)
  79.  * @param bodyCategory The category of body for the message (e.g. OAG)
  80.  * @param bodyData The body data. This is the data that will be transmitted. It can be in any format
  81.  * but is usually expected to be XML usr data.
  82.  *
  83.  * @exception AdapterException If failures occur in called methods
  84.  *
  85.  * @see #EpicMessage( String, String )
  86.  *
  87.  */
  88. public EpicMessageExt(String applicationName, String msgType, String bodyType, String bodyCategory, String bodyData)
  89.    throws com.ibm.epic.adapters.eak.common.AdapterException
  90. {
  91.    super(applicationName,msgType,bodyType,bodyCategory,bodyData);
  92. }
  93.  
  94. /**
  95.  * Insert the method's description here.
  96.  * Creation date: (10/6/00 10:23:03 AM)
  97.  * @return java.lang.String
  98.  */
  99. public String getBOCorrelationID()
  100. {
  101.    return getCorrelationID();
  102. }
  103.  
  104. /**
  105.  * Insert the method's description here.
  106.  * Creation date: (10/6/00 10:23:03 AM)
  107.  * @return java.lang.String
  108.  */
  109. public String getDestinationComponent()
  110. {
  111.    return getDestinationLogicalID();
  112. }
  113.  
  114. /**
  115.  * Insert the method's description here.
  116.  * Creation date: (10/6/00 10:23:03 AM)
  117.  * @return java.lang.String
  118.  */
  119. public String getExtricityProcessID()
  120. {
  121.    return getTransactionID();
  122. }
  123.  
  124. /**
  125.  * Insert the method's description here.
  126.  * Creation date: (10/6/00 10:23:03 AM)
  127.  * @return java.lang.String
  128.  */
  129. public String getProtocol()
  130. {
  131.    String prot = getBodyCategory();
  132.    int pos;
  133.  
  134.    pos = prot.indexOf("_");
  135.    if(pos < 0)
  136.    {
  137.           return "";
  138.    }
  139.    else
  140.    {
  141.           return prot.substring(0,pos);
  142.    }
  143. }
  144.  
  145. /**
  146.  * Insert the method's description here.
  147.  * Creation date: (10/6/00 10:23:03 AM)
  148.  * @return java.lang.String
  149.  */
  150. public String getProtocolAndVersion()
  151. {
  152.    return getBodyCategory();
  153. }
  154.  
  155. /**
  156.  * Insert the method's description here.
  157.  * Creation date: (10/6/00 10:23:03 AM)
  158.  * @return java.lang.String
  159.  */
  160. public String getProtocolVersion()
  161. {
  162.    String prot = getBodyCategory();
  163.    int pos;
  164.  
  165.    pos = prot.indexOf("_");
  166.    if(pos < 0)
  167.    {
  168.           return "";
  169.    }
  170.    else
  171.    {
  172.           return prot.substring(pos);
  173.    }
  174. }
  175.  
  176. /**
  177.  * Insert the method's description here.
  178.  * Creation date: (10/6/00 10:23:03 AM)
  179.  * @return java.lang.String
  180.  */
  181. public void setBOCorrelationID(String val)
  182.    throws com.ibm.epic.adapters.eak.common.AdapterException
  183. {
  184.    setBOCorrelationID(val,false);
  185. }
  186.  
  187. /**
  188.  * Insert the method's description here.
  189.  * Creation date: (10/6/00 10:23:03 AM)
  190.  * @return java.lang.String
  191.  */
  192. public void setDestinationComponent(String param1)
  193.    throws com.ibm.epic.adapters.eak.common.AdapterException
  194. {
  195.    setDestinationLogicalID(param1);
  196. }
  197.  
  198. /**
  199.  * Insert the method's description here.
  200.  * Creation date: (10/6/00 10:23:03 AM)
  201.  * @return java.lang.String
  202.  */
  203. public void setExtricityProcessID(String val)
  204.    throws com.ibm.epic.adapters.eak.common.AdapterException
  205. {
  206.    setExtricityProcessID(val,true);
  207. }
  208.  
  209. /**
  210.  * Insert the method's description here.
  211.  * Creation date: (10/6/00 10:23:03 AM)
  212.  * @return java.lang.String
  213.  */
  214. public void setProtocolAndVersion(String param1)
  215.    throws com.ibm.epic.adapters.eak.common.AdapterException
  216. {
  217.    setBodyCategory(param1);
  218. }
  219.  
  220. /**
  221.  * Creates an EpicMessage with DEFAULT for the bodyType & category.
  222.  * Other fields are initialized with suitable defaults. This message
  223.  * is useable but contains no data.
  224.  *
  225.  **/
  226. public EpicMessageExt()
  227. {
  228.    super();
  229. }
  230.  
  231. /**
  232.  * Insert the method's description here.
  233.  * Creation date: (11/15/00 1:35:00 PM)
  234.  * @return byte[]
  235.  * @param correlationID java.lang.String
  236.  */
  237. public static byte[] decodeLMSCorrelationID(String correlationID)
  238. {
  239.    if(correlationID == null)
  240.    {
  241.           return null;
  242.    }
  243.    else
  244.    {
  245.           return correlationID.getBytes();
  246.    }
  247. }
  248.  
  249. /**
  250.  * Insert the method's description here.
  251.  * Creation date: (11/15/00 1:35:00 PM)
  252.  * @return byte[]
  253.  * @param MessageID java.lang.String
  254.  */
  255. public static byte[] decodeLMSMessageID(String messageID)
  256. {
  257.    if(messageID == null)
  258.    {
  259.           return null;
  260.    }
  261.    else
  262.    {
  263.           int ix;
  264.           byte[] ba = new byte[messageID.length() / 2];
  265.  
  266.           // Convert from hex representation
  267.           for(ix = 0;ix < messageID.length();ix += 2)
  268.           {
  269.                  ba[ix/2] = Integer.decode("0x"+messageID.substring(ix,ix+2)).byteValue();
  270.           }
  271.           return ba;
  272.    }
  273. }
  274.  
  275. /**
  276.  * Insert the method's description here.
  277.  * Creation date: (11/3/00 11:44:25 AM)
  278.  * @return java.lang.String
  279.  * @param idVal java.lang.String
  280.  */
  281. public static String encodeLMSCorrelationID(String idVal)
  282. {
  283.    if(idVal == null)
  284.    {
  285.           return null;
  286.    }
  287.    else if(idVal.length() > LMS_CORELATION_ID_MAXLEN)
  288.    {
  289.           char[] res = new char[LMS_CORELATION_ID_MAXLEN/2];
  290.           char[] hex = new char[LMS_CORELATION_ID_MAXLEN];
  291.           int ix;
  292.           for(ix = 0;ix < LMS_CORELATION_ID_MAXLEN/2;ix++)
  293.           {
  294.                  res[ix] = 0;
  295.           }
  296.           for(ix = 0;ix < idVal.length();ix++)
  297.           {
  298.                  res[ix % (LMS_CORELATION_ID_MAXLEN/2)] ^= idVal.charAt(ix);
  299.           }
  300.           for(ix = 0;ix < LMS_CORELATION_ID_MAXLEN/2;ix++)
  301.           {
  302.                  hex[(2*ix)] = _HEXTBL[(res[ix]/16)%16];
  303.                  hex[(2*ix)+1] = _HEXTBL[res[ix]%16];
  304.           }
  305.           return new String(hex);
  306.    }
  307.    else
  308.    {
  309.           return idVal;
  310.    }
  311. }
  312.  
  313. /**
  314.  * Insert the method's description here.
  315.  * Creation date: (10/6/00 10:23:03 AM)
  316.  * @return java.lang.String
  317.  */
  318. public byte[] getByteArrLMSCorrelationID()
  319. {
  320.    if(lmsCorrelationID == null)
  321.    {
  322.           return null;
  323.    }
  324.    else
  325.    {
  326.           return decodeLMSCorrelationID(lmsCorrelationID);
  327.    }
  328. }
  329.  
  330. /**
  331.  * Insert the method's description here.
  332.  * Creation date: (10/20/00 10:24:28 AM)
  333.  * @return java.lang.String
  334.  */
  335. public byte[] getByteArrLMSMessageID()
  336. {
  337.    if(lmsMessageID == null)
  338.    {
  339.           return null;
  340.    }
  341.    else if(this.lmsMessageIDEncoded)
  342.    {
  343.           return decodeLMSMessageID(lmsMessageID);
  344.    }
  345.    else
  346.    {
  347.           return lmsMessageID.getBytes();
  348.    }
  349. }
  350.  
  351. /**
  352.  * Insert the method's description here.
  353.  * Creation date: (10/6/00 10:23:03 AM)
  354.  * @return java.lang.String
  355.  */
  356. public String getDstTradingPartnerID()
  357. {
  358.    return getRespondToLogicalID();
  359. }
  360.  
  361. /**
  362.  * Insert the method's description here.
  363.  * Creation date: (10/20/00 10:24:28 AM)
  364.  * @return java.lang.String
  365.  */
  366. public String getLMSCorrelationID()
  367. {
  368.    return lmsCorrelationID;
  369. }
  370.  
  371. /**
  372.  * Insert the method's description here.
  373.  * Creation date: (10/20/00 10:24:28 AM)
  374.  * @return java.lang.String
  375.  */
  376. public String getLMSMessageID()
  377. {
  378.    return lmsMessageID;
  379. }
  380.  
  381. /**
  382.  * Insert the method's description here.
  383.  * Creation date: (10/18/00 4:04:42 PM)
  384.  * @return java.lang.String
  385.  */
  386. public String getProcessTransactionID()
  387. {
  388.    return getBodyType();
  389. }
  390.  
  391. /**
  392.  * Insert the method's description here.
  393.  * Creation date: (10/6/00 10:23:03 AM)
  394.  * @return java.lang.String
  395.  */
  396. public String getSrcTradingPartnerID()
  397. {
  398.    return getDeliveryCategory();
  399. }
  400.  
  401. /**
  402.  * Insert the method's description here.
  403.  * Creation date: (10/6/00 10:23:03 AM)
  404.  * @return java.lang.String
  405.  */
  406. protected void setBOCorrelationID(String val,boolean asTransport)
  407.    throws com.ibm.epic.adapters.eak.common.AdapterException
  408. {
  409.    if(asTransport)
  410.    {
  411.           setLMSCorrelationID(encodeLMSCorrelationID(val));
  412.    }
  413.    setCorrelationID(val);
  414. }
  415.  
  416. /**
  417.  * Insert the method's description here.
  418.  * Creation date: (10/6/00 10:23:03 AM)
  419.  * @return java.lang.String
  420.  */
  421. public void setDstTradingPartnerID(String param1)
  422.    throws com.ibm.epic.adapters.eak.common.AdapterException
  423. {
  424.    setRespondToLogicalID(param1);
  425. }
  426.  
  427. /**
  428.  * Insert the method's description here.
  429.  * Creation date: (10/6/00 10:23:03 AM)
  430.  * @return java.lang.String
  431.  */
  432. protected void setExtricityProcessID(String val,boolean asTransport)
  433.    throws com.ibm.epic.adapters.eak.common.AdapterException
  434. {
  435.    if(asTransport)
  436.    {
  437.           setLMSCorrelationID(encodeLMSCorrelationID(val));
  438.    }
  439.    setTransactionID(val);
  440. }
  441.  
  442. /**
  443.  * Insert the method's description here.
  444.  * Creation date: (10/20/00 10:22:26 AM)
  445.  * @param correlationID java.lang.String
  446.  */
  447. public void setLMSCorrelationID(byte[] correlationID)
  448. {
  449.    if(correlationID == null)
  450.    {
  451.           lmsCorrelationID = null;
  452.    }
  453.    else
  454.    {
  455.           lmsCorrelationID = new String(correlationID);
  456.    }
  457. }
  458.  
  459. /**
  460.  * Insert the method's description here.
  461.  * Creation date: (10/20/00 10:22:26 AM)
  462.  * @param correlationID java.lang.String
  463.  */
  464. public void setLMSCorrelationID(String correlationID)
  465. {
  466.    lmsCorrelationID = correlationID;
  467. }
  468.  
  469. /**
  470.  * Insert the method's description here.
  471.  * Creation date: (10/20/00 10:22:26 AM)
  472.  * @param messageID java.lang.String
  473.  */
  474. public void setLMSMessageID(byte[] messageID)
  475. {
  476.    if(messageID == null)
  477.    {
  478.           lmsMessageID = null;
  479.           lmsMessageIDEncoded = false;
  480.    }
  481.    else
  482.    {
  483.           int ix;
  484.           StringBuffer sb = new StringBuffer(messageID.length);
  485.  
  486.           // Encode into hex representation
  487.           for(ix = 0;ix < messageID.length;ix++)
  488.           {
  489.              sb.append(_HEXTBL[(messageID[ix] >> 4) & 0x0f]);
  490.              sb.append(_HEXTBL[messageID[ix] & 0x0f]);
  491.           }
  492.           setLMSMessageID(new String(sb),true);
  493.    }
  494. }
  495.  
  496. /**
  497.  * Insert the method's description here.
  498.  * Creation date: (10/20/00 10:22:26 AM)
  499.  * @param messageID java.lang.String
  500.  */
  501. public void setLMSMessageID(String messageID)
  502. {
  503.    setLMSMessageID(messageID,false);
  504. }
  505.  
  506. /**
  507.  * Insert the method's description here.
  508.  * Creation date: (10/20/00 10:22:26 AM)
  509.  * @param messageID java.lang.String
  510.  */
  511. public void setLMSMessageID(String messageID,boolean isEncoded)
  512. {
  513.    lmsMessageID = messageID;
  514.    lmsMessageIDEncoded = isEncoded;
  515. }
  516.  
  517. /**
  518.  * Insert the method's description here.
  519.  * Creation date: (10/6/00 10:23:03 AM)
  520.  * @return java.lang.String
  521.  */
  522. public void setProcessTransactionID(String param1)
  523.    throws com.ibm.epic.adapters.eak.common.AdapterException
  524. {
  525.    setBodyType(param1);
  526. }
  527.  
  528. /**
  529.  * Insert the method's description here.
  530.  * Creation date: (10/6/00 10:23:03 AM)
  531.  * @return java.lang.String
  532.  */
  533. public void setSrcTradingPartnerID(String param1)
  534.    throws com.ibm.epic.adapters.eak.common.AdapterException
  535. {
  536.    setDeliveryCategory(param1);
  537. }
  538.  
  539. /**
  540.  * Insert the method's description here.
  541.  * Creation date: (10/24/00 4:47:49 PM)
  542.  * @return java.lang.String
  543.  */
  544. public String toString()
  545. {
  546.    return "LMSMessageID:<"+lmsMessageID+">\n"+
  547.                   "LMSCorrelationID:<"+lmsCorrelationID+">\n"+
  548.                   super.toString();
  549. }
  550. }
  551.