Class TermFactory

java.lang.Object
org.gbif.dwc.terms.TermFactory

public class TermFactory extends Object
Simple, threadsafe factory for terms that knows about all ConceptTerms of this library and keeps singletons for all unknown Term instances.
  • Method Details

    • instance

      public static TermFactory instance()
    • listRegisteredTermEnums

      public Set<Class<? extends Enum>> listRegisteredTermEnums()
      Returns:
      the set of term enum classes that have been registered with this TermFactory
    • registerTerm

      public void registerTerm(Term term)
    • registerTerm

      public void registerTerm(UnknownTerm term)
    • 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

      public <T extends Enum & Term> void registerQualifiedTermEnum(Class<T> termClass)
      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

      public static String normaliseTerm(String term)
      Returns:
      a purely alphanumerical, lower cased term with all other characters replaced
    • findTerm

      public Term findTerm(String termName) throws IllegalArgumentException
      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

      public Term findTerm(String termName, boolean isClassTerm) throws IllegalArgumentException
      This method works just as findTerm(final String termName) but restricts the results to just property or class terms.
      Throws:
      IllegalArgumentException