Package org.cdlib.mrt.utility
Class TFrame
java.lang.Object
org.cdlib.mrt.utility.TFrame
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final boolean
protected static LoggerInf.LogLevel
protected Hashtable
Registered classesprotected String
protected javax.servlet.http.HttpServletRequest
protected Hashtable
Registered instances.protected LoggerInf
protected MProperties
protected static final String
protected static final String
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a framework, loading properties from one or more property files.Constructs a framework, loading properties from one or more property files.Constructs a framework, loading properties from one or more property files. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addNewProperty
(String propertyName, String propertyValue) Saves a framework property if property does not existReturns all framework propertiesprotected Class
getComponentClass
(String propertyName) Gets a class associated with a property name in the framework's properties.javax.servlet.http.HttpServletRequest
return servlet requeestReturns the current loggerReturns the service identifierReturn a deep clone of framework propertiesgetProperty
(String propertyName) Gets a framework propertygetProperty
(String propertyName, String propertyDefault) getRegistry
(String key, String service) Returns a generic handler for a specified type of service.getResource
(String resourceName) Gets a resource using the class loadergetSingleInstance
(String registryKey) Gets the single instance of a 'singleton' patterned class.getSingleInstances
(String registryKey) Gets the single instance of each class associated with a registry key.protected void
initialize
(Object object) If object implements MFrameComponent, initialize it.instantiate
(String registryKey) Creates an instance of a registered class.instantiateAll
(String registryKey) Creates instances of all registered classes sharing a common registry keyprotected LoggerInf
loadLogger
(String logPath) Loads the registered logger.protected void
loadServiceProperties
(String servicePathName) Load properties from an optional supplied path.protected void
protected void
Registers classes by examining the framework properties and extracting values for all keys starting with "class".void
setHttpServletRequest
(javax.servlet.http.HttpServletRequest httpServletRequest) save servlet requeestvoid
setProperty
(String propertyName, String propertyValue) Sets a framework property and adds it if it doesn't already exist
-
Field Details
-
NAME
- See Also:
-
MESSAGE
- See Also:
-
DEBUG
protected static final boolean DEBUG- See Also:
-
loadExceptionLevel
-
m_properties
-
m_logger
-
m_frameworkID
-
m_httpServletRequest
protected javax.servlet.http.HttpServletRequest m_httpServletRequest -
m_classRegistry
Registered classes -
m_instanceRegistry
Registered instances. When a single instance of a registered class is desired, an instance is added to this registry.
-
-
Constructor Details
-
TFrame
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
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 entriesservicePath
- optional path to a file based properties- Throws:
TException
-
-
Method Details
-
loadServiceProperties
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
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
Returns the current logger- Returns:
- The Logger object
-
getProperties
Return a deep clone of framework properties- Returns:
- the framework properties with each element copied
-
getProperty
Gets a framework property- Parameters:
propertyName
- Name of the property whose value is to be retrieved- Returns:
- The value of the property
-
getProperty
-
getResource
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
Saves a framework property if property does not exist- Parameters:
propertyName
- Name of the property to be savedpropertyValue
- Value of the property to be saved
-
setProperty
Sets a framework property and adds it if it doesn't already exist- Parameters:
propertyName
- Name of the property to be savedpropertyValue
- Value of the property to be saved
-
getComponentClass
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
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 instantiatedTException
-
instantiateAll
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 instantiatedTException
-
getSingleInstances
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 instantiatedTException
-
getSingleInstance
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 instantiatedTException
-
initialize
If object implements MFrameComponent, initialize it.- Parameters:
object
- Object to be initialized
-
getAllProperties
Returns all framework properties- Parameters:
none
-- Returns:
- the Properties object within the framework
-
getMFrameID
Returns the service identifier- Returns:
- the identifier
-
getRegistry
Returns a generic handler for a specified type of service.- Parameters:
key
- type of classservice
- 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
-