import com.ibm.as400.data.ProgramCallDocument;
import com.ibm.as400.data.PcmlException;
import com.ibm.as400.access.AS400;
import com.ibm.as400.access.AS400Message;
// Example program to call "Retrieve NFS Exports" (QZNFRTVE) API
public class qznfrtve
{
public static void main(String[] argv)
{
AS400 as400System; // com.ibm.as400.access.AS400
ProgramCallDocument pcml; // com.ibm.as400.data.ProgramCallDocument
boolean rc = false; // Return code from ProgramCallDocument.callProgram()
String msgId, msgText; // Messages returned from AS/400
Object value; // Return value from ProgramCallDocument.getValue()
System.setErr(System.out);
// Construct AS400 without parameters, user will be prompted
as400System = new AS400();
int[] indices = new int[2]; // Indices for access array value
int nbrExports; // Number of exports returned
int nbrOfReadWriteHostNames, nbrOfRWHostNames,
nbrOfRootHostNames, nbrOfAccessHostnames, nbrOfHostOpts;
try
{
// Uncomment the following to get debugging information
// com.ibm.as400.data.PcmlMessageLog.setTraceEnabled(true);
System.out.println("Beginning PCML Example..");
System.out.println(" Constructing ProgramCallDocument for QZNFRTVE API...");
// Construct ProgramCallDocument
// First parameter is system to connect to
// Second parameter is pcml resource name. In this example,
// serialized PCML file "qznfrtve.pcml.ser" or
// PCML source file "qznfrtve.pcml" must be found in the classpath.
pcml = new ProgramCallDocument(as400System, "qznfrtve");
// Set input parameters. Several parameters have default values
// specified in the PCML source. Do not need to set them using Java code.
System.out.println(" Setting input parameters...");
pcml.setValue("qznfrtve.receiverLength", new Integer( ( pcml.getOutputsize("qznfrtve.receiver"))));
// Request to call the API
// User will be prompted to sign on to the system
System.out.println(" Calling QZNFRTVE API requesting NFS exports.");
rc = pcml.callProgram("qznfrtve");
if (rc == false)
{
// Retrieve list of AS/400 messages
AS400Message[] msgs = pcml.getMessageList("qznfrtve");
// Iterate through messages and write them to standard output
for (int m = 0; m < msgs.length; m++)
{
msgId = msgs[m].getID();
msgText = msgs[m].getText();
System.out.println(" " + msgId + " - " + msgText);
}
System.out.println("** Call to QZNFRTVE failed. See messages above **");
System.exit(0);
}
// Return code was true, call to QZNFRTVE succeeded
// Write some of the results to standard output
else
{
nbrExports = pcml.getIntValue("qznfrtve.returnedRcdsFdbkInfo.nbrOfNFSExportEntries");
// Iterate through list of exports
for (indices[0] = 0; indices[0] < nbrExports; indices[0]++)
{
value = pcml.getValue("qznfrtve.receiver.pathName", indices);
System.out.println("Path name = " + value);
// Iterate and write out Read Write Host Names for this export
nbrOfReadWriteHostNames = pcml.getIntValue("qznfrtve.receiver.nbrOfReadWriteHostNames", indices);
for(indices[1] = 0; indices[1] < nbrOfReadWriteHostNames; indices[1]++)
{
value = pcml.getValue("qznfrtve.receiver.rwAccessList.hostName", indices);
System.out.println(" Read/write access host name = " + value);
}
// Iterate and write out Root Host Names for this export
nbrOfRootHostNames = pcml.getIntValue("qznfrtve.receiver.nbrOfRootHostNames", indices);
for(indices[1] = 0; indices[1] < nbrOfRootHostNames; indices[1]++)
{
value = pcml.getValue("qznfrtve.receiver.rootAccessList.hostName", indices);
System.out.println(" Root access host name = " + value);
}
// Iterate and write out Access Host Names for this export
nbrOfAccessHostnames = pcml.getIntValue("qznfrtve.receiver.nbrOfAccessHostNames", indices);
for(indices[1] = 0; indices[1] < nbrOfAccessHostnames; indices[1]++)
{
value = pcml.getValue("qznfrtve.receiver.accessHostNames.hostName", indices);
System.out.println(" Access host name = " + value);
}
// Iterate and write out Host Options for this export
nbrOfHostOpts = pcml.getIntValue("qznfrtve.receiver.nbrOfHostOptions", indices);
for(indices[1] = 0; indices[1] < nbrOfHostOpts; indices[1]++)
{
System.out.println(" Host options:");
value = pcml.getValue("qznfrtve.receiver.hostOptions.dataFileCodepage", indices);
System.out.println(" Data file code page = " + value);
value = pcml.getValue("qznfrtve.receiver.hostOptions.pathNameCodepage", indices);
System.out.println(" Path name code page = " + value);
value = pcml.getValue("qznfrtve.receiver.hostOptions.writeModeFlag", indices);
System.out.println(" Write mode flag = " + value);
value = pcml.getValue("qznfrtve.receiver.hostOptions.hostName", indices);
System.out.println(" Host name = " + value);
}
} // end for loop iterating list of exports
} // end call to QZNFRTVE succeeded
}
catch(PcmlException e)
{
System.out.println(e.getLocalizedMessage());
e.printStackTrace();
System.exit(-1);
}
System.exit(0);
} // end main()
}
|