org.safs.staf.service
Class SAFSInputService

java.lang.Object
  extended by org.safs.staf.service.SAFSInputService
All Implemented Interfaces:
com.ibm.staf.service.STAFServiceInterfaceLevel3

public class SAFSInputService
extends java.lang.Object
implements com.ibm.staf.service.STAFServiceInterfaceLevel3

Copyright 2003 SAS Institute GNU General Public License (GPL) http://www.opensource.org/licenses/gpl-license.php

This SAFSInputService class is an external STAF service run by the JSTAF Service Proxy.
The intention is to provide global services for reading the content of text files in a manner suitable for a SAFS Drivers(like SAFSDRIVER) and Engines. For example, two different processes (or machines?) can share the file read operations as necessary. However, there will certainly be an array of other uses.

It is important to note that in a normal SAFS environment, Input services may make use of SAFS Variable services (SAFSVARS). This is because some commands may need to evaluate variable values or resolve expressions.

The SAFSInputService service provides the following commands:

OPEN Open a file for use
NEXT Get the next line from the file
GOTO Goto a defined position in the file
BEGIN Reset a file reader back to the first line
CLOSE Close and release resources on a file
QUERY Get information on a file
LIST List information for all open files
RESET Close and release all files and resources
HELP Display this help information

1.0 Service Registration

Each instance of the service must be registered via the STAF Service service.

Example showing comandline registration:

 STAF LOCAL SERVICE ADD SERVICE SAFSINPUT LIBRARY JSTAF /
            EXECUTE c:/safs/lib/SAFSINPUT.JAR [PARMS <Parameters>]
 
 STAF LOCAL SERVICE ADD SERVICE SAFSINPUT LIBRARY JSTAF /
            EXECUTE c:/safs/lib/SAFSINPUT.JAR 
 
 STAF LOCAL SERVICE ADD SERVICE SAFSINPUT LIBRARY JSTAF /
            EXECUTE c:/safs/lib/SAFSINPUT.JAR PARMS DIR "c:/repo/Datapool" 

 

By default, the service expects a "SAFSVARS" SAFSVariableService to handle Variable calls. A future release may add a parameter allowing a different variable service handler.

1.1 Valid Parameters when registering the service:

1.1.1 DIR <default directory>
If provided, the DIR parameter specifies a default directory to use if the OPEN request provides relative path information or no path information at all. File searches do not use system PATH information. The OPEN request expects a full filename path, or a path relative to this DIR option.

EX: <PARMS> DIR "c:/testproject/Datapool"

2.0 Commands

2.1 OPEN

The OPEN command attempts to open a file for read operations.

Syntax:

OPEN <FileID> FILE <Filename>

2.1.1 FileID is a unique ID for this file reader instance.

2.1.2 FILE is the filename of the file to load.
If a default Directory was specified when the service was launched, then the filename can be relative to that directory.

Example: staf local safsinput open myfile file TIDTest.CDD
Example: staf local safsinput open myfile file c:/testproject/datapool/Bench/TIDTest.txt

2.2 NEXT

The NEXT command reads the next line from the file matching FileID.

Syntax:

NEXT <FileID>

2.2.1 FileID is the unique ID for the file reader instance.

Example: staf local safsinput next myfile

2.3 GOTO

The GOTO command moves the file reader pointer to a defined place in the file.
Currently, the "defined place" must take the form of a SAFS BlockID record. Future releases may allow you to specify specific line numbers.

A SAFS BlockID record is a line with two fields separated by a delimiter as shown below:

    B, MyBlockID
 

The first field contains "B" which specifies a BlockID record. The second field specifies the name or label of the BlockID record. This label is the value identifying this "defined place" in the file.

This command will use the variables service to evaluate SAFS variables and process SAFS expressions in field #1 and/or field #2 in order to accurately locate the target BlockID.

The command will return STAFResult.OK and a (linenum:record) result string if successful; or an error code and error description upon failure.

Syntax:

