Example #1
0
    /**
     * @param bitmapCodec
     * @return
     */
    private Map<Integer, CompositeDef> buildFieldsDefs(BitmapCodec bitmapCodec) {
      NodeList messageList = doc.getElementsByTagName(ELEMENT_MESSAGE);
      Map<Integer, CompositeDef> defs = new TreeMap<>();

      for (int i = 0; i < messageList.getLength(); i++) {
        Element messageDef = (Element) messageList.item(i);
        Integer mti = getOptionalInteger(messageDef, ATTR_MTI);

        if (defs.containsKey(mti)) {
          throw new ConfigException(format("Duplicate message config for mti %d", mti));
        }

        SortedMap<Integer, ComponentDef> messageFieldDefs = buildVarComponents(messageDef);

        if (messageFieldDefs.containsKey(1)) {
          throw new ConfigException("Message field with index 1 not allowed");
        }

        defs.put(
            mti,
            new CompositeDef(
                messageFieldDefs, new VarCompositeCodec(bitmapCodec, defaultFailFast), true));
      }

      return defs;
    }
Example #2
0
 /**
  * @param ce
  * @return
  */
 private SortedMap<Integer, ComponentDef> buildFixedComponents(Element ce) {
   List<Element> fields = getSubElements(ce);
   SortedMap<Integer, ComponentDef> fieldDefs;
   if (fields.size() > 0) {
     fieldDefs = new TreeMap<>();
     int index = 1;
     for (Element e : fields) {
       ComponentDef def = buildComponent(e, true);
       fieldDefs.put(index++, def);
     }
   } else {
     throw new ConfigException("Composite components should have at least 1 sub field");
   }
   return fieldDefs;
 }
Example #3
0
    /**
     * @param ce
     * @return
     */
    private SortedMap<Integer, ComponentDef> buildTlvComponents(Element ce) {
      List<Element> fields = getSubElements(ce);
      SortedMap<Integer, ComponentDef> fieldDefs;
      if (fields.size() > 0) {
        fieldDefs = new TreeMap<>();
        for (Element e : fields) {
          Integer tag = Integer.valueOf(getMandatoryAttribute(e, ATTR_TAG));
          ComponentDef def = buildTlvComponent(e, getOrdinality(e));
          if (fieldDefs.containsKey(tag)) {
            throw new ConfigException(format("Duplicate component tag: %d", tag));
          }
          fieldDefs.put(tag, def);
        }
      } else {
        throw new ConfigException("Composite components should have at least 1 sub field");
      }

      return fieldDefs;
    }
Example #4
0
    private SortedMap<Integer, ComponentDef> cloneSubComponentDefs(
        SortedMap<Integer, ComponentDef> existingDefs) {
      SortedMap<Integer, ComponentDef> clone = new TreeMap<>();
      for (Entry<Integer, ComponentDef> defEntry : existingDefs.entrySet()) {
        Integer index = defEntry.getKey();
        ComponentDef def = defEntry.getValue();
        if (def instanceof CompositeDef) {
          CompositeDef compositeDef = (CompositeDef) def;

          clone.put(
              index,
              new CompositeDef(
                  cloneSubComponentDefs(compositeDef.getSubComponentDefs()),
                  compositeDef.getCompositeCodec(),
                  compositeDef.isMandatory(),
                  compositeDef.getLengthCodec()));
        } else {
          clone.put(index, new ComponentDef(def.getCodec(), def.isMandatory()));
        }
      }
      return clone;
    }