|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.peace_tools.core.session.ServerSession
org.peace_tools.core.session.LocalServerSession
public class LocalServerSession
A local server session to run jobs on the local host.
This class provides an implementation of the ServerSession API. Specifically, this class provides a session that can be used to interact with the local PC using the same API as that used for remote hosts. The consistent API eases development of the core GUI modules.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class org.peace_tools.core.session.ServerSession |
---|
ServerSession.OSType |
Field Summary | |
---|---|
private java.lang.String |
purpose
A simple textual information indicating the purpose for this session. |
Fields inherited from class org.peace_tools.core.session.ServerSession |
---|
parent, server |
Constructor Summary | |
---|---|
protected |
LocalServerSession(java.awt.Component parent,
Server server)
The constructor merely passes parameters to the base class that initializes the instance variables. |
Method Summary | |
---|---|
void |
connect()
Connect to the server in order to perform various operations. |
void |
copy(java.io.InputStream srcData,
java.lang.String destDirectory,
java.lang.String destFileName,
java.lang.String mode)
Copy given data from an input stream to a given file on the local machine. |
void |
copy(java.io.OutputStream destData,
java.lang.String srcDirectory,
java.lang.String srcFileName,
javax.swing.JProgressBar progBar)
Copy file from one directory to a given output stream. |
void |
disconnect()
Method to disconnect from a remote server. |
int |
exec(java.lang.String command,
javax.swing.text.DefaultStyledDocument output)
This method can be used to run a long running command that may produce verbose output. |
int |
exec(java.lang.String command,
java.lang.String[] outputs)
This method can be used to run a brief command that produces succinct output. |
FileInfo |
fstat(java.lang.String path)
Obtain information about a given path on the server. |
ServerSession.OSType |
getOSType()
Determine the type of OS that this session is connected to. |
java.lang.String |
getPurpose()
Obtain the purpose set for this session. |
void |
mkdir(java.lang.String directory)
Creates a directory on the server. |
void |
rmdir(java.lang.String directory)
Deletes an empty directory on the server. |
private void |
setPerms(java.io.File file,
char permDigit,
boolean owner)
Set up the permissions for a given file. |
void |
setPurpose(java.lang.String text)
A simple method to set a purpose message for this session. |
private java.lang.Process |
startProcess(java.lang.String command)
Helper method to start process to execute command via OS-specific command processor. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private java.lang.String purpose
Constructor Detail |
---|
protected LocalServerSession(java.awt.Component parent, Server server)
server
- The server data entry that provides the necessary
information to connect to the server.parent
- The parent component that should be used to
create GUI elements that may be needed for any interactive
operations.Method Detail |
---|
public void connect() throws java.io.IOException
connect
in class ServerSession
java.io.IOException
- The exception signature is only for API
compliance. This method does not really throw any exceptionspublic void disconnect()
disconnect
in class ServerSession
public int exec(java.lang.String command, java.lang.String[] outputs) throws java.lang.Exception
Note: The connection to the remote server must have been established successfully via a call to connect method.
exec
in class ServerSession
command
- The command line to be executed. This
command must be compatible with the target machine's
OS. Otherwise this method will generate an exception.outputs
- The buffered results from the standard
output and standard error streams of the remote process.
java.lang.Exception
- If the execution produces an error then
this method throws an exception.private java.lang.Process startProcess(java.lang.String command) throws java.lang.Exception
command
- The command to be run.
java.lang.Exception
public int exec(java.lang.String command, javax.swing.text.DefaultStyledDocument output) throws java.lang.Exception
Note: This method waits for the process to complete before returning control. Consequently, this method must be called from a separate thread if the GUI should not block.
exec
in class ServerSession
command
- The command line to be executed. This
command must be compatible with the target machine's
OS. Otherwise this method will generate an exception.output
- The styled document to which the standard
output and standard error streams are to be written.
java.lang.Exception
- If the execution produces an error then
this method throws an exception.public ServerSession.OSType getOSType() throws java.lang.Exception
getOSType
in class ServerSession
java.lang.Exception
- If the detection of OS fails or a connection
does not exist then this method throws an exception.public void copy(java.io.InputStream srcData, java.lang.String destDirectory, java.lang.String destFileName, java.lang.String mode) throws java.io.IOException
copy
in class ServerSession
srcData
- The source stream that provides the data to
be copied.destDirectory
- The destination directory to which the
data is to be copied. This method assumes that the remote
directory has already been created.destFileName
- The name of the destination file to which
the data is to be copied.mode
- The POSIX compliant mode string (such as: "0600"
or "0777" to be used as the mode for the target file.
java.io.IOException
- This method throws exceptions on errors.public void copy(java.io.OutputStream destData, java.lang.String srcDirectory, java.lang.String srcFileName, javax.swing.JProgressBar progBar) throws java.io.IOException
copy
in class ServerSession
destData
- The destination stream to which the data is
to be written.srcDirectory
- The source directory from where the
file is to be copied.srcFileName
- The name of the source file from where
the data is to be copied.progBar
- The progress bar to be used indicate the
file copy progress.
java.io.IOException
- This method throws exceptions on errors.public void mkdir(java.lang.String directory) throws java.lang.Exception
mkdir
in class ServerSession
directory
- The fully path to the directory to be created.
java.io.IOException
- This method throws an exception if the
directory could not be created.
java.lang.Exception
public void rmdir(java.lang.String directory) throws java.lang.Exception
Note:The connection to the server must have already been successfully established via a call to the connect method before invoking this method.
rmdir
in class ServerSession
directory
- The fully path to the directory to be deleted.
java.io.IOException
- This method throws an exception if the
directory could not be deleted.
java.lang.Exception
public FileInfo fstat(java.lang.String path) throws java.io.IOException
fstat
in class ServerSession
path
- The path (absolute or relative to home directory)
of the file whose meta data is to be retrieved.
java.io.IOException
- This method throws exceptions on errors.private void setPerms(java.io.File file, char permDigit, boolean owner)
file
- The file whose permissions are to be set.permDigit
- A POSIX compliant digit (0-7) that indicates the flags
for read (4), write (2), and execute (1) values.owner
- Flag to indicate if the status is for the owner (true) or
others (false).public void setPurpose(java.lang.String text)
setPurpose
in class ServerSession
text
- This string is used to create a label (possibly
with an icon on it). So it can be plain text or HTML. If the
message is long, then ensure it is properly broken into
multiple lines so that dialog boxes don't get too large.public java.lang.String getPurpose()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |