org.hackystat.sensorshell.usermap
Class SensorShellMap

java.lang.Object
  extended by org.hackystat.sensorshell.usermap.SensorShellMap

public class SensorShellMap
extends java.lang.Object

Allows for lazy instantiation of SensorShells for user tool accounts. This class abstracts the use of the UserMap class so that sensors for applicable tool sensors won't have to manage it.

The SensorShellMap is meant to only derive SensorShells for a specific tool. Queries for SensorShells are done by giving an account name to the getUserShell method. This account name must be specific to the tool of the SensorShellMap instance.

Note that the "tool" name is used in a case-insensitive fashion.

Author:
Burt Leung, Julie Ann Sakuda (v8 port)

Constructor Summary
SensorShellMap(java.lang.String tool)
          Instantiate this class which initializes the UserMap used to get SensorShells for users and also sets the Hackystat host for the SensorShells.
SensorShellMap(java.lang.String tool, java.io.File userMapFile)
          A package private constructor meant to be used only by Junit test cases.
 
Method Summary
 java.util.Set<java.lang.String> getToolAccounts(java.lang.String tool)
          Returns the set of tool account names associated with this tool in the usermaps file.
 java.lang.String getUserMapFile()
          Returns the UserMap file name associated with this SensorShellMap.
 SensorShell getUserShell(java.lang.String toolAccount)
          Gets the SensorShell instance for a Hackystat user with an account for the given tool.
 SensorShell getUserShell(java.lang.String toolAccount, java.util.Properties properties)
          Gets the SensorShell instance for a Hackystat user with an account for the given tool.
 boolean hasUserShell(java.lang.String toolAccount)
          Returns true if toolAccount is known so that a corresponding SensorShell can be retrieved.
 void validateHackystatInfo(java.lang.String tool)
          Validates the hackystat user, password, and sensorbase associated with tool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SensorShellMap

public SensorShellMap(java.lang.String tool)
               throws SensorShellMapException
Instantiate this class which initializes the UserMap used to get SensorShells for users and also sets the Hackystat host for the SensorShells.

Parameters:
tool - The specific tool that this SensorShellMap will provide SensorShells for.
Throws:
SensorShellMapException - Indicates that the usermaps.xml file is not found.

SensorShellMap

public SensorShellMap(java.lang.String tool,
                      java.io.File userMapFile)
               throws SensorShellMapException
A package private constructor meant to be used only by Junit test cases.

Parameters:
tool - The specific tool that this SensorShellMap will provide SensorShells for.
userMapFile - The UserMap.xml file.
Throws:
SensorShellMapException - Indicates that the UserMap.xml file is not found.
Method Detail

hasUserShell

public boolean hasUserShell(java.lang.String toolAccount)
Returns true if toolAccount is known so that a corresponding SensorShell can be retrieved.

Parameters:
toolAccount - The toolAccount for the tool in this instance, such as "johnson".
Returns:
True if toolAccount is known, otherwise false.

getToolAccounts

public java.util.Set<java.lang.String> getToolAccounts(java.lang.String tool)
Returns the set of tool account names associated with this tool in the usermaps file.

Parameters:
tool - The tool of interest.
Returns:
The known tool account names for this tool.

getUserMapFile

public java.lang.String getUserMapFile()
Returns the UserMap file name associated with this SensorShellMap. This file may or may not exist.

Returns:
The usermap file name associated with this SensorShellMap.

validateHackystatInfo

public void validateHackystatInfo(java.lang.String tool)
                           throws SensorShellMapException
Validates the hackystat user, password, and sensorbase associated with tool. Throws an exception if the sensorbase cannot be contacted and/or if the user/password combination is not valid for the associated sensorbase.

Parameters:
tool - The tool of interest.
Throws:
SensorShellMapException - Thrown if user map info cannot be validated.

getUserShell

public SensorShell getUserShell(java.lang.String toolAccount)
                         throws SensorShellMapException
Gets the SensorShell instance for a Hackystat user with an account for the given tool. Assumes that toolAccount is known and will map to a userKey; use hasUserShell() to check whether this is true before calling this method. Instantiates the SensorShell instance if it is not yet available.

Parameters:
toolAccount - The name of the account for the given tool. This is not the same as the Hackystat account name although it may be the same.
Returns:
The SensorShell instance for the specific Hackystat user.
Throws:
SensorShellMapException - When the user account and/or tool is undefined.

getUserShell

public SensorShell getUserShell(java.lang.String toolAccount,
                                java.util.Properties properties)
                         throws SensorShellMapException
Gets the SensorShell instance for a Hackystat user with an account for the given tool. Assumes that toolAccount is known and will map to a userKey; use hasUserShell() to check whether this is true before calling this method. Instantiates the SensorShell instance if it is not yet available.

Parameters:
toolAccount - The name of the account for the given tool. This is not the same as the Hackystat account name although it may be the same.
properties - A properties instance holding SensorShell properties to be used to initialize the underlying SensorShell if it requires instantiation. If null, then no additional properties are required.
Returns:
The SensorShell instance for the specific Hackystat user.
Throws:
SensorShellMapException - When the user account and/or tool is undefined.