Package org.zyp.cn8583

Examples of org.zyp.cn8583.cnMessageFactory


      String msgtypeid = elem.getAttribute("msgtypeid");
      if (msgtypeid.length() != 4) {
        throw new IOException("Invalid type for template: " + msgtypeid);
      }
      NodeList fields = elem.getElementsByTagName("field");
      cnMessage m = new cnMessage();
      m.setMsgTypeID(msgtypeid);
      for (int j = 0; j < fields.getLength(); j++) {
        Element f = (Element)fields.item(j);
        int fieldid = Integer.parseInt(f.getAttribute("id"));
        cnType datatype = cnType.valueOf(f.getAttribute("datatype"));
        int length = 0;
        if (f.getAttribute("length").length() > 0) {
          length = Integer.parseInt(f.getAttribute("length"));
        }
        String init_filed_data = f.getChildNodes().item(0) == null ?
                      null : f.getChildNodes().item(0).getNodeValue();
        m.setValue(fieldid, init_filed_data, datatype, length);
      }
      mfact.addMessageTemplate(m);
    }

    //Read the parsing guides
View Full Code Here


    mfact.setUseCurrentDate(false)// ������ field 7
    // ����ϵͳ���ٺŵ�������������field 11��
    mfact.setSystemTraceNumberGenerator(new cnSimpleSystemTraceNumGen((int)(System.currentTimeMillis() % 100000)));
   
    //Create a new message
    cnMessage m = mfact.newMessagefromTemplate("0200")// ����ģ�崴������ʼ��һ�����Ķ���
    m.setBinary(false);    // ������ʹ�ö�����

    if(m.setMessageHeaderData(0, new String("0123456789").getBytes()) == false) {
      System.out.println("���ñ���ͷ����");
      System.exit(-1);
    }
    m.setValue(4, new BigDecimal("501.25"), cnType.AMOUNT, 0);
    m.setValue(12, new Date(), cnType.TIME, 0);
    m.setValue(15, new Date(), cnType.DATE4, 0);
    m.setValue(17, new Date(), cnType.DATE_EXP, 0);
    m.setValue(37, 12345678, cnType.NUMERIC, 12);
    m.setValue(41, "TEST-TERMINAL", cnType.ALPHA, 16);
   
    FileOutputStream fout = new FileOutputStream("messagedata.out");
    m.write(fout, 4, 10)// �ѱ���д���ļ������ڱ���ǰ�����ϱ�ʾ�������ij��ȵ��ĸ������ַ�(10���Ʊ�ʾ)��
    fout.close();
   
    System.out.println("\n NEW MESSAGE:");
    print(m);
   
