org.netbeans.lib.cvsclient
Class Client

java.lang.Object
  extended by org.netbeans.lib.cvsclient.Client
All Implemented Interfaces:
ClientServices, ResponseServices

public class Client
extends java.lang.Object
implements ClientServices, ResponseServices

The main way of communication with a server using the CVS Protocol. The client is not responsible for setting up the connection with the server, only interacting with it.

See Also:
Connection

Nested Class Summary
static interface Client.Factory
          Factory for creating clients.
 
Constructor Summary
Client(Connection connection, AdminHandler adminHandler)
          Construct a Client using a given connection and file handler.
 
Method Summary
 void abort()
          Call this method to abort the current command.
 void addWrapper(StringPattern pattern, KeywordSubstitutionOptions option)
          This method is called by WrapperSendResponse for each wrapper setting sent back by the CVS server
 java.lang.String convertPathname(java.lang.String localDirectory, java.lang.String repository)
          Convert a pathname in the CVS sense (see 5.10 in the protocol document) into a local absolute pathname for the file.
 void dontUseGzipFileHandler()
          ReSet the filehandler for Gzip compressed data.
 void ensureConnection()
          Ensures, that the connection is open.
 boolean executeCommand(Command command, GlobalOptions globalOptions)
          Execute a command.
 boolean exists(java.io.File file)
          Tests for existence of the given file.
 AdminHandler getAdminHandler()
          Get the admin handler uesd to read and write administrative information about files on the local machine.
 java.util.Set getAllFiles(java.io.File directory)
          Get all the files contained within a given directory that are known to CVS.
 Connection getConnection()
          Get the connection used for communicating with the server.
 long getCounter()
          Counts processRequests(java.util.List).
 java.util.Iterator getEntries(java.io.File directory)
          Get the entries for a specified directory.
 Entry getEntry(java.io.File f)
          Get the Entry for the specified file, if one exists.
 EventManager getEventManager()
          Get the CVS event manager.
 GlobalOptions getGlobalOptions()
          Get the global options that are set to this client.
 FileHandler getGzipFileHandler()
          Return the Gzip stream handler.
 IgnoreFileFilter getIgnoreFileFilter()
          Returns the IgnoreFileFilter used to ignore non-cvs files.
 java.lang.String getLocalPath()
          Get the local path; that is, the path to the directory in which the currently executing command is referring.
 java.util.Date getNextFileDate()
          Get the modified date for the next file.
 java.lang.String getRepository()
          Get the repository path from the connection.
 java.lang.String getRepositoryForDirectory(java.io.File directory)
          Semantically equivalent to ClientServices.getRepositoryForDirectory(String) but does not try to recover from missing CVS/Repository file.
 java.lang.String getRepositoryForDirectory(java.lang.String directory)
          Get the repository path for a given directory, for example in the directory /home/project/foo/bar, the repository directory might be /usr/cvs/foo/bar.
 java.lang.String getStickyTagForDirectory(java.io.File directory)
          Checks for presence of CVS/Tag file and returns it's value.
 FileHandler getUncompressedFileHandler()
          Return the uncompressed file handler.
 java.util.Map getWrappersMap()
          Returns the wrappers map associated with the CVS server The map is valid only after the connection is established
 boolean isAborted()
          Tests whether command execution should be aborted.
 boolean isFirstCommand()
          Returns true if no previous command was executed using thiz.
 void processRequests(java.util.List requests)
          Process all the requests.
 void removeEntry(java.io.File file)
          Remove the Entry for the specified file.
 void removeLocalFile(java.lang.String pathname)
          Remove the specified file from the local disk.
 void removeLocalFile(java.lang.String pathName, java.lang.String repositoryName)
          Removes the specified file determined by pathName and repositoryName.
 void renameLocalFile(java.lang.String pathname, java.lang.String newName)
          Rename the local file.
 void setAdminHandler(AdminHandler adminHandler)
          Set the admin handler used to read and write administrative information about files on the local machine.
 void setConnection(Connection connection)
          Set the connection used for communicating with the server.
 void setEntry(java.io.File file, Entry entry)
          Set the Entry for the specified file.
 void setErrorStream(java.io.PrintStream stderr)
           
 void setGzipFileHandler(FileHandler gzipFileHandler)
          Set the handler for Gzip data.
 void setIgnoreFileFilter(IgnoreFileFilter ignoreFileFilter)
          Sets the specified IgnoreFileFilter to use to ignore non-cvs files.
 void setIsFirstCommand(boolean isFirstCommand)
          Set whether this is the first command.
 void setLocalPath(java.lang.String localPath)
          Set the local path, i.e.
 void setNextFileDate(java.util.Date modifiedDate)
          Set the modified date of the next file to be written.
 void setUncompressedFileHandler(FileHandler uncompFileHandler)
          Set the uncompressed file handler.
 void setValidRequests(java.lang.String requests)
          This method is called when a response for the ValidRequests request is received.
 boolean shouldBeIgnored(java.io.File directory, java.lang.String noneCvsFile)
          Returnes true to indicate, that the file specified by directory and nonCvsFile should be ignored.
 void updateAdminData(java.lang.String localDirectory, java.lang.String repositoryPath, Entry entry)
          Create or update the administration files for a particular file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Client