GOTO <FileID> LOCATE <BlockID> SEPARATOR <SepChar>

2.3.1 FileID is the unique ID for the file reader instance.

2.3.2 BlockID is the target block ID label to locate.

2.3.3 SepChar is the character that delimits the two fields.

Example: staf local safsinput goto myfile locate MyBlockID separator ","

2.4 BEGIN

The BEGIN command resets the file reader matching the FileID back to the beginning of the file.

Syntax:

BEGIN <FileID>

2.4.1 FileID is the unique ID for the file reader instance.

Example: staf local safsinput begin myfile

2.5 CLOSE

The CLOSE command closes the file matching FileID and releases its resources.

Syntax:

CLOSE <FileID>

2.5.1 FileID is the unique ID for the file reader instance.

Example: staf local safsinput close myfile

2.6 QUERY

The QUERY command returns information about the file matching FileID.

Syntax:

QUERY <FileID> [ STATUS | FILENAME | FULLPATH ]

2.6.1 FileID is the unique ID for the file reader instance.

2.6.2 STATUS request status info on this file.

2.6.3 FILENAME request the simple filename of this file.

2.6.4 FULLPATH request the full path and filename of this file.

Example: staf local safsinput query myfile STATUS FULLPATH

2.7 LIST

The LIST command returns information on ALL files.

Syntax:

LIST

Example: staf local safsinput list

2.8 RESET

The RESET command closes all files and resets all resources.

Syntax:

RESET

Example: staf local safsinput reset

2.9 HELP

The HELP command returns a quick reference of supported commands and syntax.

Syntax:

HELP

Example: staf local safsinput list

Software Automation Framework Support (SAFS) http://safsdev.sourceforge.net
Software Testing Automation Framework (STAF) http://staf.sourceforge.net


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.ibm.staf.service.STAFServiceInterfaceLevel3
com.ibm.staf.service.STAFServiceInterfaceLevel3.InitInfo, com.ibm.staf.service.STAFServiceInterfaceLevel3.RequestInfo
 
Field Summary
protected  com.ibm.staf.service.STAFCommandParser beginParser
           
protected static java.lang.String c
          a single colon
protected  com.ibm.staf.service.STAFCommandParser closeParser
           
protected  java.lang.String dir
           
protected  java.lang.String ext
           
protected  boolean file_extension_available
           
protected  com.ibm.staf.service.STAFCommandParser gotoParser
           
protected  com.ibm.staf.service.STAFCommandParser nextParser
           
protected  com.ibm.staf.service.STAFCommandParser openParser
           
protected  com.ibm.staf.service.STAFCommandParser parser
           
protected static java.lang.String r
          a single newline
protected  boolean relative_path_allowed
           
protected  com.ibm.staf.service.STAFCommandParser resetParser
           
protected  com.ibm.staf.service.STAFCommandParser routeParser
           
protected static java.lang.String s
          a single space
protected static java.util.ResourceBundle safsfilereader_resources
           
protected  java.lang.String servicename
           
protected  java.lang.String serviceparams
           
protected  java.lang.String servicevars
          Stores the name of the actual service used to resolve variable expressions.
 java.lang.String SI_DEFAULT_RESOLVE_SERVICE
          "SAFSVARS" -- default service used to resolve variable expressions for GOTO
static java.lang.String SI_RBKEY_ERROR_NOT_INTEGER
           
static java.lang.String SI_RBKEY_NOT_IMPLEMENTED
           
static java.lang.String SI_RBKEY_OPEN_FILES
           
static java.lang.String SI_RBKEY_REQUIRED
           
static java.lang.String SI_RBKEY_SYNC_ERROR
           
static java.lang.String SI_RBKEY_UCPATH
           
static java.lang.String SI_SERVICE_FILE_STATE_CLOSED
           
static java.lang.String SI_SERVICE_FILE_STATE_EOF
           
static java.lang.String SI_SERVICE_FILE_STATE_ERROR
           
static java.lang.String SI_SERVICE_FILE_STATE_OPEN
           
