Class TFrame

java.lang.Object
org.cdlib.mrt.utility.TFrame

public class TFrame extends Object
  • Field Details

    • NAME

      protected static final String NAME
      See Also:
    • MESSAGE

      protected static final String MESSAGE
      See Also:
    • DEBUG

      protected static final boolean DEBUG
      See Also:
    • loadExceptionLevel

      protected static LoggerInf.LogLevel loadExceptionLevel
    • m_properties

      protected MProperties m_properties
    • m_logger

      protected LoggerInf m_logger
    • m_frameworkID

      protected String m_frameworkID
    • m_httpServletRequest

      protected javax.servlet.http.HttpServletRequest m_httpServletRequest
    • m_classRegistry

      protected Hashtable m_classRegistry
      Registered classes
    • m_instanceRegistry

      protected Hashtable m_instanceRegistry
      Registered instances. When a single instance of a registered class is desired, an instance is added to this registry.
  • Constructor Details

    • TFrame

      public TFrame(String[] propertiesFileNames) throws TException
      Constructs a framework, loading properties from one or more property files. Files are loaded by the class loader as resources.
      Parameters:
      propertiesFileNames - An array of property file names. Names are relative to the base of the classpath.
      frameworkID - Identifier for the framework. The identifier will appear in log entries.
      Throws:
      TException
    • TFrame

      public TFrame(String[] propertiesFileNames, String frameworkID) throws TException
      Constructs a framework, loading properties from one or more property files. Files are loaded by the class loader as resources.
      Parameters:
      propertiesFileNames - An array of property file names. Names are relative to the base of the classpath.
      Throws:
      TException
    • TFrame

      public TFrame(String[] propertiesFileNames, String frameworkID, String servicePathName) throws TException
      Constructs a framework, loading properties from one or more property files. Files are loaded by the class loader as resources.
      Parameters:
      propertiesFileNames - An array of property file names. Names are relative to the base of the classpath.
      frameworkID - used on log entries
      servicePath - optional path to a file based properties
      Throws:
      TException
  • Method Details

    • loadServiceProperties

      protected void loadServiceProperties(String servicePathName) throws TException
      Load properties from an optional supplied path. If the path is supplied and not valid then an exception will occur
      Parameters:
      servicePathName - Name of current property that contains a File path to service based properties
      Throws:
      TException
    • loadLogger

      protected LoggerInf loadLogger(String logPath) throws TException
      Loads the registered logger. The logger is loaded by reading the framework property 'Logger' and instantiating an object for the class named in the property's value.

      The object that is instantiated is expected to implement the Logger interface. If it does not, a default Logger is created and returned.

      Returns:
      The Logger object
      Throws:
      TException
    • setHttpServletRequest

      public void setHttpServletRequest(javax.servlet.http.HttpServletRequest httpServletRequest)
      save servlet requeest
      Parameters:
      httpServletRequest - current servlet request
    • getHttpServletRequest

      public javax.servlet.http.HttpServletRequest getHttpServletRequest()
      return servlet requeest
      Returns:
      current servlet request
    • getLogger

      public LoggerInf getLogger()
      Returns the current logger
      Returns:
      The Logger object
    • getProperties

      public Properties getProperties()
      Return a deep clone of framework properties
      Returns:
      the framework properties with each element copied
    • getProperty

      public String getProperty(String propertyName)
      Gets a framework property
      Parameters:
      propertyName - Name of the property whose value is to be retrieved
      Returns:
      The value of the property
    • getProperty

      public String getProperty(String propertyName, String propertyDefault)
    • getResource

      public InputStream getResource(String resourceName) throws TException
      Gets a resource using the class loader
      Parameters:
      resourceName - Name of the file containing the resource. The name may include a relative path which is interpreted as being relative to the path "resources/" below the classpath root.
      Returns:
      An inputstream for the resource
      Throws:
      TException
    • addNewProperty

      public void addNewProperty(String propertyName, String propertyValue)
      Saves a framework property if property does not exist
      Parameters:
      propertyName - Name of the property to be saved
      propertyValue - Value of the property to be saved
    • setProperty

      public void setProperty(String propertyName, String propertyValue)
      Sets a framework property and adds it if it doesn't already exist
      Parameters:
      propertyName - Name of the property to be saved
      propertyValue - Value of the property to be saved
    • getComponentClass

      protected Class getComponentClass(String propertyName)
      Gets a class associated with a property name in the framework's properties.
      Parameters:
      propertyName - The name of a property in the framework properties that has the class name as its corresponding value
      Returns:
      A Class object for the class
    • registerClasses

      protected void registerClasses()
      Registers classes by examining the framework properties and extracting values for all keys starting with "class". Each value is assumed to be the name of a class to be registered.
    • instantiate

      public Object instantiate(String registryKey) throws TException
      Creates an instance of a registered class.
      Parameters:
      registryKey - The value of the registry key associated with the registered class. This is the value to the right of "class." in the properties file entry for the class.
      Returns:
      An object of the class
      Throws:
      InstantiationException - if the object can not be instantiated
      TException
    • instantiateAll

      public Vector instantiateAll(String registryKey) throws TException
      Creates instances of all registered classes sharing a common registry key
      Parameters:
      registryKey - The value of the registry key associated with the registered class. This is the value to the right of "class." in the properties file entry for the class. More than one class is associated with the registry key by appending ".n" to the right of the key, where "n" varies from 1 to the number of classes associated with the key. For example, multiple classes are associated with the key "foo" as follows:
    • class.foo.1 = org.cdlib.mstor.ingest.FooFirst
    • class.foo.2 = org.cdlib.mstor.ingest.FooSecond
    • class.foo.3 = org.cdlib.mstor.ingest.FooThird
    • Returns:
      A vector containing the instantiated objects
      Throws:
      InstantiationException - if the object can not be instantiated
      TException
    • getSingleInstances

      public Vector getSingleInstances(String registryKey) throws TException
      Gets the single instance of each class associated with a registry key.
      Parameters:
      registryKey - The value of the registry key associated with the registered class. This is the value to the right of "class." in the properties file entry for the class. More than one class is associated with the registry key by appending ".n" to the right of the key, where "n" varies from 1 to the number of classes associated with the key. For example, multiple classes are associated with the key "foo" as follows:
    • class.foo.1 = org.cdlib.mstor.ingest.FooFirst
    • class.foo.2 = org.cdlib.mstor.ingest.FooSecond
    • class.foo.3 = org.cdlib.mstor.ingest.FooThird
    • Returns:
      A vector containing the single instance objects
      Throws:
      InstantiationException - if the object can not be instantiated
      TException
    • getSingleInstance

      public Object getSingleInstance(String registryKey) throws TException
      Gets the single instance of a 'singleton' patterned class. Checks the instance registry to see if an instance of the desired class has already been created, and returns the single instance if it has. If there is no existing instance, one is created, registered and returned.
      Parameters:
      registryKey - The value of the registry key associated with the registered class and instance. This is the value to the right of "class." in the properties file entry for the class.
      Returns:
      An object of the class
      Throws:
      InstantiationException - if the object can not be instantiated
      TException
    • initialize

      protected void initialize(Object object)
      If object implements MFrameComponent, initialize it.
      Parameters:
      object - Object to be initialized
    • getAllProperties

      public Properties getAllProperties()
      Returns all framework properties
      Parameters:
      none -
      Returns:
      the Properties object within the framework
    • getMFrameID

      public String getMFrameID()
      Returns the service identifier
      Returns:
      the identifier
    • getRegistry

      public Object getRegistry(String key, String service)
      Returns a generic handler for a specified type of service.
      Parameters:
      key - type of class
      service - An identifier of the service
      Returns:
      An object that implements the GenericHandler that is registered to generic for the specified service
      Throws:
      InstantiationException - if an object can not be instantiated
    • logDebug

      protected void logDebug(String msg)