3b4c96446214ed11c07404a0256e2e59a266df32.svn-base 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package xin.glue.ui.common;
  2. import java.util.Collections;
  3. import java.util.Comparator;
  4. import java.util.List;
  5. import java.util.Map;
  6. import com.posdata.glue.biz.constants.PosBizControlConstants;
  7. import com.posdata.glue.biz.control.PosBizProvider;
  8. import com.posdata.glue.component.PosComponentFactory;
  9. import com.posdata.glue.component.PosComponentIF;
  10. import com.posdata.glue.component.layout.PosXmlMessageLayout;
  11. import com.posdata.glue.context.PosContext;
  12. import com.posdata.glue.msg.PosMESMessageImpl;
  13. import com.posdata.glue.msg.PosMessage;
  14. import com.posdata.glue.msg.util.PosMessageUtil;
  15. public class PosMessageInfo {
  16. private static String setLength(int len) {
  17. if (len < 10) return "000" + len;
  18. else if (len < 100) return "00" + len;
  19. else if (len < 1000) return "0" + len;
  20. return "" + len;
  21. }
  22. private static String setLength(String sMsg, int len) {
  23. for (int i = sMsg.length(); i < len; i++)
  24. sMsg += ' ';
  25. return sMsg.substring(0, len);
  26. }
  27. public static String getMessage(String sMsg, String TcId) {
  28. StringBuffer msg = new StringBuffer();
  29. try {
  30. List attributes = new PosXmlMessageLayout().getAttributes(TcId).getAttributes();
  31. Collections.sort(attributes, new Comparator() {
  32. public int compare(Object o1, Object o2) {
  33. return (Integer.parseInt(PosMessageUtil.getSource(o1, "seq").toString()) -
  34. Integer.parseInt(PosMessageUtil.getSource(o2, "seq").toString()));
  35. }});
  36. int mLen = sMsg.length();
  37. int iLen = 0;
  38. for (int i = 0, size = attributes.size(); i < size; i++) {
  39. Map attribute = (Map) attributes.get(i);
  40. String key = (String) attribute.get("id");
  41. msg.append(setLength(key, 20)).append('[').append(setLength(iLen)).append(" ");
  42. int len = Integer.parseInt(attribute.get("length").toString());
  43. msg.append(setLength(len)).append("] ");
  44. if (iLen + len <= mLen)
  45. msg.append(sMsg.substring(iLen, iLen + len));
  46. else
  47. msg.append('*');
  48. msg.append('\n');
  49. iLen += len;
  50. }
  51. msg.insert(0, "[Message Length: " + sMsg.length() + "]\t[Request Length: " + iLen + "]\n");
  52. msg.insert(0, sMsg + '\n');
  53. } catch (Exception e) {
  54. }
  55. return msg.toString();
  56. }
  57. public static String getMessage2(String sMsg, String TcId) {
  58. PosContext poscontext = new PosContext();
  59. PosMessage message = new PosMESMessageImpl();
  60. poscontext.setMessage(message);
  61. List attributes = new PosXmlMessageLayout().getAttributes(TcId).getAttributes();
  62. Collections.sort(attributes, new Comparator() {
  63. public int compare(Object o1, Object o2) {
  64. return (Integer.parseInt(PosMessageUtil.getSource(o1, "seq").toString()) -
  65. Integer.parseInt(PosMessageUtil.getSource(o2, "seq").toString()));
  66. }});
  67. int iLen = 0;
  68. for (int i = 0, size = attributes.size(); i < size; i++) {
  69. Map attribute = (Map) attributes.get(i);
  70. iLen += Integer.parseInt(attribute.get("length").toString());
  71. }
  72. StringBuffer msg = new StringBuffer(sMsg);
  73. for (int i = sMsg.length(); i < iLen; i++)
  74. msg.append(' ');
  75. msg.setLength(iLen);
  76. message.setTC(msg.toString());
  77. message.setTCID(TcId);
  78. PosComponentIF poscomponentif = PosComponentFactory.getInstance().getComponent(2);
  79. poscomponentif.processComponent(poscontext);
  80. msg.setLength(0);
  81. msg.append("Message Length: " + sMsg.length() + "\tRequest Length: " + iLen + '\n');
  82. iLen = 0;
  83. Map map = message.getAttributes();
  84. for (int i = 0, size = attributes.size(); i < size; i++) {
  85. Map attribute = (Map) attributes.get(i);
  86. String key = (String) attribute.get("id");
  87. msg.append(setLength(key, 20)).append('[').append(setLength(iLen)).append(" ");
  88. int len = Integer.parseInt(attribute.get("length").toString());
  89. msg.append(setLength(len)).append("] ").append(map.get(key)).append('\n');
  90. iLen += len;
  91. }
  92. return msg.toString();
  93. }
  94. public static void TC_SEND(String sMsg, String TcId) {
  95. PosContext context = new PosContext();
  96. PosMessage message = new PosMESMessageImpl();
  97. context.setMessage(message);
  98. message.setTC(sMsg);
  99. message.setTCID(TcId);
  100. context.put(PosBizControlConstants.SERVICE_NAME, TcId + "-service");
  101. PosBizProvider.getController().doSubController(context, false);
  102. }
  103. }