protected  int SI_SERVICE_INIT_PARMS_MAX
          The maximum number of options/parameters we expect a service initialization request to receive.
static java.lang.String SI_SERVICE_OPTION_DIR
           
static java.lang.String SI_SERVICE_OPTION_EXT
           
static java.lang.String SI_SERVICE_PARM_FILE
           
static java.lang.String SI_SERVICE_PARM_FILENAME
           
static java.lang.String SI_SERVICE_PARM_FULLPATH
           
static java.lang.String SI_SERVICE_PARM_LASTERROR
           
static java.lang.String SI_SERVICE_PARM_LOCATE
           
static java.lang.String SI_SERVICE_PARM_SEPARATOR
           
static java.lang.String SI_SERVICE_PARM_STATUS
           
protected  int SI_SERVICE_REQUEST_ARGS_MAX
          The maximum number of options/parameters we expect a running service to receive in a request.
static java.lang.String SI_SERVICE_REQUEST_BEGIN
           
static java.lang.String SI_SERVICE_REQUEST_CLOSE
           
static java.lang.String SI_SERVICE_REQUEST_GOTO
           
static java.lang.String SI_SERVICE_REQUEST_HELP
           
static java.lang.String SI_SERVICE_REQUEST_LIST
           
static java.lang.String SI_SERVICE_REQUEST_NEXTLINE
           
static java.lang.String SI_SERVICE_REQUEST_OPEN
           
static java.lang.String SI_SERVICE_REQUEST_QUERY
           
static java.lang.String SI_SERVICE_REQUEST_RESET
           
static java.lang.String SI_SERVICE_SAFSFILE_BUNDLE_NAME
          The fully qualified name of the localizable ResourceBundle for this class.
protected  java.lang.String SI_SERVICE_SAFSFILE_LISTINFO
          The text substring identifying the file type in each file LIST response.
 
Constructor Summary
SAFSInputService()
           
 
Method Summary
 com.ibm.staf.STAFResult acceptRequest(com.ibm.staf.service.STAFServiceInterfaceLevel3.RequestInfo info)
           
protected  java.lang.String buildHELPInfo()
           
protected  java.lang.String getHELPInfo(java.lang.String info)
          Add your HELP text response here.
protected  java.lang.String getOPENInfo(com.ibm.staf.service.STAFCommandParseResult parsedData, java.lang.String info)
          Handle any added OPEN options here.
protected  SAFSTextFile getParsedDataTextFile(com.ibm.staf.STAFResult result, java.lang.String fileid)
           
 int init(com.ibm.staf.service.STAFServiceInterfaceLevel3.InitInfo info)
           
protected  boolean isTargetBlock(java.lang.String inputBlockID, java.lang.String inputRecord, java.lang.String fieldsep)
           
protected  void locateBlockID(com.ibm.staf.STAFResult result, SAFSTextFile file, java.lang.String inputBlockID, java.lang.String fieldsep)
           
protected  SAFSTextFile openFile(java.lang.String machine, java.lang.String process, int handle, java.lang.String fileid, java.io.File file, com.ibm.staf.service.STAFCommandParseResult parsedData)
          A subclass must override this function to instantiate its own file type.
protected  java.lang.String processExpression(java.lang.String expression)
           
protected  com.ibm.staf.STAFResult processRequest(com.ibm.staf.STAFResult result, java.lang.String machine, java.lang.String process, int handle, com.ibm.staf.service.STAFCommandParseResult parseData)
          A subclass must override this function to handle requests not handled by the superclass.
protected  int shutdown()
          perform final termination cleanup operations for your service.
 int term()
           
 java.lang.String text(java.lang.String resourcekey)
          Retrieves potentially localized text from the resource bundle Localized subclasses should provide a similar function or override this function.
protected  int validateBaseServiceParseResult(com.ibm.staf.service.STAFCommandParseResult parsedData)
           
