/*****************************************************************************/
/* File name: InstanceFilable.java                                           */
/* Purpose: to work with the Filable instances                               */
/*                                                                           */
/* Last modified: 24.06.99                                                   */
/* Author: Victor Klimov, 1999                                               */
/* For the list of authors and contributors of the original C version        */
/* of the GNU tar see files AUTHORS and THANKS                               */
/*                                                                           */
/* 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 io;


import java.lang.reflect.*;


public
class

InstanceFilable

{
  private final static String RCSID =
"$Header: /d/NFS/io/RCS/InstanceFilable.java,v 1.1 1999/06/24 17:52:27 vklimov Exp $";


  public
  InstanceFilable() 
/*****************************************************************************/
/* Function name: InstanceFilable                                            */
/* File name: InstanceFilable.java                                           */
/* Purpose: constructor                                                      */
/* Parameters:                                                               */
/* Returns:                                                                  */
/* Last modified: 24.06.99                                                   */
/* Author: Victor Klimov, 1999                                               */
/*****************************************************************************/
    {
                                                       /* InstanceFilable */
/*---------------------------------------------------------------------------*/

    }
/*end of InstanceFilable*/



  public
  static
  Filable

  get( Class thisFileClass,
       String dirPath       )
/*****************************************************************************/
/* Function name: get                                                        */
/* File name: InstanceFilable.java                                           */
/* Purpose: to return an instance of the Filable object                      */
/*          representing a given file                                        */
/* Parameters: thisFileClass                                                 */
/*             dirPath                                                       */
/* Returns: the instance or                                                  */
/*          null in case of an error                                         */
/* Last modified: 24.06.99                                                   */
/* Author: Victor Klimov, 1999                                               */
/*****************************************************************************/
    {
      Filable     result = null;
      Class[]     parameterTypesArray = null;
      Constructor fileNameConstructor = null;
      Object[]    filableConstructorArguments = null;
                                                               /* get */
/*---------------------------------------------------------------------------*/

      if ( (thisFileClass == null) ||
           (dirPath == null)
         )
        return null;                                   /* return ! */
      else
        ;
    /*end of if*/

      parameterTypesArray = new Class[ 1 ];            /* only one parameter */
      parameterTypesArray[0] = java.lang.String.class; /* file name          */

      try
        {
          fileNameConstructor =
            thisFileClass.
              getConstructor( parameterTypesArray );

          filableConstructorArguments = new Object[ 1 ];
          filableConstructorArguments[ 0 ] = (Object) dirPath;

          result = (Filable)
            fileNameConstructor.
              newInstance(
                filableConstructorArguments );
        }
      catch( NoSuchMethodException e )
        {
          System.out.println( "NoSuchMethodException!" +
                              "\nthe class " +
                              thisFileClass.getName() +
                              "\ndoes not have constructor " +
                              "with one String parameter\n" +
                              e.getMessage()                  );
        }
      catch( SecurityException e )
        {
          System.out.println( "SecurityException!" +
                              "\naccess denied " +
                              "to the constructor " +
                              "of the class " +
                              thisFileClass.getName() +
                              "\n" +
                              e.getMessage()                  );
        }
      catch( InvocationTargetException e )
        {
          System.out.println( "InvocationTargetException!" +
                              "\nthe constructor of class " +
                              thisFileClass.getName() +
                              "\nhas thrown an exception\n" +
                              e.getMessage()                  );
        }
      catch( InstantiationException e )
        {
          System.out.println( "InstantiationException!" +
                              "\nthe class " +
                              thisFileClass.getName() +
                              "\ncan\'n have instances\n" +
                              e.getMessage()                  );
        }
      catch( IllegalAccessException e )
        {
          System.out.println( "IllegalAccessException!" +
                              "\nthe constructor of the class " +
                              thisFileClass.getName() +
                              "\nis not accessible\n" +
                              e.getMessage()                  );
        }
      catch( IllegalArgumentException e )
        {
          System.out.println( "IllegalArgumentException!" +
                              "\nthe arguments supplied " +
                              "to the constructor of the class " +
                              thisFileClass.getName() +
                              "\ndo not match to the " +
                              "actual parameters\n" +
                              e.getMessage()                  );
        }
    /*end of try-catch*/

      return result;

    }
/*end of get*/


}/*end of InstanceFilable class*/

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