public Client(Connection connection,
              AdminHandler adminHandler)
Construct a Client using a given connection and file handler. You must initialize the connection and adminHandler first. // establish connection to the given CVS pserver PServerConnection connection = new PServerConnection(); connection.setUserName(userName); connection.setHostName(hostName); connection.setEncodedPassword(StandardScrambler.getInstance().scramble(password)); connection.setRepository(repository); // test the connection try { connection.open(); } catch (AuthenticationException e) { // do something } // create a CVS client Client cvsClient = new Client(connection,new StandardAdminHandler()); // set the directory in which we work cvsClient.setLocalPath(localPath);

Parameters:
connection - the connection to the cvs server
adminHandler - the admin handler to use
Method Detail

setErrorStream

public void setErrorStream(java.io.PrintStream stderr)

getConnection

public Connection getConnection()
Get the connection used for communicating with the server. Connection.

Returns:
the connection

setConnection

public void setConnection(Connection connection)
Set the connection used for communicating with the server.

Parameters:
c - the connection to use for all communication with the server

getAdminHandler

public AdminHandler getAdminHandler()
Get the admin handler uesd to read and write administrative information about files on the local machine.

Returns:
the admin handler

setAdminHandler

public void setAdminHandler(AdminHandler adminHandler)
Set the admin handler used to read and write administrative information about files on the local machine.


getLocalPath

public java.lang.String getLocalPath()
Get the local path; that is, the path to the directory in which the currently executing command is referring.

Specified by:
getLocalPath in interface ClientServices
Returns:
the local path

setLocalPath

public void setLocalPath(java.lang.String localPath)
Set the local path, i.e. the path to the directory in which all commands are given (top level).


isFirstCommand

public boolean isFirstCommand()
Returns true if no previous command was executed using thiz.

Specified by:
isFirstCommand in interface ClientServices

setIsFirstCommand

public void setIsFirstCommand(boolean isFirstCommand)
Set whether this is the first command. Normally you do not need to set this yourself - after execution the first command will have set this to false.

Specified by:
setIsFirstCommand in interface ClientServices

getUncompressedFileHandler

public FileHandler getUncompressedFileHandler()
Return the uncompressed file handler.

Specified by:
getUncompressedFileHandler in interface ResponseServices
Returns:
file handler for uncompressed data.

setUncompressedFileHandler

public void setUncompressedFileHandler(FileHandler uncompFileHandler)
Set the uncompressed file handler.

Specified by:
setUncompressedFileHandler in interface ClientServices

getGzipFileHandler

public FileHandler getGzipFileHandler()
Return the Gzip stream handler.

Specified by:
getGzipFileHandler in interface ResponseServices
Returns:
file handler for Gzip compressed data.

setGzipFileHandler

public void setGzipFileHandler(FileHandler gzipFileHandler)
Set the handler for Gzip data.

Specified by:
setGzipFileHandler in interface ClientServices

dontUseGzipFileHandler

public void dontUseGzipFileHandler()
ReSet the filehandler for Gzip compressed data. Makes sure the requests for sending gzipped data are not sent..

Specified by:
dontUseGzipFileHandler in interface ResponseServices

isAborted

public boolean isAborted()
Description copied from interface: ClientServices
Tests whether command execution should be aborted. Commands are encouraged to regulary poll this value if they expect to block for a long time in their code.

Specified by:
isAborted in interface ClientServices
Returns:
true if currently running command should abort, false otherwise

ensureConnection

public void ensureConnection()
                      throws AuthenticationException
Ensures, that the connection is open.

Specified by:
ensureConnection in interface ClientServices
Throws:
AuthenticationException - if it wasn't possible to connect

processRequests

public void processRequests(java.util.List requests)
                     throws java.io.IOException,
                            UnconfiguredRequestException,
                            ResponseException,
                            CommandAbortedException
Process all the requests. The connection must have been opened and set first.

Specified by:
processRequests in interface ClientServices
Parameters:
requests - the requets to process
Throws:
java.io.IOException
UnconfiguredRequestException
ResponseException
CommandAbortedException

executeCommand

public boolean executeCommand(Command command,
                              GlobalOptions globalOptions)
                       throws CommandException,
                              CommandAbortedException,
                              AuthenticationException
