Package org.apache.sis.util.iso

# Class DefaultTypeName

Object
AbstractName
DefaultLocalName
DefaultTypeName

All Implemented Interfaces:
  `Serializable`, `Comparable<GenericName>`, `GenericName`, `LocalName`, `TypeName`

public class DefaultTypeName extends DefaultLocalName implements TypeName
The name of an attribute type associated to a member name. `DefaultTypeName` can be instantiated by any of the following methods:

- `DefaultNameFactory​.createTypeName(NameSpace, CharSequence)`
- `DefaultNameFactory​.toTypeName(Class)`

## Mapping Java classes to type names

It is sometime useful to establish a mapping between `Class` and `TypeName`. When an UML identifier from an OGC standard exists for a given `Class`, Apache SIS uses that identifier prefixed by the `"OGC"` namespace. Note that this is not a standard practice. A more standard practice would be to use the definition identifiers in OGC namespace (third column in the table below), but the set of data type identifiers defined by OGC is currently small and is sometime not an exact match.

Mapping from Java classes to type names (non-exhaustive list)
Java class | Type name (unofficial) | Definition identifier in OGC namespace | Recommended URL in Web Processing Services
--- | --- | --- | ---
`InternationalString` | `OGC:FreeText` |  |
`String` | `OGC:CharacterString` | `urn:ogc:def:dataType:OGC::string` | `http://www.w3.org/2001/XMLSchema#string`
`URI` | `OGC:URI` | `urn:ogc:def:dataType:OGC::anyURI` |
`Boolean` | `OGC:Boolean` | `urn:ogc:def:dataType:OGC::boolean` | `http://www.w3.org/2001/XMLSchema#boolean`
`Integer` | `OGC:Integer` | `urn:ogc:def:dataType:OGC::nonNegativeInteger` | `http://www.w3.org/2001/XMLSchema#integer`
`BigDecimal` | `OGC:Decimal` |  | `http://www.w3.org/2001/XMLSchema#decimal`
`Double` | `OGC:Real` |  | `http://www.w3.org/2001/XMLSchema#double`
`Float` | `OGC:Real` |  | `http://www.w3.org/2001/XMLSchema#float`
`Date` | `OGC:DateTime` |  |
`Locale` | `OGC:PT_Locale` |  |
`Metadata` | `OGC:MD_Metadata` |  |
Unknown Java class | `class:`<the class name> |  |

The mapping defined by Apache SIS may change in any future version depending on standardization progress. To protect against such changes, users are encouraged to rely on methods or constructors like `DefaultNameFactory​.toTypeName(Class)` or `toClass()` instead of parsing the name.

## Immutability and thread safety

This class is immutable and thus inherently thread-safe if the `NameSpace` and `CharSequence` arguments given to the constructor are also immutable. Subclasses shall make sure that any overridden methods remain safe to call from multiple threads and do not change any public `TypeName` state.

Since:
  0.3
See Also:
  - `DefaultMemberName`
  - `DefaultNameFactory`
  - Serialized Form

Defined in the `sis-metadata` module

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `DefaultTypeName(NameSpace scope, CharSequence name)`
  Constructs a type name from the given character sequence.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static DefaultTypeName`
  `castOrCopy(TypeName object)`
  Returns a SIS type name implementation with the values of the given arbitrary implementation.
  `Class<?>`
  `toClass()`
  Returns the Java class associated to this type name.

  ### Methods inherited from class DefaultLocalName

  `castOrCopy, compareTo, depth, equals, getParsedNames, head, scope, tip, toInternationalString, toString`

  ### Methods inherited from class AbstractName

  `castOrCopy, hashCode, push, toFullyQualifiedName`

  ### Methods inherited from class Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface Comparable

  `compareTo`

  ### Methods inherited from interface GenericName

  `push, scope, toFullyQualifiedName, toInternationalString`

  ### Methods inherited from interface LocalName

  `depth, getParsedNames, head, tip, toString`

- ## Constructor Details

  - ### DefaultTypeName

    protected DefaultTypeName(NameSpace scope, CharSequence name)
    Constructs a type name from the given character sequence. The argument are given unchanged to the super-class constructor.
    Parameters:
      `scope` - the scope of this name, or `null` for a global scope.
      `name` - the local name (never `null`).
    See Also:
      - `DefaultNameFactory​.createTypeName(NameSpace, CharSequence)`

- ## Method Details

  - ### castOrCopy

    public static DefaultTypeName castOrCopy(TypeName object)
    Returns a SIS type name implementation with the values of the given arbitrary implementation. This method performs the first applicable action in the following choices:
    - If the given object is `null`, then this method returns `null`.
    - Otherwise if the given object is already an instance of `DefaultTypeName`, then it is returned unchanged.
    - Otherwise a new `DefaultTypeName` instance is created with the same values than the given name.
    Parameters:
      `object` - the object to get as a SIS implementation, or `null` if none.
    Returns:
      a SIS implementation containing the values of the given object (may be the given object itself), or `null` if the argument was null.
    Since:
      0.5

  - ### toClass

    public Class<?> toClass() throws UnknownNameException
    Returns the Java class associated to this type name. The default implementation parses this name in different ways depending on the scope:
    - If the scope is `"OGC"`, then:
      - If the name is `"CharacterString"`, `"Integer"`, `"Real"` or other recognized names (see class javadoc), then the corresponding class is returned.
      - Otherwise `UnknownNameException` is thrown.
    - Else if the scope is `"class"`, then:
      - If the name is accepted by `Class​.forName(String)`, then that class is returned.
      - Otherwise `UnknownNameException` is thrown.
    - Else if the scope is global, then:
      - If the name is one of the names recognized in `"OGC"` scope (see above), then the corresponding class is returned.
      - Otherwise `null` is returned. No exception is thrown because names in the global namespace could be anything, so we can not be sure that the given name was wrong.
    - Otherwise `null` is returned, since this method can not check the validity of names in other namespaces.
    Returns:
      the Java class associated to this `TypeName`, or `null` if there is no mapping from this name to a Java class.
    Throws:
      `UnknownNameException` - if a mapping from this name to a Java class was expected to exist (typically because of the scope) but the operation failed.
    Since:
      0.5
    See Also:
      - `Names​.toClass(TypeName)`
      - `DefaultNameFactory​.toTypeName(Class)`