Пример #1
0
    private void setVarFields(Map<Integer, ComponentDef> components, List<Element> elements) {
      for (Element e : elements) {

        Integer index = getOptionalInteger(e, ATTR_INDEX);
        if (index == null) {
          index = Integer.valueOf(getMandatoryAttribute(e, ATTR_TAG));
        }
        ComponentDef existingDef = components.get(index);
        ComponentDef newDef = null;
        if (isCompositeVar(e) || ELEMENT_COMPOSITE_TLV.equals(e.getTagName())) {
          if (existingDef != null) {
            newDef = buildCompositeDef(existingDef, e);
          }
        }

        if (newDef == null) {
          if (ELEMENT_COMPOSITE_TLV.equals(((Element) e.getParentNode()).getTagName())) {
            newDef = buildTlvComponent(e, getOrdinality(e));
          } else {
            newDef = buildComponent(e, getOrdinality(e));
          }
        }

        components.put(index, newDef);
      }
    }
Пример #2
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);
    }
Пример #3
0
 private void removeFields(Map<Integer, ComponentDef> componentDefs, List<Element> subElements) {
   for (Element e : subElements) {
     Integer index = Integer.valueOf(e.getAttribute(ATTR_INDEX));
     switch (e.getTagName()) {
       case ELEMENT_FIELD:
         if (componentDefs.remove(index) == null) {
           throw new ConfigException(format("Expected field %d not found", index));
         }
         break;
       case ELEMENT_COMPOSITE:
         ComponentDef def = componentDefs.get(index);
         if (def instanceof CompositeDef) {
           SortedMap<Integer, ComponentDef> subComponentDefs =
               ((CompositeDef) def).getSubComponentDefs();
           removeFields(subComponentDefs, getSubElements(e));
           break;
         }
         throw new ConfigException(format("Expected composite field %d not found", index));
       default:
         throw new ConfigException(
             format("Unknown message remove component instruction %s", e.getTagName()));
     }
   }
 }