View Full Code Here

  /** Creates a message factory from an XML config file( full path and filename). */
  public static cnMessageFactory createFromXMLConfigFile(String filepath) throws IOException {
    // InputStream ins = cnMessageFactory.class.getClassLoader().getResourceAsStream(path);
    InputStream ins = new FileInputStream(filepath);
    cnMessageFactory mfact = new cnMessageFactory();
    if (ins != null) {
        log.debug("parsing config from xml file: [" + filepath + "]");
      try {
        parse(mfact, ins);
      } finally {
View Full Code Here

    return mfact;
  }

  /** Creates a message factory from the file located at the specified URL. */
  public static cnMessageFactory createFromUrl(URL url) throws IOException {
    cnMessageFactory mfact = new cnMessageFactory();
    InputStream stream = url.openStream();
    try {
      parse(mfact, stream);
    } finally {
      stream.close();
View Full Code Here

  public static void main(String[] args) throws Exception {
    // ������־
    org.apache.log4j.PropertyConfigurator.configure("j8583cn_log.properties");
    // ����j8583cn���ĸ�ʽ�����ļ�������һ�����Ĺ�������
    cnMessageFactory mfact = cnConfigParser.createFromXMLConfigFile("config.xml");
    mfact.setUseCurrentDate(false)// ������ field 7
    // ����ϵͳ���ٺŵ�������������field 11��
    mfact.setSystemTraceNumberGenerator(new cnSimpleSystemTraceNumGen((int)(System.currentTimeMillis() % 100000)));
   
    //Create a new message
    cnMessage m = mfact.newMessagefromTemplate("0200")// ����ģ�崴������ʼ��һ�����Ķ���
    m.setBinary(false);    // ������ʹ�ö�����

    if(m.setMessageHeaderData(0, new String("0123456789").getBytes()) == false) {
      System.out.println("���ñ���ͷ����");
      System.exit(-1);
    }
    m.setValue(4, new BigDecimal("501.25"), cnType.AMOUNT, 0);
    m.setValue(12, new Date(), cnType.TIME, 0);
    m.setValue(15, new Date(), cnType.DATE4, 0);
    m.setValue(17, new Date(), cnType.DATE_EXP, 0);
    m.setValue(37, 12345678, cnType.NUMERIC, 12);
    m.setValue(41, "TEST-TERMINAL", cnType.ALPHA, 16);
   
    FileOutputStream fout = new FileOutputStream("messagedata.out");
    m.write(fout, 4, 10)// �ѱ���д���ļ������ڱ���ǰ�����ϱ�ʾ�������ij��ȵ��ĸ������ַ�(10���Ʊ�ʾ)��
    fout.close();
   
    System.out.println("\n NEW MESSAGE:");
    print(m);
   
    // �������һ�����Ĵ����ô������ļ��У� 
    System.out.println("\n PARSE MESSAGE FROM FILE");
    byte[] buf = new byte[4];
    FileInputStream fin = new FileInputStream("messagedata.out");
    fin.read(buf)// ���ĸ��ֽڵ����ݣ������ij�����Ϣ������
    int len = (buf[0] - 0x30) * 1000   // ǧλ
        + (buf[1] - 0x30) * 100   // ��λ
        + (buf[2] - 0x30) * 10     // ʮλ
        + buf[3] - 0x30;      // ��λ
    buf = new byte[len];
    fin.read(buf)// �ӵ�����ֽڶ�ȡlen���ֽڵ����ݵ�buf��
    fin.close();
   
    mfact.setUseBinary(false);
    m = mfact.parseMessage(buf, mfact.getHeaderLengthAttr("0200"))// ����
    print(m);
   
  }
View Full Code Here

      cnMessage m = new cnMessage();
      m.setMsgTypeID(msgtypeid);
      for (int j = 0; j < fields.getLength(); j++) {
        Element f = (Element)fields.item(j);
        int fieldid = Integer.parseInt(f.getAttribute("id"));
        cnType datatype = cnType.valueOf(f.getAttribute("datatype"));
        int length = 0;
        if (f.getAttribute("length").length() > 0) {
          length = Integer.parseInt(f.getAttribute("length"));
        }
        String init_filed_data = f.getChildNodes().item(0) == null ?
                      null : f.getChildNodes().item(0).getNodeValue();
        m.setValue(fieldid, init_filed_data, datatype, length);
      }
      mfact.addMessageTemplate(m);
    }

    //Read the parsing guides
    nodes = root.getElementsByTagName("parseinfo");
    for (int i = 0; i < nodes.getLength(); i++) {
      elem = (Element)nodes.item(i);
      String msgtypeid = elem.getAttribute("msgtypeid");
      if (msgtypeid.length()!= 4) {
        throw new IOException("Invalid type for parse guide: " + msgtypeid);
      }
      NodeList fields = elem.getElementsByTagName("field");
      HashMap<Integer, cnFieldParseInfo> parseMap = new HashMap<Integer, cnFieldParseInfo>();
      for (int j = 0; j < fields.getLength(); j++) {
        Element f = (Element)fields.item(j);
        int fieldid = Integer.parseInt(f.getAttribute("id"));
        cnType datatype = cnType.valueOf(f.getAttribute("datatype"));
        int length = 0;
        if (f.getAttribute("length").length() > 0) {
          length = Integer.parseInt(f.getAttribute("length"));
        }
        parseMap.put(fieldid, new cnFieldParseInfo(datatype, length));
View Full Code Here

    org.apache.log4j.PropertyConfigurator.configure("j8583cn_log.properties");
    // ����j8583cn���ĸ�ʽ�����ļ�������һ�����Ĺ�������
    cnMessageFactory mfact = cnConfigParser.createFromXMLConfigFile("config.xml");
    mfact.setUseCurrentDate(false)// ������ field 7
    // ����ϵͳ���ٺŵ�������������field 11��
    mfact.setSystemTraceNumberGenerator(new cnSimpleSystemTraceNumGen((int)(System.currentTimeMillis() % 100000)));
   
    //Create a new message
    cnMessage m = mfact.newMessagefromTemplate("0200")// ����ģ�崴������ʼ��һ�����Ķ���
    m.setBinary(false);    // ������ʹ�ö�����
View Full Code Here

              + "]��,��XML�����ļ���δ���ø���. ����ܻᵼ�½�������,�����������XML�����ļ���");
        }
      }
    }
    for (Integer i : index) {
      cnFieldParseInfo fpi = parseGuide.get(i);
      if (bs.get(i - 1)) {
        cnValue val = useBinary ? fpi.parseBinary(buf, pos) : fpi.parse(buf, pos);
        m.setField(i, val);
        log.debug("parsed: fieldid=[" + i + "] <" + m.getField(i).getType() + "> \t[" 
            + m.getField(i).toString() + "] ---> [" + m.getObjectValue(i) + "]");
        if (useBinary && !(val.getType() == cnType.ALPHA || val.getType() == cnType.LLVAR
            || val.getType() == cnType.LLLVAR)) {
View Full Code Here

TOP

Related Classes of org.zyp.cn8583.cnMessageFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.