挿入された Java コードは、セッション Bean 上の create メソッドを呼び出して、次にウィザードで指定されたメソッドを呼び出します。
セッション Bean サービス・メソッドを呼び出す断片の挿入例:
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;
}
}
ServiceLocatorManager クラスには、setErrorHandler (ServiceLocatorErrorHandler ハンドラー) と呼ばれる静的メソッドがあります。 このメソッドを使用すると、ホーム・インターフェースをルックアップするときに発生するエラー条件に対して、 特定のエラー・ハンドラーを指定できます。デフォルトのハンドラーは、処理される例外について printStackTrace() を呼び出すだけです。