Пример #1
0
 /**
  * Unset a field referenced by a fpath if it exists, otherwise ignore.
  *
  * @param fpath dot-separated field path (i.e. 63.2)
  * @throws ISOException
  */
 public void unset(String fpath) throws ISOException {
   StringTokenizer st = new StringTokenizer(fpath, ".");
   ISOMsg m = this;
   ISOMsg lastm = m;
   int fldno = -1;
   int lastfldno;
   for (; ; ) {
     lastfldno = fldno;
     fldno = Integer.parseInt(st.nextToken());
     if (st.hasMoreTokens()) {
       Object obj = m.getValue(fldno);
       if (obj instanceof ISOMsg) {
         lastm = m;
         m = (ISOMsg) obj;
       } else {
         // No real way of unset further subfield, exit.  Perhaps should be ISOException?
         break;
       }
     } else {
       m.unset(fldno);
       if (m.hasFields() == false && (lastfldno != -1)) {
         lastm.unset(lastfldno);
       }
       break;
     }
   }
 }
Пример #2
0
 /**
  * Creates an ISOField associated with fldno within this ISOMsg
  *
  * @param fpath dot-separated field path (i.e. 63.2)
  * @param c component
  */
 public void set(String fpath, ISOComponent c) throws ISOException {
   StringTokenizer st = new StringTokenizer(fpath, ".");
   ISOMsg m = this;
   for (; ; ) {
     int fldno = Integer.parseInt(st.nextToken());
     if (st.hasMoreTokens()) {
       Object obj = m.getValue(fldno);
       if (obj instanceof ISOMsg) m = (ISOMsg) obj;
       else
       /*
        * we need to go deeper, however, if the value == null then
        * there is nothing to do (unset) at the lower levels, so break now and save some processing.
        */
       if (c == null) {
         break;
       } else {
         // We have a value to set, so adding a level to hold it is sensible.
         m.set(m = new ISOMsg(fldno));
       }
     } else {
       m.set(c);
       break;
     }
   }
 }
Пример #3
0
 /**
  * Return the object value associated with the given field path
  *
  * @param fpath field path
  * @return the field Object (may be null)
  */
 public Object getValue(String fpath) throws ISOException {
   StringTokenizer st = new StringTokenizer(fpath, ".");
   ISOMsg m = this;
   Object obj;
   for (; ; ) {
     int fldno = Integer.parseInt(st.nextToken());
     obj = m.getValue(fldno);
     if (st.hasMoreTokens()) {
       if (obj instanceof ISOMsg) {
         m = (ISOMsg) obj;
       } else throw new ISOException("Invalid path '" + fpath + "'");
     } else break;
   }
   return obj;
 }
Пример #4
0
 /**
  * Creates an ISOField associated with fldno within this ISOMsg
  *
  * @param fpath dot-separated field path (i.e. 63.2)
  * @param value binary field value
  */
 public void set(String fpath, byte[] value) throws ISOException {
   StringTokenizer st = new StringTokenizer(fpath, ".");
   ISOMsg m = this;
   for (; ; ) {
     int fldno = Integer.parseInt(st.nextToken());
     if (st.hasMoreTokens()) {
       Object obj = m.getValue(fldno);
       if (obj instanceof ISOMsg) m = (ISOMsg) obj;
       else m.set(m = new ISOMsg(fldno));
     } else {
       m.set(fldno, value);
       break;
     }
   }
 }
Пример #5
0
 /**
  * Check if a field indicated by a fpath is present
  *
  * @param fpath dot-separated field path (i.e. 63.2)
  */
 public boolean hasField(String fpath) throws ISOException {
   StringTokenizer st = new StringTokenizer(fpath, ".");
   ISOMsg m = this;
   for (; ; ) {
     int fldno = Integer.parseInt(st.nextToken());
     if (st.hasMoreTokens()) {
       Object obj = m.getValue(fldno);
       if (obj instanceof ISOMsg) {
         m = (ISOMsg) obj;
       } else {
         // No real way of checking for further subfields, return false, perhaps should be
         // ISOException?
         return false;
       }
     } else {
       return m.hasField(fldno);
     }
   }
 }