Ejemplo n.º 1
0
  public static ISOMsg objectToIso8583(
      ISOBasePackager packager, Object jaxbObj, Map<String, String> mappings) {
    ISOMsg res = Iso8583Util.emptyMsg(packager);
    try {
      for (String key : mappings.keySet()) {
        String oPath = mappings.get(key);

        Object value = BCUtils.extractFromJaxbObjByOPath(jaxbObj, oPath);
        debug("oPath=" + oPath + ", value=" + value);
        String strVal = "";
        if (value == null) {
          strVal = "";
        } else if (value instanceof Date) {
          strVal = ISODate.getDateTime((Date) value);
        } else {
          strVal = value.toString();
        }
        Integer fldPos = Integer.valueOf(key);

        Iso8583Util.setField(res, fldPos, strVal);
      }

    } catch (Exception ex) {
      ex.printStackTrace();
      throw new RuntimeException(ex);
    }

    return res;
  }
Ejemplo n.º 2
0
  public Object iso8583ToObject(ISOMsg msg, Map<String, String> mappings) {
    Object res = null;
    try {
      for (String key : mappings.keySet()) {
        String[] paths = parseObjPath(key);
        String oPath = paths[0];
        String thisName = paths[1];

        debug("================oPath=" + oPath + ", att=" + thisName);

        // this is to save the "Document." from mapping rule
        // todo is there a better way?
        // TODO this is not generic enough
        Object obj = findObject("Document." + oPath);

        String mapto = mappings.get(key);
        Object value = null;
        if (!mapto.contains(MAP_ISO_PREFIX)) {
          // not a ISO mapping
          value = mapto;
        } else {
          Integer fldno =
              Integer.valueOf(StringUtils.substringBetween(mapto, MAP_ISO_PREFIX, MAP_ISO_SURFIX));

          value = Iso8583Util.getField(msg, fldno);
        }

        // the leaf node itself is a List (of Strings?) see 101 RemittanceInformation5.ustrd
        if (thisName.contains("[")) {
          if (value == null) {
            // ISO msg does not contain the mapping field
            // TODO what to do?
            // now just neglect
          } else {
            String fName = StringUtils.substringBefore(thisName, "[");
            Collection collection = (Collection) PropertyUtils.getProperty(obj, fName);
            collection.add(value);
          }
        } else {
          Field field = obj.getClass().getDeclaredField(thisName);
          Class type = field.getType();
          debug("type=" + type);

          if (value == null) {
            // ISO msg does not contain the mapping field
            // TODO what to do?
            // now just neglect
          } else if (type.isEnum()) {
            Object[] values = type.getEnumConstants();
            Method m = type.getDeclaredMethod("fromValue", String.class);
            value = m.invoke(obj, (String) value);
          }

          BeanUtils.setProperty(obj, thisName, value);
        }
      }

      res = pool.get(rootName);

    } catch (Exception ex) {
      ex.printStackTrace();
      throw new RuntimeException(ex);
    }
    return res;
  }