Package org.gbif.dwc.terms
Class TermFactory
java.lang.Object
org.gbif.dwc.terms.TermFactory
Simple, threadsafe factory for terms that knows about all ConceptTerms of this library and keeps singletons for
all unknown Term instances.
-
Method Summary
Modifier and TypeMethodDescriptionfindClassTerm
(String termName) This method works just as findTerm(final String termName) but restricts the results to just class terms.findPropertyTerm
(String termName) This method works just as findTerm(final String termName) but restricts the results to just property terms.This is the main method to get a term from the factory searching both for property or class terms.This method works just as findTerm(final String termName) but restricts the results to just property or class terms.static TermFactory
instance()
static String
normaliseTerm
(String term) registerQualifiedTermEnum
(Class<T> termClass) Registers all terms from a new term enumeration, but only adds their qualified and prefixed names.void
registerTerm
(Term term) void
registerTerm
(UnknownTerm term) <T extends Enum & Term & AlternativeNames>
voidregisterTermEnum
(Class<T> termClass, String... altPrefixes) Registers all terms from a term enumeration.
-
Method Details
-
instance
-
listRegisteredTermEnums
- Returns:
- the set of term enum classes that have been registered with this TermFactory
-
registerTerm
-
registerTerm
-
registerTermEnum
public <T extends Enum & Term & AlternativeNames> void registerTermEnum(Class<T> termClass, String... altPrefixes) Registers all terms from a term enumeration. If the same class is registered again it will be silently ignored.- Parameters:
altPrefixes
- alternative prefixes to be used to register simple prefixed term names
-
registerQualifiedTermEnum
Registers all terms from a new term enumeration, but only adds their qualified and prefixed names. This is to avoid clashes with other usually more important terms that should be known by their simple name. -
normaliseTerm
- Returns:
- a purely alphanumerical, lower cased term with all other characters replaced
-
findTerm
This is the main method to get a term from the factory searching both for property or class terms. It will lookup matching terms applying some normalization and known synonyms first. In case of ambiguous terms Class terms will be preferred. If nothing matches the factory creates a new UnknownTerm property instance and keeps it for further requests so that all terms with the same qualified name return a single UnknownTerm instance. For clearly bad term names an IllegalArgumentException is thrown. For example in the case of a simple name containing whitespace like "hello tom". Ideally the term names to be looked up should be full URIs, but simple names made up of alphanumerics and dashes will also work fine. Unknown simple names will be put into the namespace http://unknown.org when a new UnknownTerm instance is created.- Throws:
IllegalArgumentException
-
findPropertyTerm
This method works just as findTerm(final String termName) but restricts the results to just property terms.- Throws:
IllegalArgumentException
-
findClassTerm
This method works just as findTerm(final String termName) but restricts the results to just class terms.- Throws:
IllegalArgumentException
-
findTerm
This method works just as findTerm(final String termName) but restricts the results to just property or class terms.- Throws:
IllegalArgumentException
-