예제 #1
0
    private void buildFieldsDefsExtension(Map<Integer, CompositeDef> existingCodecs) {
      NodeList messageExtList = doc.getElementsByTagName(ELEMENT_MESSAGE_EXT);
      Map<Integer, CompositeDef> extensions = new TreeMap<>();
      for (int i = 0; i < messageExtList.getLength(); i++) {
        Element messageDef = (Element) messageExtList.item(i);
        Integer mtiExisting = getOptionalInteger(messageDef, ATTR_EXTENDS);
        Integer mti = getOptionalInteger(messageDef, ATTR_MTI);
        if (existingCodecs.containsKey(mti) || extensions.containsKey(mti)) {
          throw new ConfigException(format("Duplicate message config for mti %d", mti));
        }

        CompositeDef existing = existingCodecs.get(mtiExisting);
        if (existing == null) {
          throw new ConfigException(format("Error extending mti %d, no config available", mti));
        }
        SortedMap<Integer, ComponentDef> clonedFieldsDef =
            cloneSubComponentDefs(existing.getSubComponentDefs());

        Element setElement = null;
        Element removeElement = null;
        for (Element e : getSubElements(messageDef)) {
          switch (e.getTagName()) {
            case ELEMENT_SET:
              setElement = e;
              break;
            case ELEMENT_REMOVE:
              removeElement = e;
              break;
            default:
              throw new ConfigException(
                  format("Unknown message extension instruction %s", e.getTagName()));
          }
        }

        if (setElement != null) {
          setVarFields(clonedFieldsDef, getSubElements(setElement));
        }

        if (removeElement != null) {
          removeFields(clonedFieldsDef, getSubElements(removeElement));
        }

        extensions.put(
            mti,
            new CompositeDef(
                clonedFieldsDef,
                existing.getCompositeCodec(),
                existing.isMandatory(),
                existing.getLengthCodec()));
      }
      existingCodecs.putAll(extensions);
    }
예제 #2
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;
    }