org.gbif.datatester
Class KnownConcepts

java.lang.Object
  extended by org.gbif.datatester.KnownConcepts

public class KnownConcepts
extends java.lang.Object

Class that provides access to information about Concepts.

The original idea was to have a simple and lightweight object capable of keeping a small map of Concepts in memory. So instead of using a real interface with many possible implementations, this single class with one constructor per possible concept storage mechanism was prefered.

So the main idea for this class is to read Concept definitions from some place (currently an XML file), load them into a simple hash map, and provide access to Concept objects through their identifiers.

Two initial constructors are available: one receiving a set of Concept objects (convenient for unit tests) and the other one receiving a file handle to read Concept definitions from an XML document as seen in the example below. In the future other storage mechanisms could be supported, like a relational database or a conceptual schema-repository.

 <?xml version="1.0" encoding="UTF-8" ?>
 <concepts>
   <concept id="CatalogNumber"  type="string"/>
   <concept id="Latitude"       type="double"/>
   <concept id="Longitude"      type="double"/>
   <concept id="Country"        type="string"/>
   <concept id="ScientificName" type="string"/>
 </concepts>
 

In the XML above, the attribute id should be a unique identifier in the document context. And the possible values for the type attribute are currently "string", "double" and "integer" - each one must correspond to a DataType identifier.

Access to any known Concept is usually achieved through these steps:

 File configFile = new File( "/some/directory/concepts.xml" );
 KnownConcepts kc = new KnownConcepts( configFile );
 
 Concept latitude = kc.getConcept( "Latitude" );
 

Note that Concept labels can be defined in another file (a resource bundle) and the methods to configure and manipulate Locale and ResourceBundle are located on the the static level of the Concept class.

Version:
$Revision: 1.3 $
Author:
Renato De Giovanni ( renato at cria . org . br )

Constructor Summary
KnownConcepts(java.io.File configFile)
          Constructs a map of known concepts based on the definitions in an XML file.
KnownConcepts(java.util.Set concepts)
          Constructs a map of known concepts based on a set of concept objects.
 
Method Summary
 Concept getConcept(java.lang.String conceptId)
          Returns the concept object related to the given id.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KnownConcepts

public KnownConcepts(java.util.Set concepts)
              throws UnableToLoadConceptsException

Constructs a map of known concepts based on a set of concept objects.

Parameters:
concepts - A set of concept objects.
Throws:
UnableToLoadConceptsException

KnownConcepts

public KnownConcepts(java.io.File configFile)
              throws UnableToLoadConceptsException

Constructs a map of known concepts based on the definitions in an XML file.

Parameters:
configFile - File handle to the XML document containing concept definitions.
Throws:
UnableToLoadConceptsException
Method Detail

getConcept

public Concept getConcept(java.lang.String conceptId)
                   throws ConceptNotFoundException

Returns the concept object related to the given id.

Parameters:
conceptId - Concept identifier.
Returns:
Concept object.
Throws:
ConceptNotFoundException