CommandCentral.java :  » Source-Control » sourcejammer » org » sourcejammer » client » gui » Java Open Source

Java Open Source » Source Control » sourcejammer 
sourcejammer » org » sourcejammer » client » gui » CommandCentral.java
/*
 *  Copyright (C) 2001-2003 Robert MacGrogan
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 *
 * $Archive: SourceJammer$
 * $FileName: CommandCentral.java$
 * $FileID: 3981$
 *
 * Last change:
 * $AuthorName: Rob MacGrogan$
 * $Date: 9/15/03 12:04 PM$
 * $Comment: On check in, check if there's a new file id. This means
 *          file branched on check in. Use new file ID to download latest
 *          version, if required.$
 */


package org.sourcejammer.client.gui;

import org.sourcejammer.project.view.*;
import org.sourcejammer.project.view.ArchiveProperties;
import javax.swing.JOptionPane;
import javax.swing.*;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableColumn;
import org.sourcejammer.util.ConfigurationException;
import org.sourcejammer.util.FileUtil;
import org.sourcejammer.util.ProcessTimer;
import org.sourcejammer.util.RepeatingResponse;
import org.sourcejammer.util.SourceJammerConnectionException;
import org.apache.xpath.operations.Mult;
import org.sourcejammer.client.SOAPPortal;
import org.sourcejammer.project.NodeExistsException;
import org.sourcejammer.project.NodeList;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.io.*;
import org.sourcejammer.util.AppConfig;
import org.sourcejammer.client.gui.conf.FileNodeInfo;
import org.sourcejammer.client.gui.conf.GuiConf;
import org.sourcejammer.client.gui.conf.UserPrefs;
import org.sourcejammer.client.SourceJammerClient;
import javax.swing.table.TableModel;
import javax.swing.tree.TreePath;
import org.sourcejammer.util.StringUtil;
import org.sourcejammer.client.filesys.FileSysUtil;
import org.sourcejammer.project.Node;
import org.sourcejammer.project.controller.LabelVersionMappingBean;
import org.sourcejammer.project.NodeDoesNotExistException;
import org.sourcejammer.util.ZipUtil;
import org.sourcejammer.util.BadMethodArgumentException;
import org.sourcejammer.client.filesys.SourceVersionChecker;
import org.sourcejammer.client.gui.logger.MessageDisplayStream;
import org.sourcejammer.client.gui.process.ProcessCentral;
import org.sourcejammer.client.plugin.EventTimingType;
import org.sourcejammer.util.TempDirectoryManager;
import org.sourcejammer.client.FileTransport;
import org.sourcejammer.project.view.DownloadFileIdentifier;
import org.sourcejammer.client.gui.action.ActionCentral;
import org.sourcejammer.client.NoSessionException;
import org.sourcejammer.client.DisplayTextLibrary;

/**
 * Title:        $FileName: CommandCentral.java$
 * @version $VerNum: 34$
 * @author $AuthorName: Rob MacGrogan$<br><br>
 * 
 * $Description: Central singleton that handles issuing all
 *              commands and performing all file system actions for GUI.$<br>
 * $KeyWordsOff: $<br><br>
 * 
 * Central singleton that handles issuing all commands and performing all
 * file system actions for GUI.
 */
public class CommandCentral implements SJRequestParams, SJResponseParams{

  public static final String APP_TITLE = "SourceJammer!";

  private static CommandCentral instance = new CommandCentral();
  private static final String SJ_FILE_NAME_ENV_VAR = "sourcejammer_file_name";
  private static final int ZIP_BUFFER_SIZE = 50;

  private String msUserName;
  private String msPassword;
  private String msArchiveName = null;
  private long mlSessionID = -1;
  private SJPrimaryWindow mjRootAppFrame = null;
  private SOAPPortal moPortal = null;
  private String msURL = null;
  private static TableColumnModel moPrimaryColumnModel = null;
  private ProjectTreeNode moCurrentTreeNode = null;
  private boolean mbAppWindowRendered = false;
  private GuiConf moConf = null;
  public static PrintStream out = null;
  private SourceVersionChecker currentProjectVerChecker = null;
  private String proxyPassword = null;
  private boolean proxyPasswordSet = false;

  private CommandCentral() {
  }

  public synchronized void setArchiveConnectInfo(String archive, String userName, String password)
        throws IOException{
    moConf = new GuiConf(archive, userName);
    msArchiveName = archive;
    msUserName = userName;
    msPassword = password;
  }

  public String getArchiveName(){
    return msArchiveName;
  }

  public SOAPPortal getPortal(){
    return moPortal;
  }

  /**
   * This method can be called to set the static out to some PrintStream
   * other than the message pane. Typically, this will be called when
   * SJ is being automated.
   */
  public void setAlternateOut(PrintStream altOut){
    out = altOut;
  }

  public String getUserName(){
    return msUserName;
  }

  public String getPassword(){
    return msPassword;
  }

  public GuiConf getGuiConf(){
    return moConf;
  }

  public void setPrimaryTableColumnModel(TableColumnModel model){
    moPrimaryColumnModel = model;
  }

  public void rebuildFileView() throws NodeExistsException, IOException{
    rebuildFileView(false);
  }

  public void rebuildFileView(boolean fromRoot) throws NodeExistsException, IOException{
    ProjectTreeNode node = null;
    if (! fromRoot){
      node = moCurrentTreeNode;
    }
    else if (mjRootAppFrame != null){
      Object oRoot = mjRootAppFrame.getProjectTree().getModel().getRoot();
      if (oRoot instanceof ProjectTreeNode){
        node = (ProjectTreeNode)oRoot;
      }
    }
    if (node != null){
      node.rebuildDisplayList(UserPrefs.getInstance().getBoolean(UserPrefs.LOCAL_REMOTE_SYNC_VIEW, true));
      if (moCurrentTreeNode != null){
        GuiUtil.setNewTableModel(moCurrentTreeNode.getFileTableModel());
      }
    }
  }

  public void setCurrentTreeNode(ProjectTreeNode node){
    moCurrentTreeNode = node;
    if (node != null){
      try{
        java.io.File defaultDir = moConf.getDefaultWorkingDirectory(node.getNodeName());
        if (defaultDir != null && defaultDir.exists()){
          currentProjectVerChecker = new SourceVersionChecker(defaultDir, msURL, msArchiveName);
        }
        else{
          currentProjectVerChecker = null;
        }
      }
      catch (IOException ex){
        currentProjectVerChecker = null;
      }
    }
  }

  public SourceVersionChecker getCurrentProjectChecker(){
    return currentProjectVerChecker;
  }

  public ProjectTreeNode getCurrentTreeNode(){
    return moCurrentTreeNode;
  }

  public void setAppWindowRendered(boolean b){
    mbAppWindowRendered = b;
  }

  public boolean isAppWindowRendered(){
    return mbAppWindowRendered;
  }

  public TableColumnModel getPrimaryTableColumnModel(){
    TableColumn col = moPrimaryColumnModel.getColumn(1);
    return moPrimaryColumnModel;
  }

  public static CommandCentral getInstance(SJPrimaryWindow rootApplicationFrame){
    instance.setRootAppFrameIfNull(rootApplicationFrame);
    instance.initializeOut();
    return instance;
  }

  private void initializeOut(){
    if (out == null && mjRootAppFrame != null){
      JTextArea messageArea = mjRootAppFrame.getMessageArea();
      if (messageArea == null){
        System.out.println("Message area is null.");
      }
      MessageDisplayStream outStream = new MessageDisplayStream(messageArea, mjRootAppFrame.getMessagePane());
      out = new PrintStream(outStream);
      //System.out.println("Initialized out.");
    }
  }

  public void setServerURL(String url) throws MalformedURLException{
    moPortal = new SOAPPortal();
    moPortal.setURL(url);
    msURL = url;
  }


  public static CommandCentral getInstance(){
    return instance;
  }

  private synchronized void setRootAppFrameIfNull(SJPrimaryWindow rootApplicationFrame){
    if (mjRootAppFrame == null){
      mjRootAppFrame = rootApplicationFrame;
    }
    else {
      throw new ConfigurationException("Application root frame has already been set.");
    }
  }

  public String[] getSelectedFileNames(){
    String[] saReturn = null;
    JTable table = mjRootAppFrame.getPrimaryTable();
    int iSelectedRows[] = table.getSelectedRows();
    TableModel model = table.getModel();

    saReturn = new String[iSelectedRows.length];
    for (int i = 0; i < iSelectedRows.length; i++){
      NodeInfo nd = (NodeInfo)model.getValueAt(iSelectedRows[i], 0);
      saReturn[i] = nd.getNodeName();
      //saReturn[i] = (String)model.getValueAt(iSelectedRows[i], 1);
    }
    return saReturn;
  }

  public NodeInfo getSelectedFileNodeInfo(){
    NodeInfo[] files = getSelectedFilesNodeInfo();
    return files[0];
  }

  public NodeInfo getSelectedFileNodeInfo(String name){
    NodeInfo file = null;
    JTable table = mjRootAppFrame.getPrimaryTable();
    int iSelectedRows[] = table.getSelectedRows();
    TableModel model = table.getModel();

    for (int i = 0; i < iSelectedRows.length; i++){
      NodeInfo nd = (NodeInfo)model.getValueAt(iSelectedRows[i], 0);
      if (nd.getNodeName().equals(name)){
        file = nd;
        break;
      }
    }
    return file;
  }

  public NodeInfo[] getSelectedFilesNodeInfo(){
    NodeInfo[] fileList = null;
    JTable table = mjRootAppFrame.getPrimaryTable();
    int iSelectedRows[] = table.getSelectedRows();
    TableModel model = table.getModel();

    fileList = new NodeInfo[iSelectedRows.length];
    for (int i = 0; i < iSelectedRows.length; i++){
      fileList[i] = (NodeInfo)model.getValueAt(iSelectedRows[i], 0);
    }
    return fileList;
  }

  public String[] getAllCurrentFileNames(){
    String[] saReturn = null;
    JTable table = mjRootAppFrame.getPrimaryTable();
    int iRowCount = table.getRowCount();

    TableModel model = table.getModel();

    ArrayList lst = new ArrayList();
    for (int i = 0; i < iRowCount; i++){
      FileNodeInfo nd = (FileNodeInfo)model.getValueAt(i, 0);
      if (nd.getLocalRemoteSyncState() != FileNodeInfo.NOT_IN_ARCHIVE)
        lst.add(nd.getNodeName());
    }
    saReturn = new String[lst.size()];
    lst.toArray(saReturn);
    return saReturn;
  }

  public String currentURL(){
    return msURL;
  }

