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