Skip to content

Commit

Permalink
Add getMessageOption() and setMessageOption() to ProgramCallDocument
Browse files Browse the repository at this point in the history
Allows users to specify how many messages should be returned when calling a program. This option already existed on ProgramCalls, but there was no way to set this through (X)PCML calls. These changes expose that option now.
Also made a change to always save the message list after the program call is run. Previously, the message list would only be saved if the program call signaled an error. However, the underlying ProgramCall would always save the message list off no matter the result. So match that behavior for (X)PCML calls.

Signed-off-by: Parker Young <[email protected]>
  • Loading branch information
pjyoung-ibm committed Jun 27, 2024
1 parent a31e649 commit 1ec8c1a
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 3 deletions.
21 changes: 21 additions & 0 deletions src/main/java/com/ibm/as400/data/PcmlDocument.java
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,15 @@ synchronized AS400Message[] getMessageList(String name) throws PcmlException
return getProgramNode(name).getMessageList();
}

/**
Returns the option for how many messages will be retrieved for the specified program.
@return A constant indicating how many messages will be retrieved.
**/
synchronized int getMessageOption(String name) throws PcmlException
{
return getProgramNode(name).getMessageOption();
}

/**
Returns the ProgramCall object that was used in the most recent invocation of {@link #callProgram() callProgram()}.
@return The ProgramCall object; null if callProgram has not been called.
Expand Down Expand Up @@ -692,6 +701,18 @@ boolean getThreadsafeOverride(String program) // @C6A
return getProgramNode(program).getThreadsafeOverride(); // @C6A
} // @C6A

/**
Specifies the option for how many messages should be retrieved for the specified program. By default, to preserve
compatability, only the messages sent to the program caller and only up to ten messages are retrieved.
This property will only take effect on systems that support the new option.
@param messageOption A constant indicating how many messages to retrieve.
**/
synchronized void setMessageOption(String program, int messageOption)
throws PcmlException
{
getProgramNode(program).setMessageOption(messageOption);
}

// Add a subtree to the document's hashtable.
// This is called to complete the document cloneing process.
void addToHashtable(PcmlDocNode newChild) // @C5A
Expand Down
29 changes: 27 additions & 2 deletions src/main/java/com/ibm/as400/data/PcmlProgram.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import com.ibm.as400.access.AS400;
import com.ibm.as400.access.AS400Message;
import com.ibm.as400.access.ExtendedIllegalArgumentException;
import com.ibm.as400.access.ProgramCall;
import com.ibm.as400.access.ServiceProgramCall; // @B1A
import com.ibm.as400.access.ProgramParameter;
Expand Down Expand Up @@ -91,6 +92,7 @@ class PcmlProgram extends PcmlDocNode
private AS400Message[] msgList; // Array of AS400Message @C1C
private int m_IntReturnValue; // Int return value for a service program call @B1A @C1C
private int m_Errno; // Errno for a service program call @B1A @C1C
private int m_MessageOption;

/**
*/
Expand All @@ -102,6 +104,7 @@ public PcmlProgram()
m_IntReturnValue = 0; // @C1A
m_Errno = 0; // @C1A
m_ThreadsafeOverrideCalled = false; // @D2A
m_MessageOption = AS400Message.MESSAGE_OPTION_UP_TO_10;
}

// Constructor
Expand All @@ -116,6 +119,7 @@ public PcmlProgram(PcmlAttributeList attrs) // @C3C
m_IntReturnValue = 0; // @C1A
m_Errno = 0; // @C1A
m_ThreadsafeOverrideCalled = false; // @D2A
m_MessageOption = AS400Message.MESSAGE_OPTION_UP_TO_10;

// **********************************
// Set attribute values
Expand Down Expand Up @@ -682,6 +686,8 @@ else if (getEntrypoint() != null) // @D1A
m_pgmCall.setThreadSafe(getThreadsafeOverride()); // @C6A
}

m_pgmCall.setMessageOption(getMessageOption());

//
// Call the target program
//
Expand All @@ -692,11 +698,15 @@ else if (getEntrypoint() != null) // @D1A
if (Trace.isTraceOn()) Trace.log(Trace.PCML, "Completed program call: " + m_pgmCall.getProgram());

//
// If the program signalled a message, save the message list.
// Save the message list in all cases
//
msgList = m_pgmCall.getMessageList();

//
// If the program signaled a message, stop processing here.
//
if (m_pgmRc != true)
{
msgList = m_pgmCall.getMessageList();
return m_pgmRc;
}

Expand Down Expand Up @@ -883,6 +893,21 @@ AS400Message[] getMessageList()
return msgList;
}

int getMessageOption()
{
return m_MessageOption;
}

void setMessageOption(int messageOption)
{
// Validate the messageOption parameter.
if (messageOption < 0 || messageOption > 2)
{
throw new ExtendedIllegalArgumentException("messageOption (" + messageOption + ")", ExtendedIllegalArgumentException.PARAMETER_VALUE_NOT_VALID);
}
m_MessageOption = messageOption;
}

/**
Returns whether or not this element is defined as a service program entrypoint.
Expand Down
41 changes: 40 additions & 1 deletion src/main/java/com/ibm/as400/data/ProgramCallDocument.java
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,25 @@ public AS400Message[] getMessageList(String name)
return m_pcmlDoc.getMessageList(name);
}

/**
Returns the option for how many messages will be retrieved for the specified program.
@param name The name of the &lt;program&gt; element in the PCML document.
@return A constant indicating how many messages will be retrieved. Valid values are:
<ul>
<li>{@link AS400Message#MESSAGE_OPTION_UP_TO_10 MESSAGE_OPTION_UP_TO_10}
<li>{@link AS400Message#MESSAGE_OPTION_NONE MESSAGE_OPTION_NONE}
<li>{@link AS400Message#MESSAGE_OPTION_ALL MESSAGE_OPTION_ALL}
</ul>
@exception PcmlException
If an error occurs.
**/
public int getMessageOption(String name)
throws PcmlException
{
return m_pcmlDoc.getMessageOption(name);
}

/**
Returns the number of bytes reserved for output for the named element.
Expand Down Expand Up @@ -1351,6 +1370,27 @@ public boolean getThreadsafeOverride(String program)
return m_pcmlDoc.getThreadsafeOverride(program); // @C6A
}

/**
Specifies the option for how many messages should be retrieved for the specified program. By default, to preserve
compatability, only the messages sent to the program caller and only up to ten messages are retrieved.
This property will only take effect on systems that support the new option.
@param program The name of the &lt;program&gt; element in the PCML document.
@param messageOption A constant indicating how many messages to retrieve. Valid values are:
<ul>
<li>AS400Message.MESSAGE_OPTION_UP_TO_10
<li>AS400Message.MESSAGE_OPTION_NONE
<li>AS400Message.MESSAGE_OPTION_ALL
</ul>
@exception PcmlException
If an error occurs.
**/
public void setMessageOption(String program, int messageOption)
throws PcmlException
{
m_pcmlDoc.setMessageOption(program, messageOption);
}


/**
Saves a PcmlDocument as a serialized resource.
Expand Down Expand Up @@ -2013,5 +2053,4 @@ public int getTimeout() {
return m_timeOut;
}
//@Y6A End

}

0 comments on commit 1ec8c1a

Please sign in to comment.