public Class getClass()

in lang/java/avro/src/main/java/org/apache/avro/specific/SpecificData.java [358:417]


  public Class getClass(Schema schema) {
    switch (schema.getType()) {
    case FIXED:
    case RECORD:
    case ENUM:
      String name = schema.getFullName();
      if (name == null)
        return null;
      Class<?> c = classCache.computeIfAbsent(name, n -> {
        try {
          return ClassUtils.forName(getClassLoader(), getClassName(schema));
        } catch (ClassNotFoundException e) {
          // This might be a nested namespace. Try using the last tokens in the
          // namespace as an enclosing class by progressively replacing period
          // delimiters with $
          StringBuilder nestedName = new StringBuilder(n);
          int lastDot = n.lastIndexOf('.');
          while (lastDot != -1) {
            nestedName.setCharAt(lastDot, '$');
            try {
              return ClassUtils.forName(getClassLoader(), nestedName.toString());
            } catch (ClassNotFoundException ignored) {
            }
            lastDot = n.lastIndexOf('.', lastDot - 1);
          }
          return NO_CLASS;
        }
      });
      return c == NO_CLASS ? null : c;
    case ARRAY:
      return List.class;
    case MAP:
      return Map.class;
    case UNION:
      List<Schema> types = schema.getTypes(); // elide unions with null
      if ((types.size() == 2) && types.contains(NULL_SCHEMA))
        return getWrapper(types.get(types.get(0).equals(NULL_SCHEMA) ? 1 : 0));
      return Object.class;
    case STRING:
      if (STRING_TYPE_STRING.equals(schema.getProp(STRING_PROP)))
        return String.class;
      return CharSequence.class;
    case BYTES:
      return ByteBuffer.class;
    case INT:
      return Integer.TYPE;
    case LONG:
      return Long.TYPE;
    case FLOAT:
      return Float.TYPE;
    case DOUBLE:
      return Double.TYPE;
    case BOOLEAN:
      return Boolean.TYPE;
    case NULL:
      return Void.TYPE;
    default:
      throw new AvroRuntimeException("Unknown type: " + schema);
    }
  }