Package org.biojavax

Class RichObjectFactory


  • public class RichObjectFactory
    extends Object
    Runs a service that builds rich objects, and provides some default values for things like default ontology, default namespace, etc.
    Since:
    1.5
    Author:
    Richard Holland
    • Method Detail

      • setRichObjectBuilder

        public static void setRichObjectBuilder​(RichObjectBuilder b)
        Sets the builder to use when instantiating new Rich objects. The basic, default, one is a SimpleRichObjectBuilder, which just calls the constructor. Another useful one is BioSQLRichObjectBuilder, which attempts to load objects from the database. The latter is required if you are working with Hibernate as it will not work without it.
        Parameters:
        b - the builder to use.
        See Also:
        SimpleRichObjectBuilder, BioSQLRichObjectBuilder
      • getObject

        public static Object getObject​(Class clazz,
                                       Object[] params)
        Delegates to a RichObjectBuilder to construct/retrieve the object, and returns it. To increase efficiency, it keeps a list of recently requested objects. If it receives further requests for the same object, it returns them from the cache. The size of the cache can be altered using setLRUCacheSize(). The default cache size is 20 objects for each type of class requested.
        Parameters:
        clazz - the class to build
        params - the parameters to pass to the class' constructor
        Returns:
        the instantiated object
      • setApplicationClass

        public static final void setApplicationClass​(Class theBiojavaClass,
                                                     Class theApplicationClass)
        Allow application to override the default biojava class created in getObject - subclass restriction is checked in the builder.
        Parameters:
        theBiojavaClass - one of the well-known builder classes: SimpleNamespace, SimpleComparableOntology, SimpleNCBITaxon, SimpleCrossRef, or SimpleDocRef
        theApplicationClass - - a subclass of theBiojavaClass
      • clearLRUCache

        public static void clearLRUCache()
        Removes all objects from the LRU cache.
      • clearLRUCache

        public static void clearLRUCache​(Class clazz)
        Removes all objects of the specified class from the LRU cache.
        Parameters:
        clazz - The class of the objects to remove.
      • setLRUCacheSize

        public static void setLRUCacheSize​(int size)
        Sets the size of the LRU cache. This is the size per class of object requested, so if you set it to 20 and request 3 different types of object, you will get 20*3=60 entries in the cache. The default cache size is 20. Setting this value will undo any previous changes made using the setLRUCacheSize(Class,int) method below, but will not override future ones.
        Parameters:
        size - the size of the cache.
      • setLRUCacheSize

        public static void setLRUCacheSize​(Class clazz,
                                           int size)
        Sets the size of the LRU cache. This is the size for the specific class of object requested, so does not affect the size of caches of other objects. If this method is not called, then the cache size defaults to 20, or whatever value was passed to setLRUCacheSize(int) above.
        Parameters:
        size - the size of the cache.
      • setDefaultNamespaceName

        public static void setDefaultNamespaceName​(String name)
        Sets the default namespace name to use when loading sequences. Defaults to "lcl".
        Parameters:
        name - the namespace name to use.
      • setDefaultOntologyName

        public static void setDefaultOntologyName​(String name)
        Sets the default ontology name to use when loading sequences. Defaults to "biojavax".
        Parameters:
        name - the ontology name to use.
      • getDefaultNamespace

        public static Namespace getDefaultNamespace()
        Returns the default namespace object. Defaults to "lcl".
        Returns:
        the default namespace.