The inserted Java code calls the create method on the session bean, then invokes the method that you specify in the wizard.
Example snippet insertion for calling an session bean service method
public class Test { public void callSessionMethod() { // insert snippet here } }
import java.rmi.RemoteException; import com.ibm.etools.service.locator.ServiceLocatorManager; import sample.RegistrationFacadeHome; import sample.RegistrationFacadeRemote; import javax.ejb.CreateException; public class Test { private final static String STATIC_RegistrationFacadeHome_REF_NAME = "ejb/RegistrationFacade"; private final static Class STATIC_RegistrationFacadeHome_CLASS = RegistrationFacadeHome.class; public void callSessionMethod() { // insert snippet here RegistrationFacadeRemote aRegistrationFacadeRemote = createRegistrationFacadeRemote(); try { Object anObject = aRegistrationFacadeRemote.getPrimaryKey(); } catch (RemoteException ex) { // TODO Auto-generated catch block ex.printStackTrace(); } } protected RegistrationFacadeRemote createRegistrationFacadeRemote() { RegistrationFacadeHome aRegistrationFacadeHome = (RegistrationFacadeHome) ServiceLocatorManager .getRemoteHome(STATIC_RegistrationFacadeHome_REF_NAME, STATIC_RegistrationFacadeHome_CLASS); try { if (aRegistrationFacadeHome != null) return aRegistrationFacadeHome.create(); } catch (CreateException ce) { // TODO Auto-generated catch block ce.printStackTrace(); } catch (RemoteException re) { // TODO Auto-generated catch block re.printStackTrace(); } return null; } }
To insert Java code for calling a session bean service method:
The ServiceLocatorManager class has a static method called setErrorHandler(ServiceLocatorErrorHandler handler) that you can use to specify a specific error handler for error conditions that occur when looking up the home interface. The default handler simply calls printStackTrace() on the exception that is handled.