/*****************************************************************************/
/* File name: Exporter.java                                                  */
/* Purpose: to prepare file systems for export                               */
/*                                                                           */
/* Last modified: 09.08.99                                                   */
/* Author: Victor Klimov, 1999                                               */
/*                                                                           */
/* This program 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 General */
/* Public License for more details.                                          */
/*                                                                           */
/* This software is distributed under the terms                              */
/* of the GNU General Public License as published                            */
/* by the Free Software Foundation; either version 2, or (at your option)    */
/* any later version.                                                        */
/* See file COPYING for your rights (GNU GPL)                                */
/*****************************************************************************/

package nfs;


import java.io.*;
import io.*;
import mount.*;


public
class

Exporter
                  implements Runnable
{

  private final static String RCSID =
"$Header: /d/NFS/nfs/RCS/Exporter.java,v 1.2 1999/08/13 20:04:40 vklimov Exp $";

  private FileReader exportsFileReader = null;
  private mount.Registry exportedFileSystemsRegistry = null;
  private String cacheDir = null;

  public

  Exporter( FileReader exportsFileReader,
            mount.Registry exportedFileSystemsRegistry,
            String cacheDir                             )
/*****************************************************************************/
/* Function name: Exporter                                                   */
/* File name: Exporter.java                                                  */
/* Purpose: constructor for the Exporter class                               */
/* Parameters: exportsFileReader                                             */
/*             exportedFileSystemsRegistry                                   */
/*             cacheDir                                                      */
/* Returns:                                                                  */
/* Last modified: 09.08.99                                                   */
/* Author: Victor Klimov, 1999                                               */
/*****************************************************************************/
    {
                                                           /* Exporter */
/*---------------------------------------------------------------------------*/

      this.exportsFileReader = exportsFileReader;
      this.exportedFileSystemsRegistry = exportedFileSystemsRegistry;
      this.cacheDir = cacheDir;
    }
/*end of Exporter*/


  public
  void

  exportAFileSystem( java.lang.String line )
/*****************************************************************************/
/* Function name: exportAFileSystem                                          */
/* File name: Exporter.java                                                  */
/* Purpose: to prepare a file system for export                              */
/* Parameters: line                                                          */
/* Returns:                                                                  */
/* Last modified: 09.08.99                                                   */
/* Author: Victor Klimov, 1999                                               */
/*****************************************************************************/
    {
      long fileId;
      Fhandle fhandle;
      FileSystemable fileSystem = null;
                                                    /* exportAFileSystem */
/*---------------------------------------------------------------------------*/

      fileSystem = FileSystemExpert.
                     getFileSystem( line,
                                    cacheDir );

      if (fileSystem == null) return;                      /* return ! */

      fileId =
        exportedFileSystemsRegistry.        /* have to change that to new */
          getUniqueFileId();                /* in the mount registry      */

      if (fileId == mount.Constants.FILE_ID_NOT_VALID) return; /* return ! */

      fhandle = new Fhandle( fileId,
                             null,                     /* no host name yet */
                             line,
                             fileSystem );

      exportedFileSystemsRegistry.put( fhandle );

    }
/*end of exportAFileSystem*/


  public
  void

  run()
/*****************************************************************************/
/* Function name: run                                                        */
/* File name: Exporter.java                                                  */
/* Purpose: to prepare the file systems for export                           */
/* Parameters: exportsFileReader                                             */
/*             exportedFileSystemsRegistry                                   */
/* Returns:                                                                  */
/* Last modified: 24.07.99                                                   */
/* Author: Victor Klimov, 1999                                               */
/*****************************************************************************/
    {
      boolean continueToInputLines = true;
      String exportsLine = null;
      LineNumberReader exportsFileLineNumberReader = null;
                                                           /* run */
/*---------------------------------------------------------------------------*/

      exportsFileLineNumberReader = new
        LineNumberReader( exportsFileReader );

      try
        {
          while( continueToInputLines )
            {
              exportsLine =
                exportsFileLineNumberReader.readLine();
              if (exportsLine != null)
                {
                  exportsLine = exportsLine.trim();

                  if (exportsLine.
                        startsWith(
                          Constants.EXPORTS_FILE_COMMENT_START ))
                    ; /* ignore */
                  else
                    exportAFileSystem( exportsLine );
                /*end of if on thisLineIsACommentLine*/
                }
              else
                continueToInputLines = false;
            /*end of if on EOF*/
            }
        /*end of while-loop*/

          exportsFileLineNumberReader.close();
          exportsFileReader.close();
        }
      catch( IOException e )
        {
          System.out.println( "Exporter, run: " +
                              "IOException !\n" +
                              e.getMessage()      );
        }
    /*end of try-catch*/

    }
/*end of run*/


} /* end of Exporter class */

/*****************************************************************************/
/* End of file: Exporter.java                                                */
/*****************************************************************************/
