WebNFS Developer's Guide

Direct Access to Filesystem-Specific Features

A reference to the object implementing a filesystem's specific features can be determined through the class interface. The interface allows developers to directly call these methods. By doing this, you are increasing the risk of writing code that works only for one filesystem type so its use is discouraged. To obtain access to these features directly, use the public method XFile.getExtensionAccessor(). Once you have obtained this handle, you can access its methods directly. Refer to the filesystem implementor's documentation for class description details.

The following example shows how a method in the NFS ExtensionAccessor is used to set the user's authentication credentials using the NFS PCNFSD protocol:

                import java.io.*;

                import com.sun.xfile.*;

                import com.sun.nfs.*;

                public class nfslogin {

                   public static void main(String av[])

                   {

                      try {

                         XFile xf = new XFile(av[0]);

                         nfsXFileExtensionAccessor nfsx =

                            (nfsXFileExtensionAccessor) xf.getExtensionAccessor();


                         if (! nfsx.loginPCNFSD("pcnfsdsrv", "bob", "-passwd-")) {

                            System.out.println("login failed");

                            return;

                         }

                         if (xf.canRead())

                            System.out.println("Read permission OK");

                         else

                            System.out.println("No Read permission");

                      } catch (Exception e) {

                         System.out.println(e.toString());

                         e.printStackTrace(System.out);

                      }

                   }

                }