Execute a command. Do not forget to initialize the CVS Root on globalOptions first! Example: GlobalOptions options = new GlobalOptions(); options.setCVSRoot(":pserver:"+userName+"@"+hostName+":"+cvsRoot);

Parameters:
command - the command to execute
options - the global options to use for executing the command
Throws:
CommandException - if an error occurs when executing the command
CommandAbortedException - if the command is aborted
AuthenticationException

getCounter

public long getCounter()
Counts processRequests(java.util.List). send and received bytes.


convertPathname

public java.lang.String convertPathname(java.lang.String localDirectory,
                                        java.lang.String repository)
Convert a pathname in the CVS sense (see 5.10 in the protocol document) into a local absolute pathname for the file.

Specified by:
convertPathname in interface ResponseServices
Parameters:
localDirectory - the name of the local directory, relative to the directory in which the command was given
repository - the full repository name for the file

getRepository

public java.lang.String getRepository()
Get the repository path from the connection.

Specified by:
getRepository in interface ClientServices
Returns:
the repository path, e.g. /home/bob/cvs. Delegated to the Connection in this case
See Also:
Connection.getRepository()

updateAdminData

public void updateAdminData(java.lang.String localDirectory,
                            java.lang.String repositoryPath,
                            Entry entry)
                     throws java.io.IOException
Create or update the administration files for a particular file. This will create the CVS directory if necessary, and the Root and Repository files if necessary. It will also update the Entries file with the new entry

Specified by:
updateAdminData in interface ClientServices
Specified by:
updateAdminData in interface ResponseServices
Parameters:
localDirectory - the local directory, relative to the directory in which the command was given, where the file in question lives
repositoryPath - the path of the file in the repository, in absolute form.
entry - the entry object for that file
Throws:
java.io.IOException - if there is an error writing the files

setNextFileDate

public void setNextFileDate(java.util.Date modifiedDate)
Set the modified date of the next file to be written. The next call to writeFile will use this date.

Specified by:
setNextFileDate in interface ResponseServices
Parameters:
modifiedDate - the date the file should be marked as modified

getNextFileDate

public java.util.Date getNextFileDate()
Get the modified date for the next file.

Specified by:
getNextFileDate in interface ResponseServices
Returns:
the date and then null the instance variable.

getEntry

public Entry getEntry(java.io.File f)
               throws java.io.IOException
Get the Entry for the specified file, if one exists.

Specified by:
getEntry in interface ClientServices
Parameters:
f - the file
Throws:
java.io.IOException - if the Entries file cannot be read

getEntries

public java.util.Iterator getEntries(java.io.File directory)
                              throws java.io.IOException
Get the entries for a specified directory.

Specified by:
getEntries in interface ClientServices
Parameters:
directory - the directory for which to get the entries
Returns:
an iterator of Entry objects
Throws:
java.io.IOException

exists

public boolean exists(java.io.File file)
Description copied from interface: ClientServices
Tests for existence of the given file. Normally this method delegates to File.exists() but it may also return true for files that exists only virtually (in memory). Is such case the file/directory will not exist on disk but its metadata will be available via getEntries() methods.

Specified by:
exists in interface ClientServices
Parameters:
file - file to test for existence
Returns:
true if the file exists, false otherwise

getRepositoryForDirectory

public java.lang.String getRepositoryForDirectory(java.lang.String directory)
                                           throws java.io.IOException
Get the repository path for a given directory, for example in the directory /home/project/foo/bar, the repository directory might be /usr/cvs/foo/bar. The repository directory is commonly stored in the file
Repository
in the CVS directory on the client (this is the case in the standard CVS command-line tool). If no
CVS/Repository
file was found, the specified directory, the localpath are used to "guess" the repository path.

Specified by:
getRepositoryForDirectory in interface ClientServices
Parameters:
directory - the directory
Throws:
java.io.IOException

getRepositoryForDirectory

public java.lang.String getRepositoryForDirectory(java.io.File directory)
                                           throws java.io.IOException
Description copied from interface: ClientServices
Semantically equivalent to ClientServices.getRepositoryForDirectory(String) but does not try to recover from missing CVS/Repository file.

Specified by:
getRepositoryForDirectory in interface ClientServices
Parameters:
directory - the directory to get repository for
Returns:
repository path that corresponds to the given local working directory or null if local directory is not versioned or does not exist
Throws:
java.io.IOException - if the repository cannot be determined by reading CVS/Repository file

setEntry

public void setEntry(java.io.File file,
                     Entry entry)
              throws java.io.IOException
Set the Entry for the specified file.

Specified by:
setEntry in interface ResponseServices
Parameters:
file - the file
entry - the new entry
Throws:
java.io.IOException - if an error occurs writing the details