protected  int validateServiceParseResult(com.ibm.staf.service.STAFCommandParseResult parsedData)
          Use to validate the Service initialization string after a request for initialization has been received.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SI_SERVICE_SAFSFILE_LISTINFO

protected java.lang.String SI_SERVICE_SAFSFILE_LISTINFO
The text substring identifying the file type in each file LIST response. Subclasses are expected to override this value for differing file types.


SI_DEFAULT_RESOLVE_SERVICE

public java.lang.String SI_DEFAULT_RESOLVE_SERVICE
"SAFSVARS" -- default service used to resolve variable expressions for GOTO


servicevars

protected java.lang.String servicevars
Stores the name of the actual service used to resolve variable expressions. This is normally "SAFSVARS".


SI_SERVICE_SAFSFILE_BUNDLE_NAME

public static final java.lang.String SI_SERVICE_SAFSFILE_BUNDLE_NAME
The fully qualified name of the localizable ResourceBundle for this class. Subclasses are expected to provide their own additional ResourceBundle handling file and subroutine when appropriate.

See Also:
Constant Field Values

SI_SERVICE_INIT_PARMS_MAX

protected int SI_SERVICE_INIT_PARMS_MAX
The maximum number of options/parameters we expect a service initialization request to receive. Subclasses are expected to override this value when appropriate.


SI_SERVICE_REQUEST_ARGS_MAX

protected int SI_SERVICE_REQUEST_ARGS_MAX
The maximum number of options/parameters we expect a running service to receive in a request. Subclasses are expected to override this value when appropriate.


safsfilereader_resources

protected static java.util.ResourceBundle safsfilereader_resources

SI_RBKEY_NOT_IMPLEMENTED

public static final java.lang.String SI_RBKEY_NOT_IMPLEMENTED
See Also:
Constant Field Values

SI_RBKEY_OPEN_FILES

public static final java.lang.String SI_RBKEY_OPEN_FILES
See Also:
Constant Field Values

SI_RBKEY_UCPATH

public static final java.lang.String SI_RBKEY_UCPATH
See Also:
Constant Field Values

SI_RBKEY_SYNC_ERROR

public static final java.lang.String SI_RBKEY_SYNC_ERROR
See Also:
Constant Field Values

SI_RBKEY_REQUIRED

public static final java.lang.String SI_RBKEY_REQUIRED
See Also:
Constant Field Values

SI_RBKEY_ERROR_NOT_INTEGER

public static final java.lang.String SI_RBKEY_ERROR_NOT_INTEGER
See Also:
Constant Field Values

SI_SERVICE_OPTION_DIR

public static final java.lang.String SI_SERVICE_OPTION_DIR
See Also:
Constant Field Values

SI_SERVICE_OPTION_EXT

public static final java.lang.String SI_SERVICE_OPTION_EXT
See Also:
Constant Field Values

SI_SERVICE_REQUEST_OPEN

public static final java.lang.String SI_SERVICE_REQUEST_OPEN
See Also:
Constant Field Values

SI_SERVICE_REQUEST_NEXTLINE

public static final java.lang.String SI_SERVICE_REQUEST_NEXTLINE
See Also:
Constant Field Values

SI_SERVICE_REQUEST_GOTO

public static final java.lang.String SI_SERVICE_REQUEST_GOTO
See Also:
Constant Field Values

SI_SERVICE_REQUEST_CLOSE

public static final java.lang.String SI_SERVICE_REQUEST_CLOSE
See Also:
Constant Field Values

SI_SERVICE_REQUEST_HELP

public static final java.lang.String SI_SERVICE_REQUEST_HELP
See Also:
Constant Field Values

SI_SERVICE_REQUEST_QUERY

public static final java.lang.String SI_SERVICE_REQUEST_QUERY
See Also:
Constant Field Values

SI_SERVICE_REQUEST_BEGIN

public static final java.lang.String SI_SERVICE_REQUEST_BEGIN
See Also:
Constant Field Values

SI_SERVICE_REQUEST_RESET

public static final java.lang.String SI_SERVICE_REQUEST_RESET
See Also:
Constant Field Values

