Exemplo n.º 1
0
  private void check(DataSchema older, DataSchema newer) {
    Checked toCheck = new Checked(older, newer);
    if (_checked.contains(toCheck)) {
      return;
    }
    _checked.add(toCheck);

    if (older == newer) {
      return;
    }

    int pathCount = 1;
    if (_options.getMode() == CompatibilityOptions.Mode.DATA) {
      older = older.getDereferencedDataSchema();
      while (newer.getType() == DataSchema.Type.TYPEREF) {
        TyperefDataSchema typerefDataSchema = ((TyperefDataSchema) newer);
        _path.addLast(typerefDataSchema.getFullName());
        _path.addLast(DataSchemaConstants.REF_KEY);
        pathCount++;
        newer = typerefDataSchema.getRef();
      }
    }
    if (newer.getType() == DataSchema.Type.TYPEREF) {
      _path.addLast(((TyperefDataSchema) newer).getFullName());
    } else {
      _path.addLast(newer.getUnionMemberKey());
    }

    switch (newer.getType()) {
      case TYPEREF:
        if (isSameType(older, newer))
          checkTyperef((TyperefDataSchema) older, (TyperefDataSchema) newer);
        break;
      case RECORD:
        if (isSameType(older, newer))
          checkRecord((RecordDataSchema) older, (RecordDataSchema) newer);
        break;
      case ARRAY:
        if (isSameType(older, newer)) checkArray((ArrayDataSchema) older, (ArrayDataSchema) newer);
        break;
      case MAP:
        if (isSameType(older, newer)) checkMap((MapDataSchema) older, (MapDataSchema) newer);
        break;
      case ENUM:
        if (isSameType(older, newer)) checkEnum((EnumDataSchema) older, (EnumDataSchema) newer);
        break;
      case FIXED:
        if (isSameType(older, newer)) checkFixed((FixedDataSchema) older, (FixedDataSchema) newer);
        break;
      case UNION:
        if (isSameType(older, newer)) checkUnion((UnionDataSchema) older, (UnionDataSchema) newer);
        break;
      default:
        if (newer instanceof PrimitiveDataSchema) checkPrimitive(older, newer);
        else
          throw new IllegalStateException(
              "Unknown schema type "
                  + newer.getType()
                  + ", checking old schema "
                  + older
                  + ", new schema "
                  + newer);
        break;
    }

    for (; pathCount > 0; pathCount--) {
      _path.removeLast();
    }
    return;
  }
Exemplo n.º 2
0
 private void checkTyperef(TyperefDataSchema older, TyperefDataSchema newer) {
   checkName(older, newer);
   _path.addLast(DataSchemaConstants.REF_KEY);
   check(older.getDereferencedDataSchema(), newer.getDereferencedDataSchema());
   _path.removeLast();
 }