Class DataStoreFactory

java.lang.Object
org.codelibs.fess.ds.DataStoreFactory

public class DataStoreFactory extends Object
Factory class responsible for managing and providing access to data store instances. This factory maintains a registry of data store implementations and provides methods to register, retrieve, and discover available data stores.

Data stores are registered by name and class name, allowing flexible lookup. The factory also supports dynamic discovery of data store plugins by scanning JAR files for data store configurations.

Thread-safe operations are supported for registration and retrieval of data stores. The factory caches data store names with a time-based refresh mechanism to improve performance while ensuring up-to-date plugin discovery.

  • Field Details

    • dataStoreMap

      protected Map<String,DataStore> dataStoreMap
      Map containing registered data store instances indexed by their names and class simple names. All keys are stored in lowercase for case-insensitive lookup.
    • dataStoreNames

      protected volatile String[] dataStoreNames
      Cached array of available data store names discovered from plugin JAR files. This cache is refreshed periodically based on the lastLoadedTime.
    • lastLoadedTime

      protected volatile long lastLoadedTime
      Timestamp of the last time data store names were loaded from plugin files. Used to implement a time-based cache refresh mechanism. Volatile to ensure visibility across threads.
  • Constructor Details

    • DataStoreFactory

      public DataStoreFactory()
      Creates a new instance of DataStoreFactory. This constructor initializes the factory for managing data store instances and provides methods for registration, retrieval, and plugin discovery.
  • Method Details

    • add

      public void add(String name, DataStore dataStore)
      Registers a data store instance with the factory using the specified name. The data store will be accessible by both the provided name and its class simple name, both converted to lowercase for case-insensitive lookup.
      Parameters:
      name - the name to register the data store under, must not be null
      dataStore - the data store instance to register, must not be null
      Throws:
      IllegalArgumentException - if either name or dataStore is null
    • getDataStore

      public DataStore getDataStore(String name)
      Retrieves a data store instance by name. The lookup is case-insensitive and will match both registered names and class simple names.
      Parameters:
      name - the name of the data store to retrieve, may be null
      Returns:
      the data store instance if found, null if not found or name is null
    • getDataStoreNames

      public String[] getDataStoreNames()
      Returns an array of available data store names discovered from plugin JAR files. This method implements a time-based caching mechanism that refreshes the list every 60 seconds to balance performance with up-to-date plugin discovery.
      Returns:
      array of data store names sorted alphabetically, never null
    • loadDataStoreNameList

      protected List<String> loadDataStoreNameList()
      Loads the list of available data store names by scanning plugin JAR files. This method searches for 'fess_ds++.xml' configuration files within JAR files in the data store plugin directory and extracts component class names.

      The method uses secure XML parsing features to prevent XXE attacks and other XML-based vulnerabilities. Component class names are extracted from the 'class' attribute of 'component' elements in the XML files.

      Returns:
      sorted list of data store class simple names discovered from plugins