コード例 #1
0
  protected static String getSegmentTag(Field field, boolean inner) {
    Class<?> clz = field.getType();

    if (Collection.class.isAssignableFrom(clz)) {
      clz = getCollectionType(field);
    }

    if (clz.isAnnotationPresent(EDISegment.class)) {
      EDISegment es = clz.getAnnotation(EDISegment.class);
      return es.tag();
    } else if (clz.isAnnotationPresent(EDISegmentGroup.class)) {
      EDISegmentGroup esg = clz.getAnnotation(EDISegmentGroup.class);

      String ediSegmentGroupTag = esg.header();

      if (!inner && StringUtils.isNotBlank(ediSegmentGroupTag)) {
        return ediSegmentGroupTag;
      } else {
        // get the segement group's first field, and recurse.
        if (clz.getDeclaredFields().length > 0) {
          return getSegmentTag(clz.getDeclaredFields()[0], false);
        }
      }
    }

    return null;
  }
コード例 #2
0
  protected static boolean matchesSegment(Field field, String segmentTag) {
    Class<?> clz = field.getType();

    if (Collection.class.isAssignableFrom(clz)) {
      clz = getCollectionType(field);
    }

    if (clz.isAnnotationPresent(EDISegment.class)) {
      EDISegment es = clz.getAnnotation(EDISegment.class);
      if (StringUtils.equals(segmentTag, es.tag())) {
        return true;
      }
    } else if (clz.isAnnotationPresent(EDISegmentGroup.class)) {
      EDISegmentGroup esg = clz.getAnnotation(EDISegmentGroup.class);

      String ediSegmentGroupTag = esg.header();

      if (StringUtils.isNotBlank(ediSegmentGroupTag)) {
        if (StringUtils.equals(segmentTag, ediSegmentGroupTag)) {
          return true;
        }
      } else {
        // get the segement group's first field, and recurse.
        if (clz.getDeclaredFields().length > 0) {
          return matchesSegment(clz.getDeclaredFields()[0], segmentTag);
        }
      }
    }

    return false;
  }
コード例 #3
0
  protected static Queue<String> queueLinesForType(
      EDIMessage ediMessage,
      EDISegment segment,
      Queue<String> lookAhead,
      SegmentIterator SegmentIterator) {
    Queue<String> segments = new LinkedList<String>();

    while (SegmentIterator.hasNext()) {
      String line = SegmentIterator.next();
      StringTokenizer tokenizer =
          new StringTokenizer(line, CharUtils.toString(ediMessage.elementDelimiter()));
      String token = tokenizer.nextToken();

      if (StringUtils.equals(segment.tag(), token)) {
        segments.add(line);
      } else {
        lookAhead.add(line);
        break;
      }
    }

    return segments;
  }