The examples in the preceding section, Creating and Editing Processor Chains Programmatically, showed how to create processor chains using the default version of the createChain() method. This version of createChain() takes one argument and constructs and returns an object of type atg.service.pipeline.PipelineChain (the default). atg.service.pipeline.PipelineResult will be the object used for that chain’s PipelineResult object.

If you subclass PipelineChain and PipelineResult, you can create a processor chain with your subclass in the same way you create a chain using the default PipelineChain and PipelineResult objects. The only difference is that you need to use another version of the createChain() method. This createChain() method does the same thing, except that it accepts two String arguments. These String arguments identify the classes to be used for the PipelineChain and PipelineResult objects.

Example

This example uses a specialized version of PipelineChain called PipelineMonoChain. This PipelineChain subclass represents a singly linked list, so each PipelineLink object transitions only to a single PipelineLink.

To create the PipelineMonoChain class, the first step is to subclass PipelineChain. The PipelineMonoChain class overrides the following methods in PipelineChain: createLink(), addTransition(), and the two removeTransition() methods.

The subclass’s createLink() method returns PipelineMonoLink, which is a special type of PipelineLink object that only allows a single transition out of it. It extends atg.service.pipeline.PipelineLink. The declaration of createLink() looks like this:

public PipelineMonoLink createLink(String aLinkId, PipelineProcessor aProc,
       PipelineLink aFromLink, int aRetCode)
    throws CreateLinkException, TransitionException

This creates a PipelineMonoLink object instead of a PipelineLink object and returns it to the caller. The main difference is that if aFromLink already has a transition coming out of it, then a TransitionException would be thrown.

In PipelineLink, the TransitionException is thrown if the aRetCode was already mapped in aFromLink. The aRetCode value has a slightly different meaning in PipelineMonoLink. If its value is returned from the PipelineProcessor for that link, then the transition is followed. Otherwise execution on the chain ends and the PipelineResult is returned to the caller.

For PipelineMonoChain to instantiate a PipelineMonoLink, the instantiatePipelineLink method must be overridden to return a new instance of a PipelineLink subclass. The code would look like this:

protected PipelineLink instantiatePipelineLink(String pLinkId) {
    return new PipelineMonoLink(pLinkId);
}

The addTransition() method checks to see if there is a transition coming out of aFromLink. If there is, then a TransitionException is thrown. Otherwise, the link is mapped. Your subclass should include a new version of addTransition() with the following signature:

void addTransition(PipelineMonoLink aFromLink, int aRetCode, PipelineMonoLink
                     aToLink)
    throws TransitionException

This differs from the addTransition() in PipelineLink by the first and third arguments. The type in the method above is PipelineMonoLink, rather than PipelineLink, as in PipelineChain. The addTransition() method in PipelineLink however still exists and has not been overridden. This should be explicitly overridden and the code should throw a TransitionException. This method would only be called if a PipelineLink (or subclass) that is not a PipelineMonoLink were passed as one of the arguments.

The removeTransition() method checks to see if a transition is coming out of aFromLink. If none exists then a TransitionException is thrown. If one does exist then the transition would be removed. Again, new versions of removeTransition() should be added with the following signatures:

void removeTransition(PipelineMonoLink aFromLink, int aRetCode)
    throws TransitionException
void removeTransition(PipelineMonoLink aFromLink, PipelineMonoLink aToLink)
    throws TransitionException

These differ again by the arguments, which provide for PipelineMonoLink objects to be passed as parameters rather than PipelineLink objects. The removeTransition() methods that take PipelineLink objects should again be overridden explicitly and exceptions thrown.

The PipelineMonoLink object needs to extend PipelineLink. New methods that are specific to this implementation need to be defined and the following methods need to be overridden: getNextLink(), getNextLinks(), and getRetCodes(). The PipelineMonoLink would contain the following methods:

public PipelineMonoLink getNextLink()
public PipelineLink getNextLink(int aRetCode)
public PipelineMonoLink getNextLinks()
public PipelineLink[] getNextLinks(int[] aRetCodes)
public int getRetCode()
public int[] getRetCodes()

Although it takes a return code parameter, getNextLink(intaRetCode) should just return the PipelineMonoLink object that is mapped to the link that called the method. For cleanliness, a getNextLink() method should be defined that takes no arguments and returns a PipelineMonoLink. The inherited getNextLink(int aRetCode) method should just call the one with no arguments and return the PipelineMonoLink object that is cast to a PipelineLink. The getNextLinks(int[]aRetCodes) method should also just call getNextLinks() and ignore the aRetCodes and put the PipelineMonoLink into a PipelineLink array. The int[] getRetCodes() method should again just call getRetCode() and take the return value, insert it into an array and return it.

The example in this section implements a singly linked chain. It overrides PipelineChain and PipelineLink to force the objects to allow each link to have only one transition. The PipelineMonoLink enforces this. The reason PipelineChain is overridden is to create PipelineMonoLink objects rather than PipelineLink objects.

 
loading table of contents...