Package gda.factory

Enum Class Finder

All Implemented Interfaces:
Serializable, Comparable<Finder>, Constable

public enum Finder extends Enum<Finder>
Finder, a singleton class, allows objects to be retrieved from local store, a name service or created by a factory.

For unit testing classes which depend on the Finder, set up the Finder first with a test factory (see TestHelpers in the uk.ac.gda.test.helpers bundle) and add any necessary Findables for the test to it. For example:

 
 public void setUp() throws Exception {
        // .. set up mocks first
        Factory testFactory = TestHelpers.createTestFactory("test");
        testFactory.addFindable(mockFindable);
        Finder.addFactory(testFactory);
 }
 
 
  • Enum Constant Details

    • INSTANCE

      public static final Finder INSTANCE
  • Method Details

    • values

      public static Finder[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static Finder valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • find

      public static <T extends Findable> T find(String name)
      Return a named object from any of the factories known to the finder.
      Type Parameters:
      T - class of Object being returned
      Parameters:
      name - object to find.
      Returns:
      the findable object or null if it cannot be found
    • findOptionalOfType

      public static <T extends Findable> Optional<T> findOptionalOfType(String name, Class<T> findableType)
      Return a Optional named object from any of the factories known to the finder.
      Type Parameters:
      T - class of Optional Object being returned
      Parameters:
      name - The object to find
      findableType - The class or interface to match
      Returns:
      the Optional findable object
    • addFactory

      public static void addFactory(Factory factory)
      Adds a factory to the list of searchable factories known by the Finder.
      Parameters:
      factory - the factory to add to the list.
    • removeAllFactories

      public static void removeAllFactories()
    • listAllInterfaces

      public static List<String> listAllInterfaces()
      List all the interfaces available on the Finder. This method is aimed at users of the scripting environment for searching for available hardware by using the 'list' command.
      Returns:
      array of interface names
    • getFindablesOfType

      public static <T extends Findable> Map<String,T> getFindablesOfType(Class<T> clazz)
      Returns a map of all Findable objects (local invalid input: '&' remote) of the given type
      Type Parameters:
      T -
      Parameters:
      clazz - the class or interface to match
      Returns:
      a map of matching Findables, with the object names as keys and the objects as values
    • getLocalFindablesOfType

      public static <T extends Findable> Map<String,T> getLocalFindablesOfType(Class<T> clazz)
      Returns a map of all local Findable objects of the given type
      Parameters:
      clazz - the class or interface to match
      Returns:
      a map of matching Findables, with the object names as keys and the objects as values
    • listFindablesOfType

      public static <T extends Findable> List<T> listFindablesOfType(Class<T> clazz)
      Returns a list of all Findable objects (local invalid input: '&' remote) of the given type
      Parameters:
      clazz - the class or interface to match
      Returns:
      a list of matching Findables
    • listLocalFindablesOfType

      public static <T extends Findable> List<T> listLocalFindablesOfType(Class<T> clazz)
      Returns a list of all local Findable objects of the given type
      Parameters:
      clazz - the class or interface to match
      Returns:
      a list of matching Findables
    • findSingleton

      public static <T extends Findable> T findSingleton(Class<T> singletonClass)
      Returns the singleton of specified type. This method removes the need for singletons to have a specific name.
      Parameters:
      singletonClass - the singleton type
      Returns:
      the singleton
      Throws:
      IllegalArgumentException - if multiple/no instances of specified type found
    • findLocalSingleton

      public static <T extends Findable> T findLocalSingleton(Class<T> singletonClass)
      Returns the local singleton of specified type. This method removes the need for singletons to have a specific name.
      Parameters:
      singletonClass - the singleton type
      Returns:
      the singleton
      Throws:
      IllegalArgumentException - if multiple/no instances of specified type found
    • findOptionalSingleton

      public static <T extends Findable> Optional<T> findOptionalSingleton(Class<T> singletonClass)
      Returns the singleton of specified type. This method removes the need for singletons to have a specific name.
      Parameters:
      singletonClass - the singleton type
      Returns:
      the singleton
      Throws:
      IllegalArgumentException - if multiple instances of specified type found
    • findOptionalLocalSingleton

      public static <T extends Findable> Optional<T> findOptionalLocalSingleton(Class<T> singletonClass)
      Returns the local singleton of specified type. This method removes the need for singletons to have a specific name.
      Parameters:
      singletonClass - the singleton type
      Returns:
      the singleton
      Throws:
      IllegalArgumentException - if multiple instances of specified type found
    • writeFindablesJythonModule

      public static Optional<File> writeFindablesJythonModule() throws FactoryException

      Generates a Jython module of Findable instances.

      GDA properties control whether the module generation is enabled (i.e. whether the module is generated and written at all) (default: true), the name of the module (default: gdaserver), and where the module is written (default: ${gda.config}/scripts). If the module is written to a non-default directory, the non-default directory should be specified in the list of script paths of the Jython server (i.e. the command_server bean) so that the module can be found when referenced from the Jython terminal or by another script.

      Once written, other Jython modules can access Findable objects using, e.g.:

      from gdaserver import gripper_x, gripper_grp as gripper_jaws

      And in Eclipse, PyDev can provide type-inferred auto-completion on:

      gripper_jaws.[Ctrl-1]

      Documented further on Confluence.

      Throws:
      FactoryException - if the file could not be written