protected final WorkspaceInfo determineCachedWorkspace(final String[] pathFreeArguments,final boolean ignoreWorkspaceOptionValue) throws CannotFindWorkspaceException, InvalidOptionValueException, InvalidOptionException {
  WorkspaceInfo cachedWorkspace=null;
  final OptionWorkspace optionWorkspace=(OptionWorkspace)findOptionType(OptionWorkspace.class);
  if (!ignoreWorkspaceOptionValue && optionWorkspace != null) {
    final WorkspaceSpec spec;
    try {
      spec=WorkspaceSpec.parse(optionWorkspace.getValue(),null);
    }
 catch (    final WorkspaceSpecParseException e) {
      throw new CannotFindWorkspaceException(e.getMessage());
    }
    final URI serverURI;
    final OptionCollection collectionOption=getCollectionOption();
    if (collectionOption != null) {
      serverURI=collectionOption.getURI();
    }
 else {
      serverURI=null;
    }
    final WorkspaceInfo[] all=findLocalWorkspaces(serverURI,spec.getName(),spec.getOwner());
    if (all == null || all.length == 0) {
      final String messageFormat=Messages.getString("Command.WorkspaceNotFoundInCacheFormat");
      final String message=MessageFormat.format(messageFormat,spec.toString());
      throw new CannotFindWorkspaceException(message);
    }
 else     if (all.length > 1 && spec.getOwner() == null) {
      final String messageFormat=Messages.getString("Command.WorkspaceNameMatchesMoreThanOneFormat");
      final String message=MessageFormat.format(messageFormat,spec.toString());
      throw new CannotFindWorkspaceException(message);
    }
 else     if (all.length > 1) {
      final String messageFormat=Messages.getString("Command.WorkspaceNameAndOwnerMatchesMoreThanOneFormat");
      final String message=MessageFormat.format(messageFormat,spec.getName(),spec.getOwner());
      throw new CannotFindWorkspaceException(message);
    }
    cachedWorkspace=all[0];
  }
 else {
    final String[] pathsToSearch=(pathFreeArguments == null) ? getFreeArguments() : pathFreeArguments;
    for (int i=0; i < pathsToSearch.length; i++) {
      String path=pathsToSearch[i];
      try {
        final VersionedFileSpec spec=VersionedFileSpec.parse(path,VersionControlConstants.AUTHENTICATED_USER,true);
        if (spec.getItem() != null) {
          path=spec.getItem();
        }
      }
 catch (      final VersionSpecParseException e) {
      }
catch (      final LabelSpecParseException e) {
      }
      path=ItemPath.canonicalize(path);
      if (!ServerPath.isServerPath(path)) {
        cachedWorkspace=findCachedWorkspaceForPath(path);
        if (cachedWorkspace != null) {
          break;
        }
      }
    }
    if (cachedWorkspace == null) {
      final File currentDirectory=new File(LocalPath.getCurrentWorkingDirectory());
      cachedWorkspace=findCachedWorkspaceForPath(currentDirectory.getAbsolutePath());
    }
    if (cachedWorkspace == null) {
      throw new CannotFindWorkspaceException(Messages.getString("Command.WorkspaceCouldNotBeDetermined"));
    }
  }
  Check.notNull(cachedWorkspace,"cachedWorkspace");
  return cachedWorkspace;
}

protected final WorkspaceInfo determineCachedWorkspace ( final String [ ] pathFreeArguments , final boolean ignoreWorkspaceOptionValue ) throws CannotFindWorkspaceException , InvalidOptionValueException , InvalidOptionException { WorkspaceInfo cachedWorkspace = null ; final OptionWorkspace optionWorkspace = ( OptionWorkspace ) findOptionType ( OptionWorkspace . class ) ; if ( ! ignoreWorkspaceOptionValue && optionWorkspace != null ) { final WorkspaceSpec spec ; try { spec = WorkspaceSpec . parse ( optionWorkspace . getValue ( ) , null ) ; } catch ( final WorkspaceSpecParseException e ) { throw new CannotFindWorkspaceException ( e . getMessage ( ) ) ; } final URI serverURI ; final OptionCollection collectionOption = getCollectionOption ( ) ; if ( collectionOption != null ) { serverURI = collectionOption . getURI ( ) ; } else { serverURI = null ; } final WorkspaceInfo [ ] all = findLocalWorkspaces ( serverURI , spec . getName ( ) , spec . getOwner ( ) ) ; if ( all == null || all . length == 0 ) { final String messageFormat = Messages . getString ( "Command.WorkspaceNotFoundInCacheFormat" ) ; final String message = MessageFormat . format ( messageFormat , spec . toString ( ) ) ; throw new CannotFindWorkspaceException ( message ) ; } else if ( all . length > 1 && spec . getOwner ( ) == null ) { final String messageFormat = Messages . getString ( "Command.WorkspaceNameMatchesMoreThanOneFormat" ) ; final String message = MessageFormat . format ( messageFormat , spec . toString ( ) ) ; throw new CannotFindWorkspaceException ( message ) ; } else if ( all . length > 1 ) { final String messageFormat = Messages . getString ( "Command.WorkspaceNameAndOwnerMatchesMoreThanOneFormat" ) ; final String message = MessageFormat . format ( messageFormat , spec . getName ( ) , spec . getOwner ( ) ) ; throw new CannotFindWorkspaceException ( message ) ; } cachedWorkspace = all [ 0 ] ; } else { final String [ ] pathsToSearch = ( pathFreeArguments == null ) ? getFreeArguments ( ) : pathFreeArguments ; for ( int i = 0 ; i < pathsToSearch . length ; i ++ ) { String path = pathsToSearch [ i ] ; try { final VersionedFileSpec spec = VersionedFileSpec . parse ( path , VersionControlConstants . AUTHENTICATED_USER , true ) ; if ( spec . getItem ( ) != null ) { path = spec . getItem ( ) ; } } catch ( final VersionSpecParseException e ) { } catch ( final LabelSpecParseException e ) { } path = ItemPath . canonicalize ( path ) ; if ( ! ServerPath . isServerPath ( path ) ) { cachedWorkspace = findCachedWorkspaceForPath ( path ) ; if ( cachedWorkspace != null ) { break ; } } } if ( cachedWorkspace == null ) { final File currentDirectory = new File ( LocalPath . getCurrentWorkingDirectory ( ) ) ; cachedWorkspace = findCachedWorkspaceForPath ( currentDirectory . getAbsolutePath ( ) ) ; } if ( cachedWorkspace == null ) { throw new CannotFindWorkspaceException ( Messages . getString ( "Command.WorkspaceCouldNotBeDetermined" ) ) ; } } Check . notNull ( cachedWorkspace , "cachedWorkspace" ) ; return cachedWorkspace ; }
determines which cached workspace ( if any ) matches the workspace command line option , or the free arguments , or the current directory ( in that order ) . throws if no match is found . only cached workspaces that reside on the current computer can match .
