Esempio n. 1
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;
     }
   }
 }
Esempio n. 2
0
 /**
  * add all fields present on received parameter to this ISOMsg<br>
  * please note that received fields take precedence over existing ones (simplifying card agent
  * message creation and template handling)
  *
  * @param m ISOMsg to merge
  */
 public void merge(ISOMsg m) {
   for (int i = 0; i <= m.getMaxField(); i++)
     try {
       if (m.hasField(i)) set(m.getComponent(i));
     } catch (ISOException e) {
       // should never happen
     }
 }
Esempio n. 3
0
 /**
  * get the component associated with the given field number
  *
  * @param fpath field path
  * @return the Component
  */
 public ISOComponent getComponent(String fpath) throws ISOException {
   StringTokenizer st = new StringTokenizer(fpath, ".");
   ISOMsg m = this;
   ISOComponent obj = null;
   for (; ; ) {
     int fldno = Integer.parseInt(st.nextToken());
     obj = m.getComponent(fldno);
     if (st.hasMoreTokens()) {
       if (obj instanceof ISOMsg) {
         m = (ISOMsg) obj;
       } else break; // 'Quick' exit if hierachy is not present.
     } else break;
   }
   return obj;
 }
Esempio n. 4
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;
 }
Esempio n. 5
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;
     }
   }
 }
Esempio n. 6
0
  public Object clone() {
    try {
      ISOMsg m = (ISOMsg) super.clone();
      m.fields = (TreeMap) ((TreeMap) fields).clone();
      if (header != null) m.header = (ISOHeader) header.clone();

      Iterator iter = fields.keySet().iterator();
      while (iter.hasNext()) {
        Integer k = (Integer) iter.next();
        ISOComponent c = (ISOComponent) m.fields.get(k);
        if (c instanceof ISOMsg) m.fields.put(k, ((ISOMsg) c).clone());
      }
      return m;
    } catch (CloneNotSupportedException e) {
      throw new InternalError();
    }
  }
Esempio n. 7
0
 /**
  * Partially clone an ISOMsg
  *
  * @param fields int array of fields to go
  * @return new ISOMsg instance
  */
 public Object clone(int[] fields) {
   try {
     ISOMsg m = (ISOMsg) super.clone();
     m.fields = new TreeMap();
     for (int i = 0; i < fields.length; i++) {
       if (hasField(fields[i])) {
         try {
           m.set(getComponent(fields[i]));
         } catch (ISOException e) {
           // it should never happen
         }
       }
     }
     return m;
   } catch (CloneNotSupportedException e) {
     throw new InternalError();
   }
 }
Esempio n. 8
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);
     }
   }
 }
Esempio n. 9
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;
     }
   }
 }