Ejemplo n.º 1
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;
    }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
    }