Пример #1
0
 public byte[] pack(ISOComponent c) throws ISOException {
   try {
     Map tab = c.getChildren();
     StringBuilder sb = new StringBuilder();
     for (int i = 0; i < fld.length; i++) {
       ISOField f = (ISOField) tab.get(i);
       if (f != null) {
         sb.append(new String(fld[i].pack(f)));
       }
     }
     return sb.toString().getBytes();
   } catch (Exception ex) {
     throw new ISOException(this.getRealm() + ": " + ex.getMessage(), ex);
   }
 }
Пример #2
0
 public ISOComponent validate(ISOComponent c) throws org.jpos.iso.ISOException {
   LogEvent evt = new LogEvent(this, "validate");
   try {
     Map tab = c.getChildren();
     for (int i = 0; i < fldVld.length; i++) {
       ISOField f = (ISOField) tab.get(i);
       if (f != null) c.set(fldVld[i].validate(f));
     }
     return c;
   } catch (ISOVException ex) {
     if (!ex.treated()) {
       c.set(ex.getErrComponent());
       ex.setTreated(true);
     }
     evt.addMessage(ex);
     throw ex;
   } finally {
     Logger.log(evt);
   }
 }
Пример #3
0
  @Override
  public byte[] pack(ISOComponent c) throws ISOException {
    LogEvent evt = new LogEvent(this, "pack");
    try {
      int len = 0;
      Map tab = c.getChildren();
      List<byte[]> l = new ArrayList();

      for (Map.Entry ent : (Set<Map.Entry>) tab.entrySet()) {
        Integer i = (Integer) ent.getKey();
        if (i < 0) continue;
        if (fld[i] == null)
          throw new ISOException("Unsupported sub-field " + i + " packing field " + c.getKey());
        if (ent.getValue() instanceof ISOComponent)
          try {
            ISOComponent f = (ISOComponent) ent.getValue();
            byte[] b = fld[i].pack(f);
            len += b.length;
            l.add(b);
          } catch (Exception e) {
            evt.addMessage("error packing subfield " + i);
            evt.addMessage(c);
            evt.addMessage(e);
            throw e;
          }
      }
      int k = 0;
      byte[] d = new byte[len];
      for (byte[] b : l) {
        System.arraycopy(b, 0, d, k, b.length);
        k += b.length;
      }
      if (logger != null) // save a few CPU cycle if no logger available
      evt.addMessage(ISOUtil.hexString(d));
      return d;
    } catch (Exception ex) {
      throw new ISOException(ex);
    }
  }