Example: Customizing target policies

You can define custom target policies by implementing the TargetPolicy interface and providing a getCommandTarget method appropriate for your application. The TargetableCommandImpl class provides setTargetPolicy and getTargetPolicy methods for managing custom target policies.

Custom target policy

So far, the target of all the commands has been a checking-account entity bean. Suppose that someone introduces a session enterprise bean (MySessionBean) that can also act as a command target. The following code example shows a simple custom policy that sets the target of every command to MySessionBean.

import java.io.*;
import java.util.*;
import java.beans.*;
import com.ibm.websphere.command.*;
public class CustomTargetPolicy implements TargetPolicy, Serializable {
public CustomTargetPolicy {
super();
}
public CommandTarget getCommandTarget(TargetableCommand command) {
CommandTarget = null;
try {
target = (CommandTarget)Beans.instantiate(null,
"com.ibm.sfc.cmd.test.MySessionBean");
}
catch (Exception e) {
e.printStackTrace();
}
}
}

Because commands are implemented as JavaBeans components, using custom target policies requires importing the java.beans package and writing some elementary JavaBeans code. Also, your custom target-policy class must also implement the java.io.Serializable interface.




Subtopics
Example: Using a custom target policy
Related concepts
Targets and target policies
Related tasks
Writing command interfaces
Reference topic Reference topic    

Terms and conditions for information centers | Feedback

Last updatedLast updated: Aug 31, 2013 12:02:36 AM CDT
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=pix&product=was-nd-zos&topic=rcmd_custtargpol
File name: rcmd_custtargpol.html