404 IBM Express Runtime V2.1
The SamplePDC.java file
Example C-4 shows the source code for the SamplePDC class.
Example: C-4 Source of SamplePDC.java
/*
* Created on Mar 10, 2005
*
* This sample program demonstrates how to create a wrapper.
* Based on your knowledge of your application,
* use this code as an example to develop a custom wrapper.
*/
package com.ibm.flght400;
import java.io.File;
import com.ibm.as400.access.AS400;
import com.ibm.as400.resource.RSoftwareResource;
import com.ibm.jsdt.support.SupportOS400Base;
import com.ibm.jsdt.support.SupportOS400Helper;
/**
* This is a sample class, created as part of the Redbook example.
*/
public class SamplePDC extends SupportOS400Base {
private String ivWASProfileDir = null;
private String ivAppName = null;
private String ivWASServerName = null;
private String ivWasProfileName = null;
private String ivHttpServerName = null;
private String ivScriptsDir = null;
private SupportOS400Helper ivHelper = null;
private String ivDB2AdminUserId = null;
private String ivBaseRelease = null;
public SamplePDC(){
}
/**
* Initialize the object.
* Retrieve input parameter
* parm#0 = The response file name.
* parm#1 = The minimul release that the sample can be installed on.
*
*/
public int init(String[] args)
{
setMainResources(SampleCommon.SAMPLE_MESSAGES);
ivHelper = (SupportOS400Helper) getHelper();
if (args.length != 2) {
logMessage(getResourceString(SampleNLSkeys.BAD_NUMBER_PGM_ARGS, new String []{"SamplePDC", "2",
Integer.toString(args.length)}));
return FAILURE;
}
setResponseFileName(args[0]);
setBaseRelease(args[1]);
return SUCCESS;
Appendix C. Source code for Flght400 user programs and script files on OS/400 405
}
/**
* The sample application requires WAS and HTTP to be install,
* and the WAS and HTTP servers instances to be configured. This PDC will
* - check to see if WAS is installed. (version specified in the properties file)
* - check to see if HTTP is installed.
* - check to see if the HTTP server name is configured.
* - check to see if the WAS profile is configured.
* - check to see if the OS release is equal or later than the base release
* - check to see if the application is installed
*/
private int check()
{
logMessage ("We are in PDC.check method");
// get the values set in the properties file, properties file is mandatory
if (getResponseFileName() == null || getResponseFileName().trim().equals("")) {
logMessage(getResourceString(SampleNLSkeys.NO_PROPERTIES_FILE));
return FAILURE;
} else {
if (getProperties() == FAILURE) return FAILURE;
}
logMessage ("Checking the OS level");
//check to make sure the release is at the correct level
if (isCurReleaseEqualOrGreater(getBaseRelease()) == false) {
logMessage(getResourceString(SampleNLSkeys.INVALID_OS_RELEASE, new
String[]{getBaseRelease()}));
return FAILURE;
}
//check to make sure HTTP is installed
logMessage ("Checking if HTTP installed");
AS400 as400 = new AS400();
if (SampleCommon.isProductInstall(as400, SampleCommon.HTTP_PRODUCT_ID,
RSoftwareResource.RELEASE_LEVEL_CURRENT,
RSoftwareResource.PRODUCT_OPTION_BASE) == false) {
logMessage(getResourceString(SampleNLSkeys.HTTP_NOT_INSTALLED, new
String[]{SampleCommon.HTTP_PRODUCT_ID}));
return FAILURE;
}
//check to make sure WAS is installed
logMessage ("Checking if WAS installed");
if (SampleCommon.isProductInstall(as400, SampleCommon.WAS_PRODUCT_ID,
RSoftwareResource.RELEASE_LEVEL_ONLY,
SampleCommon.WAS_PRODUCT_OPTION) == false) {
logMessage(getResourceString(SampleNLSkeys.WAS_NOT_INSTALLED, new
String[]{SampleCommon.WAS_PRODUCT_ID}));
return FAILURE;
}
//check to see if HTTP server is configured.
logMessage ("Checking if HTTP configured");
if (isHTTPServerConfigured() == false) {
logMessage(getResourceString(SampleNLSkeys.HTTP_SERVER_NOT_CONFIG, new
String[]{getHttpServerName()}));
return FAILURE;
}
406 IBM Express Runtime V2.1
//check to see if WAS server is configured.
logMessage ("Checking if WAS configured");
if (isWASServerConfigured() == false) {
logMessage(getResourceString(SampleNLSkeys.WAS_SERVER_NOT_EXIST, new
String[]{getServerName()}));
return FAILURE;
}
/* Don't need this
//check to see if DB2 Admin Id Exists
logMessage ("Checking if DB2 user exist");
setUserName (getDb2AdminUserId());
if ( ivHelper.doesUserExist (this) == false) {
logMessage(getResourceString(SampleNLSkeys.NO_USER_PROF, getDb2AdminUserId()));
return FAILURE;
}
//The next if should be in Main program. Access to the script file is not available yet.
//check to see if the application is installed.
logMessage ("Checking if application installed");
if (isApplicationInstalled() == true) {
return PDC_EXISTS;
}
*/
return PDC_DOES_NOT_EXIST;
}
/**
* Get values from the properties file
*/
private int getProperties()
{
int rc = SUCCESS;
// The properties file name was set in the constructor
// Log the contents of the properties file
ivHelper.logNewLine(this);
setFileName(getResponseFileName());
ivHelper.logAppendFile(this);
ivHelper.logNewLine(this);
// get the values specified in the properties file that are needed by this PDC
setKey(SampleCommon.SERVER_NAME_KEY); // server name to use to determine the application path
setServerName(ivHelper.getResponseFileValue(this));
if (getServerName() == null || getServerName().equals("")) {
logMessage(getResourceString(SampleNLSkeys.NO_PROPERTY, SampleCommon.SERVER_NAME_KEY));
rc = FAILURE;
}
setKey(SampleCommon.WAS_PROFILE_KEY); // WAS profile name
setWasProfileName(ivHelper.getResponseFileValue(this));
if (getWasProfileName() == null || getWasProfileName().equals("")) {
if (getServerName() == null || getServerName().equals("")) {
logMessage(getResourceString(SampleNLSkeys.NO_PROPERTY, SampleCommon.WAS_PROFILE_KEY));
rc = FAILURE;
} else {
setWasProfileName(getServerName());
}
}
determineWasProfileDir(getWasProfileName());

Get IBM Express Runtime V2.1 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.