{
tempFile = new IFSFile(as400System, tempName);
if (tempFile.exists())
if (!tempFile.delete())
{
throw new XException(Constants.LOCATION_EXTERN,
Constants.LAYER_TECHNICAL,
Constants.PACKAGE_TECHNICAL_AS400, "7",
(List) null);
}
if (!destFile.renameTo(tempFile))
{
throw new XException(Constants.LOCATION_EXTERN,
Constants.LAYER_TECHNICAL,
Constants.PACKAGE_TECHNICAL_AS400, "8", (List) null);
}
// Reinitialize to check existance of the renamed member
// Return value of renameTo is not reliable. It may be <true>
// even if
// the renaming was not successful.
tempFile = new IFSFile(as400System, tempName);
// Make sure that renaming was successful.
if (!tempFile.exists())
{
throw new XException(Constants.LOCATION_EXTERN,
Constants.LAYER_TECHNICAL,
Constants.PACKAGE_TECHNICAL_AS400, "8", (List) null);
}
// Reinitialise to allow further renaming
destFile = new IFSFile(as400System, destFilename);
} // if (destFile.exists())
boolean renameBackTempFile = false;
// Should the renaming of the destination member be reversed?
// 2. rename source file to dest file
if (srcFile.renameTo(destFile))
{
// Reinitialise to check existance of the destination file
// Return value of renameTo is not reliable. It may be <true>
// even if
// the renaming was not successful.
destFile = new IFSFile(as400System, destFilename);
// Make sure that renaming was successful.
if (!destFile.exists())
renameBackTempFile = true;
// delete temp member
if (tempFile != null && tempFile.exists())
deleteMember(as400System, tempName);
} // if (srcFile.renameTo(destFile))
else
// Reverse initial renaming of the destination file member
renameBackTempFile = true;
// 3. Rename the destination file member bach to its original name
// if
// any error prevented the renaming of the source file.
// Only necessary if the destination filemember existed before and
// was
// renamed to a temporyry member name.
if (tempFile != null && renameBackTempFile)
{ // Reverse initial renaming of the destination file member
// Reinitialise to allow backwards renaming
destFile = new IFSFile(as400System, destFilename);
// rename back temp member to destination member
tempFile.renameTo(destFile);
List params = new Vector();
params.add(sourceFilename);
params.add(destFilename);
throw new XException(Constants.LOCATION_EXTERN,
Constants.LAYER_TECHNICAL,
Constants.PACKAGE_TECHNICAL_AS400, "10", params);
} // if (tempFile!=null && renameBackTempFile)
} // try
catch (Exception ex)
{
throw new XException(Constants.LOCATION_EXTERN,
Constants.LAYER_TECHNICAL,
Constants.PACKAGE_TECHNICAL_AS400, "0", ex);
} // catch
} // renameFile(AS400 as400System,String sourceFilename,String