allensoft.javacvs.client
Class CVSClient

java.lang.Object
  |
  +--allensoft.javacvs.client.CVSClient

public class CVSClient
extends java.lang.Object

This is the main class that implements the CVS client/server protocol. It is used to send requests to the server and process the server's responses. Typical usage is to create a batch of requests to perform and then perform them using the perfromRequestBatch method. For example, to perform a request that commits changes to a file with the log message "Added some new features" you could do this:



// Create a request batch to add requests to

CVSRequestBatch batch = new CVSRequestBatch();

// Add a request to the batch

batch.addRequest (new CommitRequest (file, new CommitOptions ("Added some new features")));

// Now try to run the batch of requests. In this example, there is only one request added to the
// batch but you can add as many as you like. The requests can even be for completely different repositories.

try
{
client.performRequestBatch (batch);	// Perform the batch
}

// Catch any problems and tell user

catch (CVSException e) {...}
catch (IOException e) {...}

As sending a single request is quite common there is also a more convenient method, performRequest, to do a single request without the requirement of creating a batch first. The above example could have also been written:


try
{
client.performRequest (new CommitRequest (file, new CommitOptions ("Added some new features")));
}

// Catch any problems and tell user

catch (CVSException e) {...}
catch (IOException e) {...}

The CVSClient also has some other very unique and powerful features. One of those is a batch mode which causes requests to automatically be added to a batch and performed at a later time. This is transparent to any calling code that is trying to perform requests. Batch mode is turned on by calling the enterBatchMode method. The requests that have built up can then be sent by calling sendBatch. Batch mode can also be turned off by calling exitBatchMode but this will mean that none of the requests that have been built up since enterBatchMode will be performed.


Constructor Summary
CVSClient(CVSConnectionManager connectionManager, LoginManager loginManager)
          Creates a new CVS client that uses the supllied connection manager for creating connections and the supplied login manger for getting login details from the user.
CVSClient(LoginManager loginManager)
          Creates a new CVS client that uses the default connection manager for creating connections and the supplied login manger for getting login details from the user.
 
Method Summary
 void abortRequest()
           
 void abortRequest(RequestAbortedException e)
          Aborts the request(s) currently being performed.
 void addCVSClientListener(CVSClientListener listener)
           
 void enterBatchMode()
          Puts this client in batch mode.
 void exitBatchMode()
          Exits batch mode.
protected  void fireEnteredBatchMode()
           
protected  void fireExitedBatchMode()
           
protected  void fireFinishedRequests()
           
protected  void fireOpenedConnection()
           
protected  void fireReceivedResponse(CVSResponse response)
           
protected  void fireReceivedText(java.lang.String sText)
           
protected  void fireSentText(java.lang.String sText)
           
protected  void fireStartingRequests()
           
protected  void fireStatusUpdate(java.lang.String sText)
           
 CVSRequestBatch getBatch()
          Gets the request batch that will be sent when sendBatch is called.
 CVSConnectionManager getConnectionManager()
          Gets the connection manager this client uses to create connections to a server.
 CVSRequest getCurrentRequest()
           
 GlobalOptions getGlobalOptions()
           
 java.io.FileFilter getIgnoreFileFilter()
          Gets the file filter used to determine if a file should be ignored.
 LoginManager getLoginManager()
          Gets the login manager this client uses to get login details from the user when necessary.
 int getMaxDotDotLevel()
           
protected  java.lang.String getResourceString(java.lang.String sSubKey)
           
 boolean getUseUnchanged()
           
 java.lang.String getValidResponses()
           
 boolean isInBatchMode()
          Checks if this client is in batch mode.
 boolean isPerformingRequests()
           
 boolean isRequestValid(java.lang.String sRequest)
           
 CVSResponse performRequest(CVSRequest request)
           
 CVSResponse performRequest(CVSRequest request, boolean bSendImmediately)
          Performs a request.
 void performRequestBatch(CVSRequestBatch batch)
           
 void performRequestBatch(CVSRequestBatch batch, boolean bSendImmediately)
          Performs a sequential list of requests using only one connection to a server.
 void removeCVSClientListener(CVSClientListener listener)
           
 void sendBatch()
          Sends the current batch of requests that have built up since enterBatchMode was called and exits batch mode.
 void setConnectionManager(CVSConnectionManager manager)
          Sets the connection manager this client uses to create connections to a server.
 void setGlobalOptions(GlobalOptions options)
           
 void setIgnoreFileFilter(java.io.FileFilter filter)
          Sets the file filter used to determine if a file should be ignored.
 void setLoginManager(LoginManager manager)
          Sets the login manager this client uses to get login details from the user when necessary.
 void setMaxDotDotLevel(int n)
           
 void setUseUnchanged(boolean b)
           
 void setValidResponses(java.lang.String sResponses)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CVSClient

public CVSClient(CVSConnectionManager connectionManager,
                 LoginManager loginManager)
Creates a new CVS client that uses the supllied connection manager for creating connections and the supplied login manger for getting login details from the user.

CVSClient

public CVSClient(LoginManager loginManager)
Creates a new CVS client that uses the default connection manager for creating connections and the supplied login manger for getting login details from the user.
Method Detail

getCurrentRequest

public CVSRequest getCurrentRequest()