  /**
   * Returns list of archives available on server user is currently
   * connected to.
   */
  public String[] getArchiveNameList()
        throws SourceJammerConnectionException, GUICommandException{
    String[] names = null;
    SJRequest request = getBaseRequest();
    SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.GET_ARCHIVE_NAMES);
    if ( response.getErrorEncountered()){
      throw new GUICommandException(response.getMessage());
    }
    Object[] oArchNames = (Object[])response.objectValue(OBJECT_ARRAY);
    names = new String[oArchNames.length];
    for (int i = 0; i < oArchNames.length; i++){
      names[i] = (String)oArchNames[i];
    }
    return names;
  }

  public SJResponse sendRequest(SJRequest  request, String method)
          throws SourceJammerConnectionException, GUICommandException{
    SJResponse response = null;
    try{
      response = moPortal.sendRequest(request, method);
    }
    catch(NoSessionException ex){
      noSession();
      //try action again after reconnecting
      try{
        response = moPortal.sendRequest(request, method);
      }
      catch (NoSessionException ex2){
        throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_LOGIN_EXPIRED), ex2);
      }
    }
    return response;
  }

  private void noSession() throws SourceJammerConnectionException, GUICommandException{
    try{
      //Attempt to reconnect.
      connectToArchive();
    }
    catch (NoSessionException ex){
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_LOGIN_EXPIRED));
    }
  }

  /**
   * Returns true if the archive deleted is the current archive and
   * the user is now disconnected. Signal to close any open dialog.
   */
  public boolean deleteArchive(String archiveName)
        throws SourceJammerConnectionException, GUICommandException{
    boolean deletingCurrentArchive = false;
    SJRequest request = getBaseRequest();
    request.putString(NEW_ARCHIVE_NAME, archiveName);
    SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.DELETE_ARCHIVE);
    if (! response.getErrorEncountered()){
      //Set logout status to not logged in if just deleted current archive.
      if (archiveName.equals(msArchiveName)){
        deletingCurrentArchive = true;
        setDisconnectedDisplaySettings();
        msArchiveName = null;
        msURL = null;
        msUserName = null;
        msPassword = null;
      }
      printServerMessage(response.getMessage());
    }
    else{
      throw new GUICommandException(response.getMessage());
    }
    return deletingCurrentArchive;
  }

  public Project connectToArchive()
          throws SourceJammerConnectionException, GUICommandException, NoSessionException{
    Project oReturn = null;
    try {
      SJRequest request = new SJRequest();
      request.setArchiveName(msArchiveName);
      request.setUserName(msUserName);
      request.setPassword(msPassword);

      //Don't use internal sendRequest() method here because sendRequest() itself
      //may call this method. And NoSessionException does not mean very much
      //for Connection calls.
      
      //Before we call soap, set the proxy password to whatever we've got.
      moPortal.setProxyPassword(proxyPassword);
      SJResponse response = moPortal.sendRequest(request, SOAPPortal.MCPMethodNames.CONNECT);
      if (! response.getErrorEncountered()) {
        mlSessionID = response.getSessionID();
        oReturn = response.projectValue();
        try{
          oReturn.buildChildrenFromStrings();
        }
        catch (NodeExistsException ex){
          throw new ConfigurationException(ex.getMessage(), ex);
        }
      }
      else {
        throw new GUICommandException (response.getMessage());
      }
      if (mjRootAppFrame != null){
        mjRootAppFrame.setTitle(APP_TITLE + " -- " + msArchiveName);
      }
      out.print(DisplayTextLibrary.displayText(DisplayTextLibrary.LBL_CONNECTED_TO));
      out.print(msArchiveName);
      out.print(" @ ");
      out.println(msURL);
      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      ex.printStackTrace(out);
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
    return oReturn;
  }

  public void resetAppTitle(){
    mjRootAppFrame.setTitle(APP_TITLE);
  }

  /**
   * Get file info
   */
  public org.sourcejammer.project.view.File getFileInfo(NodeInfo flInfo, SJRequest request)
          throws GUICommandException, SourceJammerConnectionException{
    org.sourcejammer.project.view.File oReturn = null;
    try {
      if (request == null){
        request = getBaseRequest();
      }
      request.putLong(REQUESTED_NODE_UNIQUE_ID, flInfo.getUniqueID());

      SourceJammerClient.getInstance().getFileListeners()
                .notifyFileDetailsViewed(request, null, EventTimingType.BEFORE_REQUEST_SENT, flInfo);

      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.GET_FILE_INFO);

      SourceJammerClient.getInstance().getFileListeners()
                .notifyFileDetailsViewed(request, response, EventTimingType.AFTER_RESPONSE_RECEIVED, flInfo);

      if (response.getErrorEncountered()){
        throw new GUICommandException(response.getMessage());
      }
      oReturn = response.fileValue();
      try{
        oReturn.buildChildrenFromStrings();
      }
      catch (NodeExistsException ex){
        throw new ConfigurationException(ex.getMessage(), ex);
      }
      
      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      ex.printStackTrace(out);
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
    return oReturn;
  }

  /**
   * Get Branch report
   */
  public String getBranchReport(long fileID, SJRequest request)
          throws GUICommandException, SourceJammerConnectionException{
    String rpt = null;
    try {
      if (request == null){
        request = getBaseRequest();
      }
      request.putLong(REQUESTED_NODE_UNIQUE_ID, fileID);

      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.GET_BRANCH_REPORT);


      if (response.getErrorEncountered()){
        throw new GUICommandException(response.getMessage());
      }
      rpt = response.stringValue(BRANCHES);
    }
    catch (SourceJammerConnectionException ex){
      ex.printStackTrace(out);
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
    return rpt;
  }


  /**
   * Make a new project on the server.
   */
  public long makeProject(long parentProjectID, String newProjectName)
        throws SourceJammerConnectionException, GUICommandException {
    long lNewProjectID = -1;
    try {
      SJRequest request = getBaseRequest();
      newProjectName = newProjectName.trim();
      request.putLong(REQUESTED_NODE_UNIQUE_ID, parentProjectID);
      request.putString(REQUESTED_NODE_NAME, newProjectName);
      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.ADD_PROJECT);
      if (response.getErrorEncountered()){
        throw new GUICommandException(response.getMessage());
      }
      lNewProjectID = response.longValue(NODE_UNIQUE_ID);
      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
    return lNewProjectID;
  }

  public void renameProject(long projectID, long parentID, String newName){
    try {
      SJRequest request = getBaseRequest();
      request.putLong(REQUESTED_NODE_UNIQUE_ID, projectID);
      request.putLong(PARENT_NODE_UNIQUE_ID, parentID);
      request.putString(REQUESTED_NODE_NAME, newName);
      SJResponse response = moPortal.sendRequest(request, SOAPPortal.MCPMethodNames.RENAME_PROJECT);
      if (response.getErrorEncountered()){
        throw new Exception(response.getMessage());
      }
      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      MessageBoxUtil.displayErrorMessage(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION));
    }
    catch (Exception ex){
      MessageBoxUtil.displayErrorMessage(ex.getMessage());
    }
  }

  public void renameFile(NodeInfo flInfo, long parentID, String newName, SJRequest request)
          throws SourceJammerConnectionException, GUICommandException{
    try {
      if (request == null){
        request = getBaseRequest();
      }
      request.putLong(REQUESTED_NODE_UNIQUE_ID, flInfo.getUniqueID());
      request.putLong(PARENT_NODE_UNIQUE_ID, parentID);
      request.putString(REQUESTED_NODE_NAME, newName);
      
      SourceJammerClient.getInstance().getFileListeners()
              .notifyFileRenamed(request, null, EventTimingType.BEFORE_REQUEST_SENT, flInfo);

      SJResponse response = moPortal.sendRequest(request, SOAPPortal.MCPMethodNames.RENAME_FILE);
      if (response.getErrorEncountered()){
        throw new Exception(response.getMessage());
      }
      printServerMessage(response.getMessage());

      SourceJammerClient.getInstance().getFileListeners()
              .notifyFileRenamed(request, response, EventTimingType.AFTER_RESPONSE_RECEIVED, flInfo);

    }
    catch (SourceJammerConnectionException ex){
      ex.printStackTrace(out);
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION));
    }
    catch (Exception ex){
      throw new GUICommandException(ex.getMessage(), ex);
    }
  }

  /**
   * Retrieve info about a project from the server.
   *
   * Migrated to 1.1 unique ID approach. --rfm
   */
  public Project retrieveProject(long projectID)
          throws SourceJammerConnectionException, GUICommandException{
    Project oReturn = null;
    try {
      SJRequest request = getBaseRequest();
      request.putLong(REQUESTED_NODE_UNIQUE_ID, projectID);

      SJResponse response = moPortal.sendRequest(request, SOAPPortal.MCPMethodNames.GET_PROJECT_INFO);
      if (response.getErrorEncountered()){
        throw new Exception(response.getMessage());
      }
      oReturn = response.projectValue();
      try{
        oReturn.buildChildrenFromStrings();
      }
      catch (NodeExistsException ex){
        throw new ConfigurationException(ex.getMessage(), ex);
      }
      mlSessionID = response.getSessionID();
    }
    catch (SourceJammerConnectionException ex){
      ex.printStackTrace(out);
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION));
    }
    catch (Exception ex){
      throw new GUICommandException(ex.getMessage(), ex);
    }
    return oReturn;
  }


  /**
   * Returns unique id of project based on full path to sourcejammer node.
   */
  public long getProjectUniqueID(String sjPath)
        throws SourceJammerConnectionException, GUICommandException{
    return getFileUniqueID(sjPath);
  }

  /**
   * Returns unique id of file based on full path to sourcejammer node.
   */
  public long getFileUniqueID(String sjPath)
        throws SourceJammerConnectionException, GUICommandException{
    long lFileID = -1;
    try{
      SJRequest request = getBaseRequest();
      //First get the file ID.
      request.putLong(REQUESTED_NODE_UNIQUE_ID, 0);
      request.putString(REQUESTED_NODE_NAME, sjPath);
      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.GET_UNIQUE_ID_FROM_PATH);
      if ( ! response.getErrorEncountered() ){
        lFileID = response.longValue(NODE_UNIQUE_ID);
      }
      else {
        throw new Exception(response.getMessage());
      }
    }
    catch (SourceJammerConnectionException ex){
      ex.printStackTrace(out);
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION));
    }
    catch (Exception ex){
      throw new GUICommandException(ex.getMessage(), ex);
    }
    return lFileID;
  }

  public void addFile(long parentUniqueID, String newFileName,
                      String localFileNameLocation, int fileType,
                      int historyType,  String description,
                      String afterAddAction, SJRequest request)
        throws GUICommandException, SourceJammerConnectionException, IOException{
    try {
      if (request == null){
        request = getBaseRequest();
      }
      request.putLong(REQUESTED_NODE_UNIQUE_ID, parentUniqueID);
      request.putString(REQUESTED_NODE_NAME, newFileName);
      if ( fileType != AppConfig.FileTypes.BINARY &&
           fileType != AppConfig.FileTypes.TEXT ){
        throw new GUICommandException (DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_FILE_TYPE_INVALID));
      }
      FileProperties props = new FileProperties();
      props.setFileType(fileType);
      props.setHistoryStorageType(historyType);
      props.setDescription(description);
      request.putObject(FILE_PROPERTIES, props);

      //Send binary file using uploader proxy.
      java.io.File fl = new java.io.File(localFileNameLocation);
      long lFileUploadId = sendFileToServer(fl, request);
      request.putLong(FILE_UPLOAD_ID, lFileUploadId);
      
      //Notify file listeners.
      SourceJammerClient.getInstance().getFileListeners()
              .notifyFileAdded(request, props, EventTimingType.BEFORE_REQUEST_SENT, null);

      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.ADD_FILE);

      //Notify file listeners.
      SourceJammerClient.getInstance().getFileListeners()
              .notifyFileAdded(request, props, EventTimingType.AFTER_RESPONSE_RECEIVED, null);

      if ( response.getErrorEncountered() ){
        throw new GUICommandException(response.getMessage());
      }
      mlSessionID = response.getSessionID();
      long lNewVerID =  response.longValue(NODE_UNIQUE_ID);
      java.io.File flFile = new java.io.File(localFileNameLocation);
      SourceVersionChecker checker = getChecker(flFile.getParentFile());
      checker.updateLocalInfo(newFileName, lNewVerID);

      if (afterAddAction.equals(SourceJammerClient.lfa_SET_READ_ONLY)){
        flFile.setReadOnly();
      }
      else if (afterAddAction.equals(SourceJammerClient.lfa_DELETE)){
        flFile.delete();
      }
      else{
        //no special action.
      }

      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      ex.printStackTrace(out);
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }


  public void changeFileDescription(NodeInfo flInfo, String newDescription, SJRequest request)
        throws GUICommandException, SourceJammerConnectionException, IOException{
    try {
      if (request == null){
        request = getBaseRequest();
      }
      request.putLong(REQUESTED_NODE_UNIQUE_ID, flInfo.getUniqueID());
      request.putString(COMMENT, newDescription);

      SourceJammerClient.getInstance().getFileListeners()
                .notifyFileDescriptionChanged(request, newDescription, EventTimingType.BEFORE_REQUEST_SENT, flInfo);
      
      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.CHANGE_FILE_DESCRIPTION);

      SourceJammerClient.getInstance().getFileListeners()
                .notifyFileDescriptionChanged(request, response, EventTimingType.AFTER_RESPONSE_RECEIVED, flInfo);

      if ( response.getErrorEncountered() ){
        throw new GUICommandException(response.getMessage());
      }
      mlSessionID = response.getSessionID();
      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      ex.printStackTrace(out);
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }
  

  private void printServerMessage(String s){
    //ScreenUpdater.getInstance().printMessage("# " + s);
    out.println("# " + s);
  }

  public boolean disconnect()
          throws SourceJammerConnectionException, GUICommandException{
    boolean bActionComplete = false;
    try {
      SJRequest request = getBaseRequest();
      msArchiveName = null;
      SJResponse response = moPortal.sendRequest(request, SOAPPortal.MCPMethodNames.DISCONNECT);
      printServerMessage(response.getMessage());
      msUserName = null;
      msPassword = null;
      moCurrentTreeNode = null;
      bActionComplete = true;
      out.println(DisplayTextLibrary.displayText(DisplayTextLibrary.LBL_DISCONNECTED));
    }
    catch (SourceJammerConnectionException ex){
      ex.printStackTrace(out);
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION));
    }
    catch (Exception ex){
      throw new GUICommandException(ex.getMessage(), ex);
    }
    return bActionComplete;
  }

  public void setDisconnectedDisplaySettings(){
    mjRootAppFrame.getProjectTree().setModel(null);
    mjRootAppFrame.getPrimaryTable().setModel(new javax.swing.table.DefaultTableModel());
    mjRootAppFrame.setTitle(APP_TITLE);

    ActionCentral oActions = ActionCentral.getInstance();
    oActions.enableAction(ActionCentral.act_CONNECT_LIST_ARCHIVES);
    oActions.disableAction(ActionCentral.act_CHANGE_PASSWORD);
    oActions.disableAction(ActionCentral.act_GET_COMPLETE_USER_LIST);
    oActions.disableAction(ActionCentral.act_VIEW_LABELED_VERSIONS);
    oActions.disableAction(ActionCentral.act_GET_LABELED_VERSION);
    oActions.disableAction(ActionCentral.act_DISCONNECT);
    oActions.disableAction(ActionCentral.act_LIST_ARCHIVES_ON_SERVER);
    oActions.disableAction(ActionCentral.act_LIST_ARCHIVES_ON_SERVER_DELETE);
    oActions.disableAction(ActionCentral.act_SHOW_ARCHIVE_PROPS);
    
    oActions.disableAction(ActionCentral.act_ADD_FILE);
    oActions.disableAction(ActionCentral.act_REFRESH_PROJECT);
    oActions.disableAction(ActionCentral.act_SET_DEFAULT_DIR);
    oActions.disableAction(ActionCentral.act_MAKE_PROJECT);
    oActions.disableAction(ActionCentral.act_REMOVE_PROJECT);
    oActions.disableAction(ActionCentral.act_VIEW_REMOVED);
    oActions.disableAction(ActionCentral.act_VIEW_RESTORE_REMOVED);
    oActions.disableAction(ActionCentral.act_VIEW_DELETE_REMOVED);
    oActions.disableAction(ActionCentral.act_GET_FILES_IN_PROJECT);
    oActions.disableAction(ActionCentral.act_MAKE_LABELED_VERSION);
    oActions.disableAction(ActionCentral.act_RENAME_PROJECT);
    oActions.disableAction(ActionCentral.act_MOVE_COPY_PROJECT);
    oActions.disableAction(ActionCentral.act_CHECK_OUT_RPT);

    oActions.disableAction(ActionCentral.act_MAINTAIN_ARCHIVE_USERS);
  }

  public void getFile(NodeInfo fileInfo, 
                      java.io.File flTargetDirectory, boolean setReadOnly,
                      RepeatingResponse repeating)
        throws SourceJammerConnectionException, GUICommandException, IOException{
    int iEOL = getClientDefaultEOLType();
    getFile(fileInfo, flTargetDirectory, iEOL, setReadOnly, repeating, null);
  }

  public long getFileLatestVersionID(long lFileID){
    long lReturn = -1;
    try{
      SJRequest request = getBaseRequest();
      request.putLong(REQUESTED_NODE_UNIQUE_ID, lFileID);
      SJResponse resID = moPortal.sendRequest(request, SOAPPortal.MCPMethodNames.GET_LATEST_VERSION_ID);
      lReturn = resID.longValue(NODE_UNIQUE_ID);
    }
    catch (Exception ex){
      lReturn = -1;
    }
    return lReturn;
  }

  public void getFile(NodeInfo fileInfo, java.io.File flTargetDirectory,
                      int eolType, boolean setReadOnly, RepeatingResponse repeating,
                      SJRequest request)
        throws SourceJammerConnectionException, GUICommandException, IOException{
    getFile(fileInfo, flTargetDirectory, eolType, true, setReadOnly, repeating, request);
  }

  private boolean doesLocalFileExist(java.io.File dir, String fileName){
    boolean exists = true;
    java.io.File fl = new java.io.File(dir, fileName);
    
    if (! fl.exists() ){
      exists = false;
    }
    return exists;
  }
  
  public void getChangeList(long labelID, int newerVer, int olderVer, 
                             java.io.File targetFile, int eolType)
          throws SourceJammerConnectionException, GUICommandException, IOException{
    try {
      java.io.File targetDir = targetFile.getParentFile();
      if (! targetDir.exists()){
        throw new GUICommandException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_DIR_NO_EXIST));
      }

      //Build request.
      SJRequest request = getBaseRequest();
      request.putLong(REQUESTED_NODE_UNIQUE_ID, labelID);
      request.putInt(VERSION_NUMBER, newerVer);
      request.putInt(SECONDARY_VERSION_NUMBER, olderVer);
      request.putInt(REQUESTED_EOL_TYPE, eolType);
      request.putInt(ZIP_BINARIES_LARGER_THAN, SourceJammerClient.getInstance().getZipIfLargerThan());
        
      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.GET_CHANGE_LIST);
      if ( response.getErrorEncountered() ){
        throw new GUICommandException(response.getMessage());
      }

      DownloadFileIdentifier downloadId = response.downloadFileIdentifierValue();
      long lTempFileId = retrieveFileFromServer(downloadId, response);
      
      java.io.File tempFile = TempDirectoryManager.getTempFileById(lTempFileId);
      
      FileSysUtil.streamFileToFile(tempFile, targetFile, false);
    }
    catch (SourceJammerConnectionException ex){
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }
  
  public void getFile(NodeInfo fileInfo, java.io.File flTargetDirectory,
                      int eolType, boolean printMessages, boolean setReadOnly, 
                      RepeatingResponse repeating, SJRequest request)
        throws SourceJammerConnectionException, GUICommandException, IOException{
    try {
      String sFileName = fileInfo.getNodeName();
      
      //If path passed in includes a file, assume this overrides file name.
      if (! flTargetDirectory.isDirectory() ){
        sFileName = flTargetDirectory.getName();
        flTargetDirectory = flTargetDirectory.getParentFile();
      }

      SourceVersionChecker checker = getChecker(flTargetDirectory);
      
      long lFileID = fileInfo.getUniqueID();
      boolean downloadFile = true;
      if (doesLocalFileExist(flTargetDirectory, sFileName)){            
        //If it exists, we need to see if we have latest version.
        long lLatestVerID = getFileLatestVersionID(lFileID);
        if (lLatestVerID == -1){
          throw new BadMethodArgumentException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CANT_GET_VER_ID));
        }
        downloadFile = (! checker.isFileCurrent(sFileName, lLatestVerID));
      }
      //Check on latest version on file system.
      if (downloadFile){
        if (request == null){
          request = getBaseRequest();
        }
        request.putLong(REQUESTED_NODE_UNIQUE_ID, lFileID);

        request.putInt(REQUESTED_EOL_TYPE, eolType);
        request.putInt(ZIP_BINARIES_LARGER_THAN, SourceJammerClient.getInstance().getZipIfLargerThan());

        SourceJammerClient.getInstance().getFileListeners()
                  .notifyFileGet(request, null, EventTimingType.BEFORE_REQUEST_SENT, fileInfo );
        
        SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.GET_FILE_LATEST_VERSION);

        SourceJammerClient.getInstance().getFileListeners()
                  .notifyFileGet(request, response, EventTimingType.AFTER_RESPONSE_RECEIVED, fileInfo);

        if ( response.getErrorEncountered() ){
          throw new GUICommandException(response.getMessage());
        }

        DownloadFileIdentifier downloadId = response.downloadFileIdentifierValue();
        long lTempFileId = retrieveFileFromServer(downloadId, response);
        
        long latestVerID = response.longValue(NODE_UNIQUE_ID);
        boolean bSaved = checker.saveFile(sFileName, latestVerID, lTempFileId, setReadOnly, repeating);
        if (printMessages){
          printServerMessage(response.getMessage());
          if (bSaved){
            out.print(DisplayTextLibrary.displayText(DisplayTextLibrary.LBL_SAVED_FILE));
            out.println(flTargetDirectory + java.io.File.separator + sFileName);
          }
          else{
            out.println(DisplayTextLibrary.displayText(DisplayTextLibrary.LBL_FILE_NOT_SAVED));
          }
        }
      }
      else {
        if (printMessages){
          out.println(DisplayTextLibrary.displayText(DisplayTextLibrary.LBL_LOCAL_IS_CURRENT) + "--" + sFileName );
        }
      }
    }
    catch (SourceJammerConnectionException ex){
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }


  public void checkOutFileToStream(long fileID, OutputStream stmOut, int eolType )
        throws SourceJammerConnectionException, GUICommandException, IOException {

    try {

      SJRequest request = getBaseRequest();

      request.putLong(REQUESTED_NODE_UNIQUE_ID, fileID);
      request.putString(CHECK_OUT_PATH, "unknown");
      request.putInt(REQUESTED_EOL_TYPE, eolType);
      request.putBoolean(EXCLUDE_FILE, false);
      request.putInt(ZIP_BINARIES_LARGER_THAN, SourceJammerClient.getInstance().getZipIfLargerThan());

      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.CHECK_OUT_FILE);
      if ( response.getErrorEncountered() ){
        throw new GUICommandException(response.getMessage());
      }
      DownloadFileIdentifier downloadId = response.downloadFileIdentifierValue();
      long lTempFileId = retrieveFileFromServer(downloadId, response);

      java.io.File flTemp = TempDirectoryManager.getTempFileById(lTempFileId);
      FileInputStream stmIn = new FileInputStream(flTemp);
      try{
        FileUtil.inputStreamToOutputStream(stmIn, stmOut);
      }
      finally{
        stmIn.close();
        flTemp.delete();
      }
    }
    catch (SourceJammerConnectionException ex){
      ex.printStackTrace(out);
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }


  public void getFileToStream(long lFileID, OutputStream stmOut,
                      int eolType)
        throws SourceJammerConnectionException, GUICommandException, IOException{
    try {

      long lLatestVerID = getFileLatestVersionID(lFileID);
      if (lLatestVerID == -1){
        throw new BadMethodArgumentException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CANT_GET_VER_ID));
      }

      SJRequest request = getBaseRequest();
      request.putLong(REQUESTED_NODE_UNIQUE_ID, lFileID);

      request.putInt(REQUESTED_EOL_TYPE, eolType);
      request.putInt(ZIP_BINARIES_LARGER_THAN, SourceJammerClient.getInstance().getZipIfLargerThan());
        
      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.GET_FILE_LATEST_VERSION);
      if ( response.getErrorEncountered() ){
        throw new GUICommandException(response.getMessage());
      }

      DownloadFileIdentifier downloadId = response.downloadFileIdentifierValue();
      long lTempFileId = retrieveFileFromServer(downloadId, response);

      java.io.File flTemp = TempDirectoryManager.getTempFileById(lTempFileId);
      FileInputStream stmIn = new FileInputStream(flTemp);
      try{
        FileUtil.inputStreamToOutputStream(stmIn, stmOut);
      }
      finally{
        stmIn.close();
        flTemp.delete();
      }
    }
    catch (SourceJammerConnectionException ex){
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }

  /**
   * Gets the default EOL type for the client from AppConfig.
   */
  public int getClientDefaultEOLType(){
    int iEOL = -1;
    String sEOL = new String(SourceJammerClient.getInstance().getDefaultEndOfLine());
    String sLF = new String(AppConfig.EndOfLines.LINE_FEED);
    if (sEOL.equals(sLF)){
      iEOL = AppConfig.EndOfLineType.LINE_FEED;
    }
    else {
      iEOL = AppConfig.EndOfLineType.CARRIAGE_RETURN_LINE_FEED;
    }
    return iEOL;
  }

  public void checkOutFile(long fileID, String fileName, java.io.File flTargetDirectory )
        throws SourceJammerConnectionException, GUICommandException, IOException {
    int iEOL = getClientDefaultEOLType();
    checkOutFile(fileID, fileName, flTargetDirectory, iEOL, null);
  }

  public boolean hasLocalFileChanged(String fileName, java.io.File flTargetDir)
          throws IOException{

    boolean hasChnaged = false;
    java.io.File testFile = new java.io.File(flTargetDir, fileName);
    if (testFile.exists()){
      SourceVersionChecker checker = getChecker(flTargetDir);
      hasChnaged = ! checker.isStoredFileInfoAccurate(fileName);
    }
    return hasChnaged;
  }

  public void checkOutFile(long fileID, String fileName, java.io.File flTargetDirectory,
                           int eolType, SJRequest request )
        throws SourceJammerConnectionException, GUICommandException, IOException {

    try {
      long lLatestVerID = getFileLatestVersionID(fileID);
      SourceVersionChecker checker = getChecker(flTargetDirectory);
      boolean bExclude = checker.isFileCurrent(fileName, lLatestVerID);

      if (request == null){
        request = getBaseRequest();
      }

      request.putLong(REQUESTED_NODE_UNIQUE_ID, fileID);
      request.putString(CHECK_OUT_PATH, flTargetDirectory.getAbsolutePath());
      request.putInt(REQUESTED_EOL_TYPE, eolType);
      request.putBoolean(EXCLUDE_FILE, bExclude);
      if (bExclude){
        out.println(DisplayTextLibrary.displayText(DisplayTextLibrary.LBL_LOCAL_IS_CURRENT) + ".");
      }
      else{
        request.putInt(ZIP_BINARIES_LARGER_THAN, SourceJammerClient.getInstance().getZipIfLargerThan());
      }

      FileNodeInfo flNodeInfo = (FileNodeInfo)getSelectedFileNodeInfo(fileName);
      SourceJammerClient.getInstance().getFileListeners()
              .notifyFileCheckedOut(request, null, EventTimingType.BEFORE_REQUEST_SENT, flNodeInfo);

      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.CHECK_OUT_FILE);

      SourceJammerClient.getInstance().getFileListeners()
              .notifyFileCheckedOut(request, null, EventTimingType.AFTER_RESPONSE_RECEIVED, flNodeInfo);

      if ( response.getErrorEncountered() ){
        throw new GUICommandException(response.getMessage());
      }
      printServerMessage(response.getMessage());
      if (! bExclude){
        DownloadFileIdentifier downloadId = response.downloadFileIdentifierValue();
        long lTempFileId = retrieveFileFromServer(downloadId, response);

        boolean bSaved = checker.saveFile(fileName, lLatestVerID, lTempFileId, false, null);
        if (bSaved){
          out.print(DisplayTextLibrary.displayText(DisplayTextLibrary.LBL_SAVED_FILE));
          out.println(flTargetDirectory + java.io.File.separator + fileName);
        }
        else{
          out.println(DisplayTextLibrary.displayText(DisplayTextLibrary.LBL_FILE_NOT_SAVED));
        }
      }
      else {
        makeFileWritable(new java.io.File(flTargetDirectory, fileName));
      }
    }
    catch (SourceJammerConnectionException ex){
      ex.printStackTrace(out);
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }

  /**
   * Force local version of file into archive without checking file out.
   */
  public void forceCheckIn(NodeInfo fileNode, java.io.File flTargetDirectory,
                            String comment, String afterCheckInAction, SJRequest request)
        throws SourceJammerConnectionException, GUICommandException, IOException{
    try {
      if (request == null){
        request = getBaseRequest();
      }
      
      long fileID = fileNode.getUniqueID();
      String fileName = fileNode.getNodeName();

      //Check out file, but don't download it.
      request.putLong(REQUESTED_NODE_UNIQUE_ID, fileID);
      request.putString(CHECK_OUT_PATH, flTargetDirectory.getAbsolutePath());
      request.putBoolean(EXCLUDE_FILE, true);

      FileNodeInfo flNodeInfo = (FileNodeInfo)getSelectedFileNodeInfo(fileName);
      //Notify force check in
      SourceJammerClient.getInstance().getFileListeners()
              .notifyFileForceCheckedIn(request, null, EventTimingType.BEFORE_REQUEST_SENT, flNodeInfo);

      //Notify check out.
      SourceJammerClient.getInstance().getFileListeners()
              .notifyFileCheckedOut(request, null, EventTimingType.BEFORE_REQUEST_SENT, flNodeInfo);

      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.CHECK_OUT_FILE);

      SourceJammerClient.getInstance().getFileListeners()
              .notifyFileCheckedOut(request, response, EventTimingType.AFTER_RESPONSE_RECEIVED, flNodeInfo);

      if ( response.getErrorEncountered() ){
        throw new GUICommandException(response.getMessage());
      }

      //Check local file in.
      //Notify check in.
      SourceJammerClient.getInstance().getFileListeners()
              .notifyFileCheckedIn(request, null, EventTimingType.BEFORE_REQUEST_SENT, flNodeInfo);
      
      checkInFile(fileNode, flTargetDirectory, comment, afterCheckInAction, null);

      SourceJammerClient.getInstance().getFileListeners()
              .notifyFileCheckedIn(request, response, EventTimingType.AFTER_RESPONSE_RECEIVED, flNodeInfo);

      SourceJammerClient.getInstance().getFileListeners()
              .notifyFileForceCheckedIn(request, response, EventTimingType.AFTER_RESPONSE_RECEIVED, flNodeInfo);
    }
    catch (SourceJammerConnectionException ex){
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }

  }


  /**
   * Checks in the file. If file is shared, tells server to branch it on
   * checkin.
   */
  public void branchAndCheckIn(NodeInfo fileNode, java.io.File flTargetDirectory,
                                String comment, String afterCheckInAction,
                                long parentProjectID, String identifier,
                                SJRequest request)
        throws SourceJammerConnectionException, GUICommandException, 
                IOException{
    if (request == null){
      request = getBaseRequest();
    }
    if (fileNode.isShared()){
      request.putBoolean(IS_BRANCH_AFTER_CHECKIN, true);
      request.putString(IDENTIFIER, identifier);
      request.putLong(PARENT_NODE_UNIQUE_ID, parentProjectID);
    }
    else{
      request.removeValue(IS_BRANCH_AFTER_CHECKIN);;
    }
    checkInFile(fileNode, flTargetDirectory, comment, afterCheckInAction, request);
  }

  public void checkInFile(NodeInfo fileNode, java.io.File flTargetDirectory,
                          String comment, String afterCheckInAction, SJRequest request)
        throws SourceJammerConnectionException, GUICommandException, IOException{

    try {
      String fileName = fileNode.getNodeName();
      long fileID = fileNode.getUniqueID();
      String localFileNameLocation = flTargetDirectory.getAbsolutePath() +
              java.io.File.separator + fileName;

      if (request == null){
        request = getBaseRequest();
      }

      request.putLong(REQUESTED_NODE_UNIQUE_ID, fileID);
      if (comment == null){
        comment = "";
      }
      request.putString(COMMENT, comment);

      java.io.File fl = new java.io.File(localFileNameLocation);
      long lFileUploadId = sendFileToServer(fl, request);

      request.putLong(FILE_UPLOAD_ID, lFileUploadId);
      
      SourceJammerClient.getInstance().getFileListeners()
               .notifyFileCheckedIn(request, null, EventTimingType.BEFORE_REQUEST_SENT, fileNode);

      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.CHECK_IN_FILE);

      SourceJammerClient.getInstance().getFileListeners()
                .notifyFileCheckedIn(request, null, EventTimingType.AFTER_RESPONSE_RECEIVED, fileNode);

      if (  response.getErrorEncountered() ){
        throw new GUICommandException(response.getMessage());
      }
      long lNewVerID = response.longValue(NODE_UNIQUE_ID);
      SourceVersionChecker checker = getChecker(flTargetDirectory);
      checker.updateLocalInfo(fileName, lNewVerID);
      java.io.File flFile = new java.io.File(localFileNameLocation);
      if (afterCheckInAction.equals(SourceJammerClient.lfa_SET_READ_ONLY)){
        flFile.setReadOnly();
      }
      else if (afterCheckInAction.equals(SourceJammerClient.lfa_DELETE)){
        flFile.delete();
      }
      else{
        //No action.
      }
      
      if (lNewVerID < 0){
        //Means file was modified by server on checkin.
        String confAction = SourceJammerClient.getInstance().getOnFileModifiedOnCheckin();
        if (confAction.equals(SourceJammerClient.lfa_GET_LATEST)){
          //Fire off a get on the file.
          //Check if we have a new file id.
          long newID = response.longValue(NEW_FILE_ID);
          if (newID > -1){
            fileNode = fileNode.cloneNodeInfo();
            fileNode.setUniqueID(newID);
          }
          getFile(fileNode, 
                  flTargetDirectory,
                  afterCheckInAction.equals(SourceJammerClient.lfa_SET_READ_ONLY),
                  null);
        }
      }
      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }

  public void undoCheckOut(long fileID, String sFileName, java.io.File flTargetDirectory,
                           SJRequest request)
          throws SourceJammerConnectionException, GUICommandException{
    try {
      if (request == null){
        request = getBaseRequest();
      }
      request.putLong(REQUESTED_NODE_UNIQUE_ID, fileID);

      FileNodeInfo flNodeInfo = (FileNodeInfo)getSelectedFileNodeInfo(sFileName);
      SourceJammerClient.getInstance().getFileListeners()
              .notifyFileCheckeOutUndone(request, null, EventTimingType.BEFORE_REQUEST_SENT, flNodeInfo);

      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.UNDO_CHECKOUT);

      SourceJammerClient.getInstance().getFileListeners()
              .notifyFileCheckeOutUndone(request, response, EventTimingType.AFTER_RESPONSE_RECEIVED, flNodeInfo);

      if (response.getErrorEncountered()){
        throw new GUICommandException (response.getMessage());
      }
      if (flTargetDirectory != null){
        java.io.File flFile = new java.io.File(flTargetDirectory, sFileName);
        if (flFile.exists()){
          flFile.setReadOnly();
        }
      }
      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }


  public String viewVersionComment(long versionID)
          throws SourceJammerConnectionException, GUICommandException{
    String comment = null;
    try {
      SJRequest request = getBaseRequest();
      request.putLong(REQUESTED_NODE_UNIQUE_ID, versionID);
      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.VIEW_VERSION_COMMENT);
      if (  response.getErrorEncountered() ){
        throw new GUICommandException(response.getMessage());
      }
      comment = response.getMessage();
      if (comment == null){
        comment = "";
      }
    }
    catch (SourceJammerConnectionException ex){
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
    return comment;
  }

  public void getFileVersion(NodeInfo flInfo, java.io.File flTargetDirectory,
            int iVersion, long versionID, boolean setReadOnly,
            RepeatingResponse repeating)
        throws SourceJammerConnectionException, GUICommandException, IOException{
    getFileVersion(flInfo, flTargetDirectory, iVersion, versionID, setReadOnly, true, repeating);
  }

  public void getFileVersion(NodeInfo flInfo, java.io.File flTargetDirectory,
            int iVersion, long versionID, boolean setReadOnly,
            RepeatingResponse repeating, SJRequest request)
        throws SourceJammerConnectionException, GUICommandException, IOException{
    getFileVersion(flInfo, flTargetDirectory, iVersion, versionID, getClientDefaultEOLType(), setReadOnly, true, repeating, request);
  }

  public void getFileVersion(NodeInfo flInfo, java.io.File flTargetDirectory,
            int iVersion, long versionID, boolean setReadOnly, boolean printMessages,
            RepeatingResponse repeating)
          throws SourceJammerConnectionException, GUICommandException, IOException{
    int iEOL = getClientDefaultEOLType();
    getFileVersion(flInfo, flTargetDirectory, iVersion, versionID, iEOL, setReadOnly, printMessages, repeating, null);
  }

  public void getFileVersion(NodeInfo flInfo, java.io.File flTargetDirectory,
            int iVersion, long versionID, int eolType, boolean setReadOnly,
            RepeatingResponse repeating, SJRequest request)
        throws SourceJammerConnectionException, GUICommandException, IOException{
    getFileVersion(flInfo, flTargetDirectory, iVersion, versionID, eolType, setReadOnly, true, repeating, request);
  }

  public void getFileVersion(NodeInfo flInfo, java.io.File flTargetDirectory,
            int iVersion, long versionID, int eolType, 
            boolean setReadOnly, boolean printMessages,
            RepeatingResponse repeating, SJRequest request)
        throws SourceJammerConnectionException, GUICommandException, IOException{
    try {
      getFileVersionFromServer(flInfo, iVersion, eolType, versionID, flTargetDirectory, setReadOnly, printMessages, repeating, request);
    }
    catch (SourceJammerConnectionException ex){
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }

  /**
   * Gets full source from server for a specified version, if required, and
   * saves the file.
   */
  private void getFileVersionFromServer(NodeInfo flInfo, int iVersion,
                    int eolType, long versionID, 
                    java.io.File targetDir, boolean setReadOnly, 
                    RepeatingResponse repeating, SJRequest request)
        throws GUICommandException, SourceJammerConnectionException, IOException{
    getFileVersionFromServer(flInfo, iVersion, eolType, versionID, targetDir, setReadOnly, true, repeating, request);
  }

  private void getFileVersionFromServer(NodeInfo flInfo, int iVersion,
                    int eolType, long versionID, java.io.File targetDir,
                    boolean setReadOnly, boolean printMessages, RepeatingResponse repeating,
                    SJRequest request)
        throws GUICommandException, SourceJammerConnectionException, IOException{
    String fileName = flInfo.getNodeName();
    //if target is a file, assume name overrides.
    if (! targetDir.isDirectory()){
      fileName = targetDir.getName();
      targetDir = targetDir.getParentFile();
    }
    SourceVersionChecker checker = getChecker(targetDir);
    if ( ! checker.isFileCurrent(fileName, versionID)){
      if (request == null){
        request = getBaseRequest();
      }
      long fileID = flInfo.getUniqueID();
      request.putLong(REQUESTED_NODE_UNIQUE_ID, fileID);
      request.putInt(VERSION_NUMBER, iVersion);
      request.putInt(REQUESTED_EOL_TYPE, eolType);
      request.putInt(ZIP_BINARIES_LARGER_THAN, SourceJammerClient.getInstance().getZipIfLargerThan());

      SourceJammerClient.getInstance().getFileListeners()
                .notifyFileVersionGet(request, null, EventTimingType.BEFORE_REQUEST_SENT, flInfo);

      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.GET_FILE_VERSION);

      SourceJammerClient.getInstance().getFileListeners()
                .notifyFileVersionGet(request, null, EventTimingType.AFTER_RESPONSE_RECEIVED, flInfo);

      if ( response.getErrorEncountered() ){
        throw new GUICommandException(response.getMessage());
      }
      DownloadFileIdentifier downloadId = response.downloadFileIdentifierValue();
      long lTempFileId = retrieveFileFromServer(downloadId, response);

      boolean bSaved = checker.saveFile(fileName, versionID, lTempFileId, setReadOnly, repeating);
      if (printMessages){
        printServerMessage(response.getMessage());
        if (bSaved){
          out.print(DisplayTextLibrary.displayText(DisplayTextLibrary.LBL_SAVED_FILE));
          out.println(targetDir + java.io.File.separator + fileName);
        }
        else{
          out.println(DisplayTextLibrary.displayText(DisplayTextLibrary.LBL_FILE_NOT_SAVED));
        }
      }
    }
    else {
      if (printMessages){
        out.println(DisplayTextLibrary.displayText(DisplayTextLibrary.LBL_LOCAL_IS_CURRENT) + "--" + fileName );
      }
    }
  }

  public boolean doesProjectContainShares(long projectID)
          throws SourceJammerConnectionException, GUICommandException{
    try {
      SJRequest request = getBaseRequest();
      request.putLong(REQUESTED_NODE_UNIQUE_ID, projectID);
      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.PROJECT_CONTAINS_SHARES);
      if ( response.getErrorEncountered() ){
        throw new GUICommandException(response.getMessage());
      }
      return response.booleanValue(BOOLEAN_QUERY_RESULT);
    }
    catch (SourceJammerConnectionException ex){
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }

  public boolean checkDeletedNodeShareStatus(long projectID, int itemIndex)
          throws SourceJammerConnectionException, GUICommandException{
    boolean containsShares = false;
    try {
      SJRequest request = getBaseRequest();
      request.putLong(REQUESTED_NODE_UNIQUE_ID, projectID);
      request.putInt(VERSION_NUMBER, itemIndex);
      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.CHECK_DELETED_NODE_SHARE_STATUS);
      if ( response.getErrorEncountered() ){
        throw new GUICommandException(response.getMessage());
      }
      if (response.booleanValue(IS_CHECKED_OUT)){
        //The node is a shared file that's checked out or a project that
        //contains a shared file that's checked out. Either way, it can't be
        //deleted, so we'll error out here.
        throw new GUICommandException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CANT_DELETE_CHECKED_OUT));
      }
      containsShares = response.booleanValue(IS_SHARED);
    }
    catch (SourceJammerConnectionException ex){
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
    return containsShares;
  }

  public void removeProjectAndAllShares(long projectID)
          throws SourceJammerConnectionException, GUICommandException{
    try {
      SJRequest request = getBaseRequest();
      request.putLong(REQUESTED_NODE_UNIQUE_ID, projectID);
      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.REMOVE_PROJECT);
      if ( response.getErrorEncountered() ){
        throw new GUICommandException(response.getMessage());
      }
      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }


  public void removeProjectFromParent(long projectID, long parentID)
          throws SourceJammerConnectionException, GUICommandException{
    try {
      SJRequest request = getBaseRequest();
      request.putLong(PARENT_NODE_UNIQUE_ID, parentID);
      request.putLong(REQUESTED_NODE_UNIQUE_ID, projectID);
      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.REMOVE_PROJECT);
      if ( response.getErrorEncountered() ){
        throw new GUICommandException(response.getMessage());
      }
      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }


  public void removeAllSharesOfFile(NodeInfo flInfo, SJRequest request)
          throws SourceJammerConnectionException, GUICommandException{
    try {
      if (request == null){
        request = getBaseRequest();
      }
      request.putLong(REQUESTED_NODE_UNIQUE_ID, flInfo.getUniqueID());

      SourceJammerClient.getInstance().getFileListeners()
              .notifyFileRemoved(request, "removeAllSharesOfFile", EventTimingType.BEFORE_REQUEST_SENT, flInfo);
      
      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.REMOVE_FILE);

      SourceJammerClient.getInstance().getFileListeners()
              .notifyFileRemoved(request, response, EventTimingType.AFTER_RESPONSE_RECEIVED, flInfo);

      if ( response.getErrorEncountered() ){
        throw new GUICommandException(response.getMessage());
      }
      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }
            
  public void removeFileFromParent(NodeInfo flInfo, long parentID, SJRequest request)
          throws SourceJammerConnectionException, GUICommandException{
    try {
      if (request == null){
        request = getBaseRequest();
      }
      request.putLong(PARENT_NODE_UNIQUE_ID, parentID);
      request.putLong(REQUESTED_NODE_UNIQUE_ID, flInfo.getUniqueID());

      SourceJammerClient.getInstance().getFileListeners()
              .notifyFileRemoved(request, SOAPPortal.MCPMethodNames.REMOVE_FILE, EventTimingType.BEFORE_REQUEST_SENT, flInfo);

      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.REMOVE_FILE);

      SourceJammerClient.getInstance().getFileListeners()
              .notifyFileRemoved(request, response, EventTimingType.AFTER_RESPONSE_RECEIVED, flInfo);

      if ( response.getErrorEncountered() ){
        throw new GUICommandException(response.getMessage());
      }
      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }

 public RemovedItem[] viewRemoved(long projectID)
        throws SourceJammerConnectionException, GUICommandException{
    RemovedItem[] oaRemoved = null;
    try {
      SJRequest request = getBaseRequest();
      request.putLong(REQUESTED_NODE_UNIQUE_ID, projectID);
      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.VIEW_REMOVED_NODES);
      if ( response.getErrorEncountered() ){
        throw new GUICommandException(response.getMessage());
      }
      Object[] nodes = (Object[])response.objectValue(OBJECT_ARRAY);
      oaRemoved = new RemovedItem[nodes.length];
      for (int iCounter = 0; iCounter < nodes.length; iCounter++){
        NodeInfo ndRem = (NodeInfo)nodes[iCounter];
        oaRemoved[iCounter] = new RemovedItem();
        oaRemoved[iCounter].setNumber(iCounter);
        oaRemoved[iCounter].setName(ndRem.getNodeName());
        oaRemoved[iCounter].setNodeType(ndRem.getNodeType());
      }
    }
    catch (SourceJammerConnectionException ex){
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
    return oaRemoved;
  }

  public void restoreRemoved(long parentID, int iItemNumber, String newName){
    try {
      SJRequest request = getBaseRequest();
      request.putLong(REQUESTED_NODE_UNIQUE_ID, parentID);
      request.putInt(VERSION_NUMBER, iItemNumber);
      if (newName != null){
        request.putString(REQUESTED_NODE_NAME, newName);
      }
      SJResponse response = moPortal.sendRequest(request, SOAPPortal.MCPMethodNames.RESTORE_REMOVED_NODE);
      if ( response.getErrorEncountered() ){
        throw new Exception(response.getMessage());
      }
      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      MessageBoxUtil.displayErrorMessage(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION));
    }
    catch (Exception ex){
      MessageBoxUtil.displayErrorMessage(ex.getMessage());
    }
  }

  public void deleteRemoved(long lParentID, int iItemNumber)
          throws SourceJammerConnectionException, GUICommandException{
    deleteRemoved(lParentID, iItemNumber, false);
  }

  public void deleteRemoved(long lParentID, int iItemNumber, boolean deleteAllShares)
          throws SourceJammerConnectionException, GUICommandException{
    try {
      SJRequest request = getBaseRequest();
      request.putLong(REQUESTED_NODE_UNIQUE_ID, lParentID);
      request.putInt(VERSION_NUMBER, iItemNumber);
      request.putBoolean(RECURSIVE, deleteAllShares);
      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.PERMANENTLY_DELETE_NODE);
      if ( response.getErrorEncountered() ){
        throw new GUICommandException(response.getMessage());
      }
      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      ex.printStackTrace(out);
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }

  public void makeUser(String sUserName, String sPassword, String sFullName)
          throws GUICommandException, SourceJammerConnectionException{
    try {
      SJRequest request = getBaseRequest();
      request.putString(NEW_USER_NAME, sUserName);
      request.putString(NEW_USER_PASSWORD, sPassword);
      request.putString(NEW_USER_FULL_NAME, sFullName);
      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.ADD_USER);
      if ( response.getErrorEncountered() ){
        throw new GUICommandException(response.getMessage());
      }
      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      ex.printStackTrace();
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }

  public void removeUser(String sUserName)
          throws GUICommandException, SourceJammerConnectionException{
    try {
      SJRequest request = getBaseRequest();
      request.putString(NEW_USER_NAME, sUserName);
      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.REMOVE_USER);
      if ( response.getErrorEncountered() ){
        throw new GUICommandException(response.getMessage());
      }
      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      ex.printStackTrace();
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }

  public void changePassword(String sPassword)
        throws SourceJammerConnectionException, GUICommandException{
    try {
      SJRequest request = getBaseRequest();
      request.putString(NEW_USER_PASSWORD, sPassword);
      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.CHANGE_PASSWORD);
      if ( response.getErrorEncountered() ){
        throw new GUICommandException(response.getMessage());
      }
      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }

  public void changePassword(String sPassword, String userName)
        throws SourceJammerConnectionException, GUICommandException{
    try {
      SJRequest request = getBaseRequest();
      request.putString(NEW_USER_PASSWORD, sPassword);
      request.putString(NEW_USER_NAME, userName);
      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.CHANGE_PASSWORD);
      if ( response.getErrorEncountered() ){
        throw new GUICommandException(response.getMessage());
      }
      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }

  public void makeArchive(String name, int implementation, String path)
          throws SourceJammerConnectionException, GUICommandException{
    try {
      SJRequest request = getBaseRequest();
      Integer intImplementation = null;
      if (implementation > -1){
       intImplementation = new Integer(implementation);
      }
      request.putString(NEW_ARCHIVE_NAME, name);
      if (intImplementation != null){
        request.putInt(NEW_ARCHIVE_IMPLEMENTATION, intImplementation.intValue());
      }
      if (path != null){
        request.putString(NEW_ARCHIVE_ROOT_PATH, path);
      }
      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.ADD_ARCHIVE);
      if ( response.getErrorEncountered() ){
        throw new GUICommandException(response.getMessage());
      }
      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }

  public void makeArchiveDisconnected(String userName, String password,
                                    String url, String name, int implementation,
                                    String path)
        throws SourceJammerConnectionException, GUICommandException, MalformedURLException,
               NoSessionException{
    try {
      SJRequest request = getBaseRequest();
      request.setUserName(userName);
      request.setPassword(password);
      SOAPPortal oLocalPortal = new SOAPPortal();
      oLocalPortal.setURL(url);
      SJResponse loginResponse = oLocalPortal.sendRequest(request, SOAPPortal.MCPMethodNames.LOG_IN);
      SJResponse response = null;
      if(! loginResponse.getErrorEncountered()){
        request.setSessionID(loginResponse.getSessionID());
        Integer intImplementation = null;
        if (implementation > -1){
         intImplementation = new Integer(implementation);
        }
        request.putString(NEW_ARCHIVE_NAME, name);
        if (intImplementation != null){
          request.putInt(NEW_ARCHIVE_IMPLEMENTATION, intImplementation.intValue());
        }
        if (path != null){
          request.putString(NEW_ARCHIVE_ROOT_PATH, path);
        }
        response = oLocalPortal.sendRequest(request, SOAPPortal.MCPMethodNames.ADD_ARCHIVE);
        oLocalPortal.sendRequest(request, SOAPPortal.MCPMethodNames.DISCONNECT);
      }
      else {
        response = loginResponse;
      }
      if ( response.getErrorEncountered() ){
        throw new GUICommandException(response.getMessage());
      }
      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }

  public NodeList getLabelList()
          throws SourceJammerConnectionException, GUICommandException,
                 org.sourcejammer.project.NodeExistsException{
    NodeList oReturn = null;
    try {
      SJRequest request = getBaseRequest();
      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.LABEL_LIST);
      if ( response.getErrorEncountered() ){
        throw new GUICommandException(response.getMessage());
      }
      Object[] obj = (Object[])response.objectValue(OBJECT_ARRAY);
      oReturn = new NodeList();
      if (obj != null){
        for (int i = 0; i < obj.length; i++){
          oReturn.addNode((Node)obj[i]);
        }
      }
    }
    catch (SourceJammerConnectionException ex){
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
    return oReturn;
  }


  public void makeLabel(long labelRootProjectID, String labelName, String description)
          throws SourceJammerConnectionException, GUICommandException{
    try {
      SJRequest request = getBaseRequest();
      request.putLong(REQUESTED_NODE_UNIQUE_ID, labelRootProjectID);
      request.putString(REQUESTED_NODE_NAME, labelName);
      request.putString(COMMENT, description);
      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.MAKE_LABEL);
      if (response.getErrorEncountered()){
        throw new GUICommandException(response.getMessage());
      }
      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }

  public void moveFile(NodeInfo flInfo, long fromProjectID, long toProjectID, SJRequest request)
          throws SourceJammerConnectionException, GUICommandException{
    try {
      if (request ==  null){
        request = getBaseRequest();
      }
      request.putLong(REQUESTED_NODE_UNIQUE_ID, flInfo.getUniqueID());
      request.putLong(PARENT_NODE_UNIQUE_ID, fromProjectID);
      request.putLong(NEW_PARENT_NODE_UNIQUE_ID, toProjectID);

      SourceJammerClient.getInstance().getFileListeners()
                .notifyFileMoveCopy(request, "move", EventTimingType.BEFORE_REQUEST_SENT, flInfo);

      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.MOVE_FILE);

      SourceJammerClient.getInstance().getFileListeners()
                .notifyFileMoveCopy(request, response, EventTimingType.AFTER_RESPONSE_RECEIVED, flInfo);

      if (response.getErrorEncountered()){
        throw new GUICommandException(response.getMessage());
      }
      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }

  public void shareFile(NodeInfo flInfo, long toProjectID, SJRequest request)
          throws SourceJammerConnectionException, GUICommandException{
    try {
      if (request == null){
        request = getBaseRequest();
      }
      request.putLong(REQUESTED_NODE_UNIQUE_ID, flInfo.getUniqueID());
      request.putLong(NEW_PARENT_NODE_UNIQUE_ID, toProjectID);

      SourceJammerClient.getInstance().getFileListeners()
              .notifyFileShared(request, null, EventTimingType.BEFORE_REQUEST_SENT, flInfo );

      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.SHARE_FILE);

      SourceJammerClient.getInstance().getFileListeners()
              .notifyFileShared(request, response, EventTimingType.AFTER_RESPONSE_RECEIVED, flInfo );

      if (response.getErrorEncountered()){
        throw new GUICommandException(response.getMessage());
      }
      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }

  public void shareProject(long projectID, long toProjectID, String newProjectName)
          throws SourceJammerConnectionException, GUICommandException{
    try {
      SJRequest request = getBaseRequest();
      request.putLong(REQUESTED_NODE_UNIQUE_ID, projectID);
      request.putLong(NEW_PARENT_NODE_UNIQUE_ID, toProjectID);
      request.putString(REQUESTED_NODE_NAME, newProjectName);

      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.SHARE_PROJECT);
      if (response.getErrorEncountered()){
        throw new GUICommandException(response.getMessage());
      }
      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }

  public void removeFileShare(NodeInfo flInfo, long fromProjectID, SJRequest request)
          throws SourceJammerConnectionException, GUICommandException{
    try {
      if (request == null){
        request = getBaseRequest();
      }
      request.putLong(REQUESTED_NODE_UNIQUE_ID, flInfo.getUniqueID());
      request.putLong(PARENT_NODE_UNIQUE_ID, fromProjectID);

      SourceJammerClient.getInstance().getFileListeners()
              .notifyFileShareRemoved(request, null, EventTimingType.BEFORE_REQUEST_SENT, flInfo);

      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.REMOVE_FILE_SHARE);

      SourceJammerClient.getInstance().getFileListeners()
              .notifyFileShareRemoved(request, response, EventTimingType.AFTER_RESPONSE_RECEIVED, flInfo);

      if (response.getErrorEncountered()){
        throw new GUICommandException(response.getMessage());
      }
      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }

  public void removeProjectShare(long projectID)
          throws SourceJammerConnectionException, GUICommandException{
    try {
      SJRequest request = getBaseRequest();
      request.putLong(REQUESTED_NODE_UNIQUE_ID, projectID);

      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.REMOVE_PROJECT_SHARE);
      if (response.getErrorEncountered()){
        throw new GUICommandException(response.getMessage());
      }
      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }

  public void branchFile(NodeInfo flInfo, long parentProjectID, String comment, String identifier, SJRequest request)
          throws SourceJammerConnectionException, GUICommandException{
    try {
      if (request == null){
        request = getBaseRequest();
      }
      request.putLong(REQUESTED_NODE_UNIQUE_ID, flInfo.getUniqueID());
      request.putLong(PARENT_NODE_UNIQUE_ID, parentProjectID);
      request.putString(COMMENT, comment);
      request.putString(IDENTIFIER, identifier);

      SourceJammerClient.getInstance().getFileListeners()
                .notifyFileBranched(request, null, EventTimingType.BEFORE_REQUEST_SENT, flInfo );

      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.BRANCH_FILE);

      SourceJammerClient.getInstance().getFileListeners()
                .notifyFileBranched(request, null, EventTimingType.AFTER_RESPONSE_RECEIVED, flInfo );

      if (response.getErrorEncountered()){
        throw new GUICommandException(response.getMessage());
      }
      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }

  public void branchProject(long projectID, String comment, String identifier)
          throws SourceJammerConnectionException, GUICommandException{
    try {
      SJRequest request = getBaseRequest();
      request.putLong(REQUESTED_NODE_UNIQUE_ID, projectID);
      request.putString(COMMENT, comment);
      request.putString(IDENTIFIER, identifier);

      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.BRANCH_PROJECT);
      if (response.getErrorEncountered()){
        throw new GUICommandException(response.getMessage());
      }
      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }



  public void copyFile(NodeInfo flInfo, long fromProjectID, long toProjectID, SJRequest request)
          throws SourceJammerConnectionException, GUICommandException{
    try {
      if (request == null){
        request = getBaseRequest(); 
      }
      request.putLong(REQUESTED_NODE_UNIQUE_ID, flInfo.getUniqueID());
      request.putLong(PARENT_NODE_UNIQUE_ID, fromProjectID);
      request.putLong(NEW_PARENT_NODE_UNIQUE_ID, toProjectID);

      SourceJammerClient.getInstance().getFileListeners()
                .notifyFileMoveCopy(request, "copy", EventTimingType.BEFORE_REQUEST_SENT, flInfo);

      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.COPY_FILE);

      SourceJammerClient.getInstance().getFileListeners()
                .notifyFileMoveCopy(request, response, EventTimingType.AFTER_RESPONSE_RECEIVED, flInfo);

      if (response.getErrorEncountered()){
        throw new GUICommandException(response.getMessage());
      }
      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }


  public void copyProject(long projectID, long toProjectID, String newProjectName)
          throws SourceJammerConnectionException, GUICommandException{
    try {
      SJRequest request = getBaseRequest();
      request.putLong(REQUESTED_NODE_UNIQUE_ID, projectID);
      request.putLong(NEW_PARENT_NODE_UNIQUE_ID, toProjectID);
      request.putString(REQUESTED_NODE_NAME, newProjectName);

      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.COPY_PROJECT);
      if (response.getErrorEncountered()){
        throw new GUICommandException(response.getMessage());
      }
      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }


  public void moveProject(long projectID, long toProjectID, String newProjectName)
          throws SourceJammerConnectionException, GUICommandException{
    try {
      SJRequest request = getBaseRequest();
      request.putLong(REQUESTED_NODE_UNIQUE_ID, projectID);
      request.putLong(NEW_PARENT_NODE_UNIQUE_ID, toProjectID);
      request.putString(REQUESTED_NODE_NAME, newProjectName);

      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.MOVE_PROJECT);
      if (response.getErrorEncountered()){
        throw new GUICommandException(response.getMessage());
      }
      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }


  /**
   * Gets all of the file version in the specified label from the server and
   * writes them to the specified directory (building subdirectories if required and
   * allowed).
   */
  /*
  public void getLabel(String labelName, java.io.File flToDirectory, boolean bBuildSubDirs)
        throws SourceJammerConnectionException, GUICommandException, IOException {
    int iEOL = getClientDefaultEOLType();
    getLabel(labelName, flToDirectory, bBuildSubDirs, iEOL);
  }
  */

  /**
   * Rebuild the specified label.
   */
  public void rebuildLabel(long labelId, long parentProjectID, String comment, boolean buildChangeList)
          throws SourceJammerConnectionException, GUICommandException, IOException{
    try{
      SJRequest request = getBaseRequest();
      request.putLong(REQUESTED_NODE_UNIQUE_ID, labelId);
      request.putString(COMMENT, comment);
      request.putLong(PARENT_NODE_UNIQUE_ID, parentProjectID);
      request.putBoolean(IS_BUILD_CHANGELIST, buildChangeList);
      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.REBUILD_LABEL);
      if (response.getErrorEncountered()){
        throw new GUICommandException(response.getMessage());
      }
      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }

  /**
   * Gets all of the file version in the specified label from the server and
   * writes them to the specified directory (building subdirectories if required and
   * allowed).
   */
  public void getLabel(long labelID, int verNumber, java.io.File flToDirectory, boolean bBuildSubDirs,
                       int eolType, boolean setReadOnly, RepeatingResponse repeating)
        throws SourceJammerConnectionException, GUICommandException, IOException {
    try {
      SJRequest request = getBaseRequest();
      request.putLong(REQUESTED_NODE_UNIQUE_ID, labelID);
      request.putInt(VERSION_NUMBER, verNumber);
      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.GET_LABEL);

      //Now we need to get all the files in the label.
      if (response.getErrorEncountered()){
        throw new GUICommandException(response.getMessage());
      }
      long lRootProjectID = response.longValue(NODE_UNIQUE_ID);

      String sBasePath = "";

      Object[] versionMappings = (Object[])response.objectValue(OBJECT_ARRAY);
      for (int i = 0; i < versionMappings.length; i++){
        LabelVersionMappingBean bnVersion = (LabelVersionMappingBean)versionMappings[i];
        //The path below is actually relative to the root project.
        String sSJPath = bnVersion.getFullPathToFile();
        long lFileID = bnVersion.getFileUniqueID();
        int iVersion = bnVersion.getVersionNumber();
        long lVersionID = bnVersion.getVersionUniqueID();

        int iLastSwitch = sSJPath.lastIndexOf(AppConfig.getInstance().getSourceJammerSwitch());
        String sParent = sSJPath.substring(0, iLastSwitch);
        String sFileName = sSJPath.substring(iLastSwitch + 1);

        java.io.File flTargetDir = new java.io.File(flToDirectory, sParent);
        if (! flTargetDir.exists() && bBuildSubDirs){
          flTargetDir.mkdirs();
          out.println(DisplayTextLibrary.displayText(DisplayTextLibrary.LBL_MAKING_DIR) + flTargetDir.getAbsolutePath());
        }
        if (flTargetDir.exists() &&
            flTargetDir.isDirectory()){
          NodeInfo nd = new NodeInfo();
          nd.setUniqueID(lFileID);
          nd.setNodeName(sFileName);
          getFileVersionFromServer(nd, iVersion, eolType, lVersionID, flTargetDir, setReadOnly, repeating, null);
        }
        else{
          out.println(DisplayTextLibrary.displayText(DisplayTextLibrary.LBL_DIR_NOT_EXIST) + flTargetDir.getAbsoluteFile());
          out.println(DisplayTextLibrary.displayText(DisplayTextLibrary.LBL_SKIPPING_PROJ) + sParent);
        }

      }//end for
    }
    catch (SourceJammerConnectionException ex){
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }

  public UserInfo[] getCompleteUserList()
        throws SourceJammerConnectionException, GUICommandException{

    UserInfo[] users = getUsers(SOAPPortal.MCPMethodNames.GET_COMPLETE_USER_LIST);
    return users;
  }

  public ArchiveProperties getArchiveProperties()
          throws GUICommandException, SourceJammerConnectionException{
    ArchiveProperties props = null;
    try{
      SJRequest request = getBaseRequest();
      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.GET_ARCHIVE_PROPS);
      if (response.getErrorEncountered()){
        throw new GUICommandException(response.getMessage());
      }
      props = response.archivePropertiesValue();
    }
    catch (SourceJammerConnectionException ex){
      ex.printStackTrace();
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
    return props;
  }

  public void setArchiveProperties(ArchiveProperties props)
          throws GUICommandException, SourceJammerConnectionException{
    try{
      SJRequest request = getBaseRequest();
      request.putObject(ARCHIVE_PROPERTIES, props);
      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.SET_ARCHIVE_PROPS);
      if (response.getErrorEncountered()){
        throw new GUICommandException(response.getMessage());
      }
      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      ex.printStackTrace();
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }

  public UserInfo[] getArchiveControllerList()
        throws SourceJammerConnectionException, GUICommandException{

    UserInfo[] users = getUsers(SOAPPortal.MCPMethodNames.GET_CONTROLLER_USER_LIST);
    return users;
  }

  public UserInfo[] getArchiveUserList()
        throws SourceJammerConnectionException, GUICommandException{

    UserInfo[] users = getUsers(SOAPPortal.MCPMethodNames.GET_ARCHIVE_USER_LIST);
    return users;
  }

  private UserInfo[] getUsers(String type)
        throws SourceJammerConnectionException, GUICommandException{

    UserInfo[] users = null;
    try{
      SJRequest request = getBaseRequest();
      SJResponse response = sendRequest(request, type);
      if (response.getErrorEncountered()){
        throw new GUICommandException(response.getMessage());
      }
      Object[] o = (Object[])response.objectValue(OBJECT_ARRAY);
      users = new UserInfo[o.length];
      for (int i = 0; i < o.length; i++){
        users[i] = (UserInfo)o[i];
      }
    }
    catch (SourceJammerConnectionException ex){
      ex.printStackTrace();
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
    return users;
  }




  public String getCurrentUserName(){
    return msUserName;
  }

  public void setUserAdminStatus(String userName, boolean status)
        throws SourceJammerConnectionException, GUICommandException{
    try{
      SJRequest request = getBaseRequest();
      request.putString(NEW_USER_NAME, userName);
      request.putBoolean(NEW_USER_ADMIN, status);
      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.SET_USER_ADMIN_STATUS);
      if (response.getErrorEncountered()){
        throw new GUICommandException(response.getMessage());
      }
      printServerMessage(response.getMessage()
      );
    }
    catch (SourceJammerConnectionException ex){
      ex.printStackTrace();
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }


  public void addUserToArchiveControllers(String userName)
        throws SourceJammerConnectionException, GUICommandException{
    try{
      SJRequest request = getBaseRequest();
      request.putString(NEW_USER_NAME, userName);
      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.ADD_USER_TO_ARCHIVE_CONTROLLERS);
      if (response.getErrorEncountered()){
        throw new GUICommandException(response.getMessage());
      }
      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      ex.printStackTrace();
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }

  public void addUserToArchiveUsers(String userName)
        throws SourceJammerConnectionException, GUICommandException{
    try{
      SJRequest request = getBaseRequest();
      request.putString(NEW_USER_NAME, userName);
      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.ADD_USER_TO_ARCHIVE_USERS);
      if (response.getErrorEncountered()){
        throw new GUICommandException(response.getMessage());
      }
      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      ex.printStackTrace();
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }

  public void removeUserFromArchiveControllers(String userName)
        throws SourceJammerConnectionException, GUICommandException{
    try{
      SJRequest request = getBaseRequest();
      request.putString(NEW_USER_NAME, userName);
      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.REMOVE_USER_FROM_ARCHIVE_CONTROLLERS);
      if (response.getErrorEncountered()){
        throw new GUICommandException(response.getMessage());
      }
      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      ex.printStackTrace();
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }

  public void removeUserFromArchiveUsers(String userName)
        throws SourceJammerConnectionException, GUICommandException{
    try{
      SJRequest request = getBaseRequest();
      request.putString(NEW_USER_NAME, userName);
      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.REMOVE_USER_FROM_ARCHIVE_USERS);
      if (response.getErrorEncountered()){
        throw new GUICommandException(response.getMessage());
      }
      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      ex.printStackTrace();
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }



  /**
   * Rolls back a file in the SourceJammer server to the specified previous
   * version of the file.
   */
  public  void rollbackToVersion(NodeInfo flInfo, long versionID, SJRequest request )
          throws SourceJammerConnectionException, GUICommandException{
    try {
      if (request == null){
        request = getBaseRequest(); 
      }
      request.putLong(REQUESTED_NODE_UNIQUE_ID, versionID);
      request.putLong(PARENT_NODE_UNIQUE_ID, flInfo.getUniqueID());

      SourceJammerClient.getInstance().getFileListeners()
              .notifyFileRolledBack(request, null, EventTimingType.BEFORE_REQUEST_SENT, flInfo);

      SJResponse response = sendRequest(request, SOAPPortal.MCPMethodNames.ROLLBACK_TO_VERSION);

      SourceJammerClient.getInstance().getFileListeners()
              .notifyFileRolledBack(request, response, EventTimingType.AFTER_RESPONSE_RECEIVED, flInfo);

      if (response.getErrorEncountered()){
        throw new GUICommandException(response.getMessage());
      }
      printServerMessage(response.getMessage());
    }
    catch (SourceJammerConnectionException ex){
      ex.printStackTrace();
      throw new SourceJammerConnectionException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_CONNECTION), ex);
    }
  }


  public boolean isConnected(){
    boolean bReturn = false;
    if (msArchiveName != null){
      bReturn = true;
    }
    else {
      bReturn = false;
    }
    return bReturn;
  }

  public SJRequest getBaseRequest(){
    SJRequest request = new SJRequest();
    request.setArchiveName(msArchiveName);
    request.setUserName(msUserName);
    request.setPassword(msPassword);

    if (mlSessionID != -1){
      request.setSessionID(mlSessionID);
    }
    return request;
  }


  private byte[] readLocalFile(String sFullPathAndName)
        throws IOException {

    return FileSysUtil.readLocalFile(sFullPathAndName);

  }

  private void makeFileWritable(java.io.File file) throws IOException{
    FileSysUtil.makeFileWritable(file);
  }

  public SJPrimaryWindow getRootAppFrame(){
    return mjRootAppFrame;
  }


  public JTree getProjectTree(){
    return mjRootAppFrame.getProjectTree();
  }

  public JTable getPrimaryTable(){
    return mjRootAppFrame.getPrimaryTable();
  }

  /**
   * Select the specified project in the project tree.
   */
  public void selectProject(ProjectTreeNode nd){
    TreePath path = new TreePath(nd.getPath());
    //mjFileExplorer.fireTreeExpanded(path);
    JTree jProjectTree = mjRootAppFrame.getProjectTree();
    jProjectTree.expandPath(path);
    int iRow = jProjectTree.getRowForPath(path);
    jProjectTree.setSelectionRow(iRow);
  }

  /**
   * Checks if a byte array about to be sent is larger than the minimum
   * unzipped file size. If so, zips the file and sets the flag in the SJRequest.
   */
  protected byte[] zipByteArrayIfNeeded(byte[] file, SJRequest request, String fileName)
          throws IOException{
    byte[] byReturn = null;
    int iSize = file.length;
    int iMinZipSize = SourceJammerClient.getInstance().getZipIfLargerThan();
    if (iSize > iMinZipSize && ZipUtil.canZip(fileName)){
      byReturn = ZipUtil.zipByteArray(file);
      request.putBoolean(BINARY_ZIPPED, true);
    }//end if needs to be zipped.
    else {
      byReturn = file;
    }
    return byReturn;
  }

  public SourceVersionChecker getChecker(java.io.File flDirectory)
        throws IOException{
    return new SourceVersionChecker(flDirectory, msURL, msArchiveName);
  }

  /**
   * Returns temp file id.
   */
  protected long retrieveFileFromServer(DownloadFileIdentifier id, SJResponse response)
          throws IOException, SourceJammerConnectionException{
    long lTempId = TempDirectoryManager.getNextID();
    java.io.File flTemp = TempDirectoryManager.getNewTempFile(lTempId);
    if (id.getFileSize() < (SourceJammerClient.getInstance().getMaxFileSendChunkSize())){
      FileTransport.downloadFullFileFromServer(id, flTemp, msURL);
    }
    else{
      FileTransport.downloadFileFromServer(id, flTemp, msURL);
    }

    //Unzip if needed.
    if (response.booleanValue(res_BINARY_ZIPPED)){
      long lUnzipId = TempDirectoryManager.getNextID();
      java.io.File flUnzip = TempDirectoryManager.getNewTempFile(lUnzipId);
      ZipUtil.unzipFileToFile(flTemp, flUnzip);
      TempDirectoryManager.deleteTempFile(lTempId);
      lTempId = lUnzipId;
      flTemp = flUnzip;
    }
    return lTempId;
  }

  protected long sendFileToServer(java.io.File fl, SJRequest request)
          throws IOException, SourceJammerConnectionException{
    //First zip file if required.
    java.io.File flSend = null;
    int iSize = (int)fl.length();
    int iMinZipSize = SourceJammerClient.getInstance().getZipIfLargerThan();
    long lTempID = -1;
    if (iSize > iMinZipSize && ZipUtil.canZip(fl.getName())){
      lTempID = TempDirectoryManager.getNextID();
      java.io.File flZip = TempDirectoryManager.getNewTempFile(lTempID);
      ZipUtil.zipFileToFile(fl, flZip);
      flSend = flZip;
      request.putBoolean(BINARY_ZIPPED, true);
    }
    else {
      flSend = fl;
      request.removeValue(BINARY_ZIPPED);
    }
    long lSendID = -1;
    if (flSend.length() < (SourceJammerClient.getInstance().getMaxFileSendChunkSize())){
      lSendID = FileTransport.sendFullFileToServer(flSend, msURL);
    }
    else{
      lSendID = FileTransport.sendFileToServer(flSend, msURL);
    }
    if (request.booleanValue(BINARY_ZIPPED)){
      //remove temp file.
      TempDirectoryManager.deleteTempFile(lTempID);
    }
    return lSendID;
  }

  /*
  public static void main (String[] args){
    byte[] by1 = {1, 2, 3, 4, 5};
    byte[] by2 = {1, 2, 3, 4, 5};

    if (by1 == by2){
      System.out.println("Equal.");
    }
    else {
      System.out.println("Not equal.");
    }
  }
  */
  /**
   * Returns the proxyPassword.
   * @return String
   */
  public String getProxyPassword() {
    return proxyPassword;
  }

  /**
   * Returns the proxyPasswordSet.
   * @return boolean
   */
  public boolean isProxyPasswordSet() {
    return proxyPasswordSet;
  }

  /**
   * Sets the proxyPassword.
   * @param proxyPassword The proxyPassword to set
   */
  public void setProxyPassword(String proxyPassword) {
    this.proxyPassword = proxyPassword;
  }

  /**
   * Sets the proxyPasswordSet.
   * @param proxyPasswordSet The proxyPasswordSet to set
   */
  public void setProxyPasswordSet(boolean proxyPasswordSet) {
    this.proxyPasswordSet = proxyPasswordSet;
  }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.