Added by jgarnett, last edited by jgarnett on Mar 31, 2008  (view change)

Labels

 
(None)

The org.opengis.feature.Name interface is used to identify the data structures used as part of the "feature model". A Name can be used as a key (equals and hashcode are specified) and is similar to the concept of an XML QName without the idea of a "prefix".

Creating

You can create a specific name:

Name roadName = new NameImpl("http://localhost/","Road");

String localName = roadName.getLocalPart();
String namespace = roadName.getNamespaceURI(); // yes this is actually a String

This name is specific, and while not a singleton it can be treated as a unqiue and immutable object.

Creating a Global Name

Name roadName = new NameImpl(null,"Road");

roadName.isGlobal(); // true! roadName.getNamespaceURI() == null

GeoTools code has fallen into using a global name to represent a "local" name (ie something with unknown context). This steps outside of the use supported by the GeoAPI interface:

Name roadName = new NameImpl("size");

The implementation seems to treat this as a global name? Specifically getNameSpaceUI would be null and isGlobal() returns true. It may be more usefull to treat this as a new NameImpl( "*", "size" ) and insure that Equals knows about the contract.

Comparison

Name objects are treated as equals if they represent the same thing in the end. As such you will need to use equals rather than == when checking Names.

Name name1 = new Name( "gopher://localhost/example", "name" );
Name name2 = new Name( "gopher://localhost", "example/name" );

name1.equals( name2 ); // true they both represent gopher://localhost/example/name