SI_SERVICE_REQUEST_LIST

public static final java.lang.String SI_SERVICE_REQUEST_LIST
See Also:
Constant Field Values

SI_SERVICE_PARM_FILE

public static final java.lang.String SI_SERVICE_PARM_FILE
See Also:
Constant Field Values

SI_SERVICE_PARM_STATUS

public static final java.lang.String SI_SERVICE_PARM_STATUS
See Also:
Constant Field Values

SI_SERVICE_PARM_FILENAME

public static final java.lang.String SI_SERVICE_PARM_FILENAME
See Also:
Constant Field Values

SI_SERVICE_PARM_FULLPATH

public static final java.lang.String SI_SERVICE_PARM_FULLPATH
See Also:
Constant Field Values

SI_SERVICE_PARM_LASTERROR

public static final java.lang.String SI_SERVICE_PARM_LASTERROR
See Also:
Constant Field Values

SI_SERVICE_PARM_LOCATE

public static final java.lang.String SI_SERVICE_PARM_LOCATE
See Also:
Constant Field Values

SI_SERVICE_PARM_SEPARATOR

public static final java.lang.String SI_SERVICE_PARM_SEPARATOR
See Also:
Constant Field Values

SI_SERVICE_FILE_STATE_OPEN

public static final java.lang.String SI_SERVICE_FILE_STATE_OPEN
See Also:
Constant Field Values

SI_SERVICE_FILE_STATE_CLOSED

public static final java.lang.String SI_SERVICE_FILE_STATE_CLOSED
See Also:
Constant Field Values

SI_SERVICE_FILE_STATE_EOF

public static final java.lang.String SI_SERVICE_FILE_STATE_EOF
See Also:
Constant Field Values

SI_SERVICE_FILE_STATE_ERROR

public static final java.lang.String SI_SERVICE_FILE_STATE_ERROR
See Also:
Constant Field Values

parser

protected com.ibm.staf.service.STAFCommandParser parser

routeParser

protected com.ibm.staf.service.STAFCommandParser routeParser

openParser

protected com.ibm.staf.service.STAFCommandParser openParser

closeParser

protected com.ibm.staf.service.STAFCommandParser closeParser

beginParser

protected com.ibm.staf.service.STAFCommandParser beginParser

nextParser

protected com.ibm.staf.service.STAFCommandParser nextParser

resetParser

protected com.ibm.staf.service.STAFCommandParser resetParser

gotoParser

protected com.ibm.staf.service.STAFCommandParser gotoParser

servicename

protected java.lang.String servicename

serviceparams

protected java.lang.String serviceparams

relative_path_allowed

protected boolean relative_path_allowed

file_extension_available

protected boolean file_extension_available

dir

protected java.lang.String dir

ext

protected java.lang.String ext

c

protected static java.lang.String c
a single colon


s

protected static java.lang.String s
a single space


r

protected static java.lang.String r
a single newline

Constructor Detail

SAFSInputService

public SAFSInputService()
Method Detail

text

public java.lang.String text(java.lang.String resourcekey)
Retrieves potentially localized text from the resource bundle Localized subclasses should provide a similar function or override this function. If the subclass function fails to locate the message in the subclass's ResourceBundle, then the subclass should call the superclass function to look there.

    text = super.text(resourceKey);

Parameters:
resourceKey - the key name of the message to retrieve.

Returns:
the localized text or a localization error string

getOPENInfo

protected java.lang.String getOPENInfo(com.ibm.staf.service.STAFCommandParseResult parsedData,
                                       java.lang.String info)
Handle any added OPEN options here. This root class has already added info to the string prior to the call into the subclass. You may still forward the request to any superclass "just in case".

    return super.getOPENInfo( parsedData, info );

Parameters:
parsedData - the parsed request to interrogate for OPEN option parameter values.

info - the status string that will be displayed for the OPEN command.

Returns:
any text to be added to the OPEN response.

validateServiceParseResult

