| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- package xin.glue.ui.common;
- import java.util.Collections;
- import java.util.Comparator;
- import java.util.List;
- import java.util.Map;
- import com.posdata.glue.biz.constants.PosBizControlConstants;
- import com.posdata.glue.biz.control.PosBizProvider;
- import com.posdata.glue.component.PosComponentFactory;
- import com.posdata.glue.component.PosComponentIF;
- import com.posdata.glue.component.layout.PosXmlMessageLayout;
- import com.posdata.glue.context.PosContext;
- import com.posdata.glue.msg.PosMESMessageImpl;
- import com.posdata.glue.msg.PosMessage;
- import com.posdata.glue.msg.util.PosMessageUtil;
- public class PosMessageInfo {
- private static String setLength(int len) {
- if (len < 10) return "000" + len;
- else if (len < 100) return "00" + len;
- else if (len < 1000) return "0" + len;
- return "" + len;
- }
- private static String setLength(String sMsg, int len) {
- for (int i = sMsg.length(); i < len; i++)
- sMsg += ' ';
- return sMsg.substring(0, len);
- }
- public static String getMessage(String sMsg, String TcId) {
- StringBuffer msg = new StringBuffer();
- try {
- List attributes = new PosXmlMessageLayout().getAttributes(TcId).getAttributes();
- Collections.sort(attributes, new Comparator() {
- public int compare(Object o1, Object o2) {
- return (Integer.parseInt(PosMessageUtil.getSource(o1, "seq").toString()) -
- Integer.parseInt(PosMessageUtil.getSource(o2, "seq").toString()));
- }});
- int mLen = sMsg.length();
- int iLen = 0;
- for (int i = 0, size = attributes.size(); i < size; i++) {
- Map attribute = (Map) attributes.get(i);
- String key = (String) attribute.get("id");
- msg.append(setLength(key, 20)).append('[').append(setLength(iLen)).append(" ");
- int len = Integer.parseInt(attribute.get("length").toString());
- msg.append(setLength(len)).append("] ");
- if (iLen + len <= mLen)
- msg.append(sMsg.substring(iLen, iLen + len));
- else
- msg.append('*');
- msg.append('\n');
- iLen += len;
- }
- msg.insert(0, "[Message Length: " + sMsg.length() + "]\t[Request Length: " + iLen + "]\n");
- msg.insert(0, sMsg + '\n');
- } catch (Exception e) {
- }
- return msg.toString();
- }
- public static String getMessage2(String sMsg, String TcId) {
- PosContext poscontext = new PosContext();
- PosMessage message = new PosMESMessageImpl();
- poscontext.setMessage(message);
- List attributes = new PosXmlMessageLayout().getAttributes(TcId).getAttributes();
- Collections.sort(attributes, new Comparator() {
- public int compare(Object o1, Object o2) {
- return (Integer.parseInt(PosMessageUtil.getSource(o1, "seq").toString()) -
- Integer.parseInt(PosMessageUtil.getSource(o2, "seq").toString()));
- }});
- int iLen = 0;
- for (int i = 0, size = attributes.size(); i < size; i++) {
- Map attribute = (Map) attributes.get(i);
- iLen += Integer.parseInt(attribute.get("length").toString());
- }
- StringBuffer msg = new StringBuffer(sMsg);
- for (int i = sMsg.length(); i < iLen; i++)
- msg.append(' ');
- msg.setLength(iLen);
- message.setTC(msg.toString());
- message.setTCID(TcId);
- PosComponentIF poscomponentif = PosComponentFactory.getInstance().getComponent(2);
- poscomponentif.processComponent(poscontext);
- msg.setLength(0);
- msg.append("Message Length: " + sMsg.length() + "\tRequest Length: " + iLen + '\n');
- iLen = 0;
- Map map = message.getAttributes();
- for (int i = 0, size = attributes.size(); i < size; i++) {
- Map attribute = (Map) attributes.get(i);
- String key = (String) attribute.get("id");
- msg.append(setLength(key, 20)).append('[').append(setLength(iLen)).append(" ");
- int len = Integer.parseInt(attribute.get("length").toString());
- msg.append(setLength(len)).append("] ").append(map.get(key)).append('\n');
- iLen += len;
- }
- return msg.toString();
- }
- public static void TC_SEND(String sMsg, String TcId) {
- PosContext context = new PosContext();
- PosMessage message = new PosMESMessageImpl();
- context.setMessage(message);
- message.setTC(sMsg);
- message.setTCID(TcId);
- context.put(PosBizControlConstants.SERVICE_NAME, TcId + "-service");
- PosBizProvider.getController().doSubController(context, false);
- }
- }
|