removeEntry

public void removeEntry(java.io.File file)
                 throws java.io.IOException
Remove the Entry for the specified file.

Specified by:
removeEntry in interface ClientServices
Specified by:
removeEntry in interface ResponseServices
Parameters:
file - the file whose entry is to be removed
Throws:
java.io.IOException - if an error occurs writing the Entries file

removeLocalFile

public void removeLocalFile(java.lang.String pathname)
                     throws java.io.IOException
Remove the specified file from the local disk. If the file does not exist, the operation does nothing.

Specified by:
removeLocalFile in interface ResponseServices
Parameters:
pathname - the full path to the file to remove
Throws:
java.io.IOException - if an IO error occurs while removing the file

removeLocalFile

public void removeLocalFile(java.lang.String pathName,
                            java.lang.String repositoryName)
                     throws java.io.IOException
Removes the specified file determined by pathName and repositoryName. In this implementation the filename from repositoryPath is added to the localpath (which doesn't have the filename in it) and that file is deleted.

Specified by:
removeLocalFile in interface ResponseServices
Throws:
java.io.IOException - if an IO error occurs while removing the file

renameLocalFile

public void renameLocalFile(java.lang.String pathname,
                            java.lang.String newName)
                     throws java.io.IOException
Rename the local file.

Specified by:
renameLocalFile in interface ResponseServices
Parameters:
pathname - the full path to the file to rename
newName - the new name of the file (not the full path)
Throws:
java.io.IOException - if an IO error occurs while renaming the file

getEventManager

public EventManager getEventManager()
Get the CVS event manager. This is generally called by response handlers that want to fire events.

Specified by:
getEventManager in interface ResponseServices
Returns:
the eventManager

getGlobalOptions

public GlobalOptions getGlobalOptions()
Get the global options that are set to this client. Individual commands can get the global options via this method.

Specified by:
getGlobalOptions in interface ClientServices
Specified by:
getGlobalOptions in interface ResponseServices

abort

public void abort()
Call this method to abort the current command. The command will be aborted at the next suitable time


getAllFiles

public java.util.Set getAllFiles(java.io.File directory)
                          throws java.io.IOException
Get all the files contained within a given directory that are known to CVS.

Specified by:
getAllFiles in interface ClientServices
Parameters:
directory - the directory to look in
Returns:
a set of all files.
Throws:
java.io.IOException

setIgnoreFileFilter

public void setIgnoreFileFilter(IgnoreFileFilter ignoreFileFilter)
Description copied from interface: ClientServices
Sets the specified IgnoreFileFilter to use to ignore non-cvs files. TS, 2001-11-23: really needed in the interface (it's never used)?

Specified by:
setIgnoreFileFilter in interface ClientServices

getIgnoreFileFilter

public IgnoreFileFilter getIgnoreFileFilter()
Description copied from interface: ClientServices
Returns the IgnoreFileFilter used to ignore non-cvs files. TS, 2001-11-23: really needed in the interface (it's never used)?

Specified by:
getIgnoreFileFilter in interface ClientServices

shouldBeIgnored

public boolean shouldBeIgnored(java.io.File directory,
                               java.lang.String noneCvsFile)
Description copied from interface: ClientServices
Returnes true to indicate, that the file specified by directory and nonCvsFile should be ignored.

Specified by:
shouldBeIgnored in interface ClientServices

getStickyTagForDirectory

public java.lang.String getStickyTagForDirectory(java.io.File directory)
Checks for presence of CVS/Tag file and returns it's value.

Specified by:
getStickyTagForDirectory in interface ClientServices
Returns:
the value of CVS/Tag file for the specified directory null if file doesn't exist

setValidRequests

public void setValidRequests(java.lang.String requests)
This method is called when a response for the ValidRequests request is received.

Specified by:
setValidRequests in interface ResponseServices
Parameters:
requests - A List of requests that is valid for this CVS server separated by spaces.

addWrapper

public void addWrapper(StringPattern pattern,
                       KeywordSubstitutionOptions option)
This method is called by WrapperSendResponse for each wrapper setting sent back by the CVS server

Specified by:
addWrapper in interface ResponseServices
Parameters:
pattern - A StringPattern indicating the pattern for which the wrapper applies
option - A KeywordSubstituionOption corresponding to the setting

getWrappersMap

public java.util.Map getWrappersMap()
                             throws CommandException
Returns the wrappers map associated with the CVS server The map is valid only after the connection is established

Specified by:
getWrappersMap in interface ClientServices
Throws:
CommandException

 

Built on August 7 2008.  |  Portions Copyright 1997-2005 Sun Microsystems, Inc. All rights reserved.