Пример #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;
    }
Пример #2
0
    private CompositeDef buildCompositeDef(ComponentDef existingDef, Element e) {
      SortedMap<Integer, ComponentDef> existingSubComponentDefs;
      CompositeCodec existingCompositeCodec;
      Boolean existingMandatory = existingDef.isMandatory();
      Codec<Number> existingLengthCodec;

      CompositeDef newDef = null;

      if (existingDef instanceof CompositeDef) {

        existingSubComponentDefs = ((CompositeDef) existingDef).getSubComponentDefs();
        existingCompositeCodec = ((CompositeDef) existingDef).getCompositeCodec();
        existingLengthCodec = ((CompositeDef) existingDef).getLengthCodec();

        NumericCodec newLengthCodec =
            ELEMENT_COMPOSITE_TLV.equals(((Element) e.getParentNode()).getTagName())
                ? null
                : buildVarLengthCodec(e);

        CompositeCodec newCompositeCodec;
        Boolean newMandatory = getOrdinality(e);
        if (ELEMENT_COMPOSITE_TLV.equals(e.getTagName())) {
          newCompositeCodec =
              new TlvCompositeCodec(
                  getEncoding(e, ATTR_TAG_ENCODING, defaultTlvTagEncoding),
                  getEncoding(e, ATTR_LENGTH_ENCODING, defaultTlvLengthEncoding),
                  defaultFailFast);
        } else {
          Bitmap.Type bitmapType = getBitmapType(e);
          BitmapCodec newBitmapCodec = bitmapType != null ? new BitmapCodec(bitmapType) : null;
          newCompositeCodec = new VarCompositeCodec(newBitmapCodec, defaultFailFast);
        }

        if (existingSubComponentDefs != null
            && EqualsBuilder.newInstance(existingCompositeCodec, newCompositeCodec)
                .append(existingMandatory, newMandatory)
                .append(existingLengthCodec, newLengthCodec)
                .isEqual()) {
          setVarFields(existingSubComponentDefs, getSubElements(e));

          newDef =
              new CompositeDef(
                  existingSubComponentDefs, newCompositeCodec, newMandatory, newLengthCodec);
        }
      }

      return newDef;
    }