org.moremotion.process
Class Process

java.lang.Object
  extended by org.moremotion.process.Process
Direct Known Subclasses:
MScriptingProcess, QueryProcess

public abstract class Process
extends java.lang.Object

The process manager will call the interface methods of this abstract class as in the following example.

 pro.prepare(pbc);
 for (int i = 0; i < pb.recordCount(); i++) {
   ProcessRecord prec = pb.getRecord(i);
   if (isThroughRecordFilter(prec)) {
     pro.processRecord(prec);
   }
 }
 int cc = pro.finalizeProcess();
 
Please note that the process classes that extends this interface can have private data members safely since the process manager will create a new instance of them before calling their methods.

Version:
$Id: Process.java 67 2008-03-17 07:03:46Z erkan $

Constructor Summary
Process()
           
 
Method Summary
 ADOMNode createMessage(java.lang.Exception exception)
          Creates a new Request ADOM for the message if not already created, composes an message entry from the given Exception object and adds in it.
 ADOMNode createMessage(java.lang.String messageId, java.lang.String[] arguments, java.lang.Object details)
          Creates a new Request ADOM for the message if not already created and adds the given message in it.
abstract  void finalizeProcess()
          This method is called by the process manager after there is no more records to process.
 int getCompletionCode()
          Returns the completion code of the current step.
abstract  void prepare()
          The Process should prepare to be called for each process records existing in the configured process block.
abstract  void processRecord(ProcessRecord prec)
          This method is called by the process manager for each process record in the configured process block that passes through the configured record filter.
 java.lang.String resolve(java.lang.String str)
          Resolves the MScript functions existing in the given string and returns the resolved string.
 void setCompletionCode(int cc)
          Sets the completion code of the current step.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Process

public Process()
Method Detail

prepare

public abstract void prepare()
                      throws ProcessException
The Process should prepare to be called for each process records existing in the configured process block. The preparation can be accessing to the process configuration, establishing any necessary database connection and store the results of this preparation in private data members.

Throws:
ProcessException - indicates that the preparation failed and means other methods of this process instance will not be called and the overall completion code of the process execution will be set to 20.

processRecord

public abstract void processRecord(ProcessRecord prec)
                            throws ProcessException
This method is called by the process manager for each process record in the configured process block that passes through the configured record filter. For example if the call definition of the process is as follows
 <callProcess name="x" blockName="PBx" recordFilter="PRICE < 100" ... 
then the process manager will call the processRecord() method for each record in the process block "PBx" that satisfies the "PRICE < 100" pre-condition.

Parameters:
prec - The ProcessRecord Object that contains process fields
Throws:
ProcessException - indicates that there is an error and the process cannot continue. This exception will set the overall completion code to 20.

finalizeProcess

public abstract void finalizeProcess()
                              throws ProcessException
This method is called by the process manager after there is no more records to process. This is the last call to the process instance and therefore the process should finalize its tasks.

Note that this method is called regardless of the completion code if the prepare method did not throw an exception.

The method should take care of the current completion code and act accordingly

  public void finalizeProcess() throws ProcessException {
    if (getCompletionCode() <= 4) {
      // successfull completion
    } else {
      // unsuccessfull completion
    }
   }
 

Throws:
ProcessException - that indicates that finalization was in an unrecoverable error. This exception will set the completion code to 20.

resolve

public java.lang.String resolve(java.lang.String str)
                         throws MScriptException
Resolves the MScript functions existing in the given string and returns the resolved string.

Throws:
MScriptException

setCompletionCode

public void setCompletionCode(int cc)
Sets the completion code of the current step.

Parameters:
cc - the completion code

The value 0, which is the default, means everything was fine . A value between 1 and 4 means there were warnings but that's OK. A value between 5 and 8 means there were errors which should be interpretted as user errors and finally a value greater than 8 means process error.

It should be kept in mind that the process manager will not change the execution plan depending on the process completion codes. This is valid even if the process throws a ProcessException. in that case the process manager will catch the exception and set the completion code of the step to 20.

The process manager will attempt to execute all the processes in the processTemplate as long as the execution precondition (the expression defined in the "if" attribute) of the invocation elements, such as callProcess, callQueryProcess and callTemplate is satisfied.

Once the execution of process classes completed, the process manager decides what to do; If the maximum completion code is between 0 and 4, this means "success", the PM displays the configured "nextpage"; if it is between 5 and 8, this means "user-error" and the PM re-displays the "current page" to let the user to correct his/her errors; and if the code is greater than 8, the PM displays the configured "errorpage".


getCompletionCode

public int getCompletionCode()
Returns the completion code of the current step.


createMessage

public ADOMNode createMessage(java.lang.String messageId,
                              java.lang.String[] arguments,
                              java.lang.Object details)
Creates a new Request ADOM for the message if not already created and adds the given message in it.

This method will use the unitname definition made in the Proceces Definition element to name the data source to be created and the resource associated with it.

Parameters:
messageId - Either a message text or a resource ID. The message will be taken from the resource file unitname.res with this ID. If no resource is found with the given id in the resource file then messageId is used as the message text.
arguments - the message arguments which will be used to replace argument symbols (%0, %1, etc.) existing in the message text.
details - Either an Exception object that keeps the original exception or a String object that keeps the
message details.
Returns:
created ADOMNode object to let you add extra information to the message created.

The XML representation of the created message ADOM is as follows:

 <unitname_messages>
    <message id="messageId">
      <text>Message text taken from the resource file with the given messageId</text>
      <unitname>Given unit name</unitname>
      <details>Message Details. Either the Stack Trace of the orginal exception or the given details as String</details>
    </message>
 </unitname_messages>
 

Example:

  ADOMNode msg = createMessage(MISSING_TABLE",new String[]{databaseName, tableName},e);
  msg.setNodeValue("extrainfo","extra info .....");
  p.setCC(12); // That will tell the Processs Manager the execution of the processes was not OK.
 


createMessage

public ADOMNode createMessage(java.lang.Exception exception)
Creates a new Request ADOM for the message if not already created, composes an message entry from the given Exception object and adds in it. If the Exception object is an instance of a MoreMotionException or a ProcessException this method can extract the message id, arguments and details from it.

If the given exception is or contains a java.sql.SQLException the returned ADOMNode object contains two additional entries athat are "jdbc-error-code" and "jdbc-sql-state".

See Also:
createMessage(String messageID, String[] arguments, Object details)


Copyright © 2002-2008 MOR YAZILIM. All Rights Reserved.