addCVSClientListener

public void addCVSClientListener(CVSClientListener listener)

removeCVSClientListener

public void removeCVSClientListener(CVSClientListener listener)

isPerformingRequests

public boolean isPerformingRequests()

getConnectionManager

public CVSConnectionManager getConnectionManager()
Gets the connection manager this client uses to create connections to a server.

setConnectionManager

public void setConnectionManager(CVSConnectionManager manager)
Sets the connection manager this client uses to create connections to a server.

getLoginManager

public LoginManager getLoginManager()
Gets the login manager this client uses to get login details from the user when necessary.

setLoginManager

public void setLoginManager(LoginManager manager)
Sets the login manager this client uses to get login details from the user when necessary.

getValidResponses

public java.lang.String getValidResponses()

setValidResponses

public void setValidResponses(java.lang.String sResponses)

getMaxDotDotLevel

public int getMaxDotDotLevel()

setMaxDotDotLevel

public void setMaxDotDotLevel(int n)

getUseUnchanged

public boolean getUseUnchanged()

setUseUnchanged

public void setUseUnchanged(boolean b)

getIgnoreFileFilter

public java.io.FileFilter getIgnoreFileFilter()
Gets the file filter used to determine if a file should be ignored. The filter should accept files that should not be ignored. This is used only by the client to send questionable commands to the server. It will not actually prevent files from being added to a repository, say, if this filter thinks they should be ignored. If a filter is not set then a CVSIgnoreFileFilter will be returned.

setIgnoreFileFilter

public void setIgnoreFileFilter(java.io.FileFilter filter)
Sets the file filter used to determine if a file should be ignored. The filter should accept files that should not be ignored. This is used only by the client to send questionable commands to the server. It will not actually prevent files from being added to a repository, say, if this filter thinks they should be ignored.

getGlobalOptions

public GlobalOptions getGlobalOptions()

setGlobalOptions

public void setGlobalOptions(GlobalOptions options)

isRequestValid

public boolean isRequestValid(java.lang.String sRequest)

performRequest

public CVSResponse performRequest(CVSRequest request,
                                  boolean bSendImmediately)
                           throws java.io.IOException,
                                  CVSException
Performs a request. This involves sending the request to the server and receiving the response from the server. This is the main method for performing a request and by passing specific request types to this method different requests can be performed. For example, to send a request to update a file:
client.performRequest (new UpdateRequest (file));
There are more convenient methods for performing common requests that build the request object and supply it to this method. If bSendImmediately is true then the request will be sent immediately regardless of whether this client is in batch mode or not.
Parameters:
request - the request to perform.
bSendImmediately - true if request should be sent immediately regardless of whether this client is in batch mode. If false the request will be added to the current batch if in batch mode or performed immedaitely otherwise.
Returns:
a CVSResponse detailing the response from the server or null if no response was received.

performRequest

public CVSResponse performRequest(CVSRequest request)
                           throws java.io.IOException,
                                  CVSException

performRequestBatch

public void performRequestBatch(CVSRequestBatch batch,
                                boolean bSendImmediately)
                         throws java.io.IOException,
                                CVSException
Performs a sequential list of requests using only one connection to a server. If the requests have different repository locations then they will be performed in the order they are defined with one connection to each server required. If bSendImmediately is true then the batch will be sent immediately regardless of whether this client is in batch mode or not. After performing the batch you can examine the batch and see which requests completed successfully and which had problems.

performRequestBatch

public void performRequestBatch(CVSRequestBatch batch)
                         throws java.io.IOException,
                                CVSException

enterBatchMode

public void enterBatchMode()
Puts this client in batch mode. When in batch mode the client won't actually perform any requests until the sendBatch method is called. This is transparent to any threads that have asked this client to perform requests and they will simply wait until the batch is sent before continuing.

exitBatchMode

public void exitBatchMode()
Exits batch mode. If this is called before sendBatch has been called the the current batch of requests will not be performed.

isInBatchMode

public boolean isInBatchMode()
Checks if this client is in batch mode.

getBatch

public CVSRequestBatch getBatch()
Gets the request batch that will be sent when sendBatch is called.
Returns:
null if this client is not in batch mode or the batch that will be executed.

sendBatch

public void sendBatch()
               throws CVSException,
                      java.io.IOException
Sends the current batch of requests that have built up since enterBatchMode was called and exits batch mode. If the client is not in batch mode then this will do nothing.

abortRequest

public void abortRequest(RequestAbortedException e)
Aborts the request(s) currently being performed.

abortRequest

public void abortRequest()

getResourceString

protected java.lang.String getResourceString(java.lang.String sSubKey)

fireSentText

protected void fireSentText(java.lang.String sText)

fireReceivedText

protected void fireReceivedText(java.lang.String sText)

fireStatusUpdate

protected void fireStatusUpdate(java.lang.String sText)

fireReceivedResponse

protected void fireReceivedResponse(CVSResponse response)

fireStartingRequests

protected void fireStartingRequests()

fireOpenedConnection

protected void fireOpenedConnection()

fireFinishedRequests

protected void fireFinishedRequests()

fireEnteredBatchMode

protected void fireEnteredBatchMode()

fireExitedBatchMode

protected void fireExitedBatchMode()