protected int validateServiceParseResult(com.ibm.staf.service.STAFCommandParseResult parsedData)
Use to validate the Service initialization string after a request for initialization has been received.

This is where you check to see which options exist in the request, and act upon them. Make sure you also forward the validation request up the food chain so the superclasses can validate their service init options, too.

    return super.validateServiceParseResult( parsedData );

Parameters:
parsedData - the result object after parsing was performed

getHELPInfo

protected java.lang.String getHELPInfo(java.lang.String info)
Add your HELP text response here. The root class will handle its own HELP substring. You will still forward the request to any superclass to have their HELP options displayed, too.

    info += MY_LONG_INVOLVED_FORMATTED_HELP_TEXT;
    return super.getHELPInfo( info );

Parameters:
info - the response string that will be displayed for the HELP command.

Returns:
any text to be prepend the superclass response.

openFile

protected SAFSTextFile openFile(java.lang.String machine,
                                java.lang.String process,
                                int handle,
                                java.lang.String fileid,
                                java.io.File file,
                                com.ibm.staf.service.STAFCommandParseResult parsedData)
A subclass must override this function to instantiate its own file type. The file type, obviously, must be a extension of SAFSFile.

Parameters:
machine - the machine initiating the request to open the file.

process - the name of the Process initiating the request to open the file.

handle - the Handle of the Process initiating the request to open the file.

fileid - the unique fileid to be assigned the file. fileids should be uniquely identifiable among all Handles for a given Process.

file - the File object used to open the file.

parsedData - the parsed result containing the OPEN command and any of the user-supplied options that may be needed when opening the file or setting options in the file handler.

Returns:
the instance of the SAFSFile object that has been created.

buildHELPInfo

protected final java.lang.String buildHELPInfo()

processRequest

protected com.ibm.staf.STAFResult processRequest(com.ibm.staf.STAFResult result,
                                                 java.lang.String machine,
                                                 java.lang.String process,
                                                 int handle,
                                                 com.ibm.staf.service.STAFCommandParseResult parseData)
A subclass must override this function to handle requests not handled by the superclass. The subclass must also forward any unhandled requests to the superclass function.

    return super.processRequest(result, machine, process, handle, parsedData);

Parameters:
result - the object containing the return code and response string for the request.

machine - the machine initiating the request.

process - the name of the Process initiating the request.

handle - the Handle of the Process initiating the request.

parsedData - the parsed result containing the command and the user-supplied options provided.

Returns:
the result object after processing the request.

shutdown

protected int shutdown()
perform final termination cleanup operations for your service. The service is being shutdown by STAF. You must also forward this shutdown request to your superclass.

    return super.shutdown();


validateBaseServiceParseResult

protected final int validateBaseServiceParseResult(com.ibm.staf.service.STAFCommandParseResult parsedData)

init

public int init(com.ibm.staf.service.STAFServiceInterfaceLevel3.InitInfo info)
Specified by:
init in interface com.ibm.staf.service.STAFServiceInterfaceLevel3

acceptRequest

public com.ibm.staf.STAFResult acceptRequest(com.ibm.staf.service.STAFServiceInterfaceLevel3.RequestInfo info)
Specified by:
acceptRequest in interface com.ibm.staf.service.STAFServiceInterfaceLevel3

processExpression

protected java.lang.String processExpression(java.lang.String expression)

isTargetBlock

protected boolean isTargetBlock(java.lang.String inputBlockID,
                                java.lang.String inputRecord,
                                java.lang.String fieldsep)

locateBlockID

protected void locateBlockID(com.ibm.staf.STAFResult result,
                             SAFSTextFile file,
                             java.lang.String inputBlockID,
                             java.lang.String fieldsep)

getParsedDataTextFile

protected final SAFSTextFile getParsedDataTextFile(com.ibm.staf.STAFResult result,
                                                   java.lang.String fileid)

term

public final int term()
Specified by:
term in interface com.ibm.staf.service.STAFServiceInterfaceLevel3