Class TypeNames

java.lang.Object
org.apache.sis.util.iso.TypeNames

final class TypeNames extends Object
Implements the mapping between Class and TypeName documented in DefaultTypeName.
Since:
0.5
Version:
1.3
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final org.opengis.util.NameSpace
    The "class" namespace.
    private static final Map<String,Class<?>>
    The mapping between TypeName and Class as documented in DefaultTypeName.
    private final org.opengis.util.NameSpace
    The "OGC" namespace.
  • Constructor Summary

    Constructors
    Constructor
    Description
    TypeNames(org.opengis.util.NameFactory factory)
    Creates a new factory of type names.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) static boolean
    isValid(Class<?> valueClass)
    Ensures that the given class is non-null and not Void.TYPE.
    (package private) static String
    namespace(org.opengis.util.NameSpace ns)
    Null-safe getter for the namespace argument to be given to toClass(String, String).
    (package private) static Class<?>
    toClass(String namespace, String name)
    Returns the class for a TypeName made of the given scope and name.
    (package private) final org.opengis.util.TypeName
    toTypeName(org.opengis.util.NameFactory factory, Class<?> valueClass)
    Infers the type name from the given class.
    (package private) static String
    unknown(org.opengis.util.GenericName name)
    Formats the error message for an unknown type.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MAPPING

      private static final Map<String,Class<?>> MAPPING
      The mapping between TypeName and Class as documented in DefaultTypeName. When searching for a name from a class, the values will be tested in iteration order.

      toTypeName(NameFactory, Class) will not iterate over all entries. Numbers and character strings are handled in a special way, so we do not need to iterate on them. We arbitrarily use Boolean.class as the sentinel value for detecting when to stop iteration.

      This map shall not be modified after construction.

    • ogcNS

      private final org.opengis.util.NameSpace ogcNS
      The "OGC" namespace.
    • classNS

      private final org.opengis.util.NameSpace classNS
      The "class" namespace.
  • Constructor Details

    • TypeNames

      TypeNames(org.opengis.util.NameFactory factory)
      Creates a new factory of type names.
  • Method Details

    • toTypeName

      final org.opengis.util.TypeName toTypeName(org.opengis.util.NameFactory factory, Class<?> valueClass)
      Infers the type name from the given class.
      Parameters:
      factory - the same factory than the one given to the constructor.
      valueClass - the value class for which to get a type name.
      Returns:
      a type name for the given class (never null).
    • toClass

      static Class<?> toClass(String namespace, String name) throws ClassNotFoundException
      Returns the class for a TypeName made of the given scope and name. This method is the converse of toTypeName(NameFactory, Class). There is 3 kinds of return value:
      • null if the namespace or the name is unrecognized, without considering that as an error.
      • Void.TYPE if namespace is recognized, but not the name. This is a sentinel value to be considered as an error by DefaultTypeName constructor.
      • Otherwise the class for the given name.
      Parameters:
      namespace - the namespace, case-insensitive. Can be any value, but this method recognizes only "OGC", "class" and null. Other namespaces will be ignored.
      name - the type name, case-sensitive.
      Returns:
      the class, or null if the given namespace is not recognized, or Void.TYPE if the namespace is recognized but not the type name.
      Throws:
      ClassNotFoundException - if namespace is "class" but name is not the name of a reachable class.
    • isValid

      static boolean isValid(Class<?> valueClass)
      Ensures that the given class is non-null and not Void.TYPE. This is a helper method for callers of toTypeName(NameFactory, Class).
    • namespace

      static String namespace(org.opengis.util.NameSpace ns)
      Null-safe getter for the namespace argument to be given to toClass(String, String).
    • unknown

      static String unknown(org.opengis.util.GenericName name)
      Formats the error message for an unknown type. This is a helper method for callers of toClass(String, String).