Locale locale =
I18nUtil.getLocaleFromString(profile.getPreferredLanguage());
session.setAttribute(PetstoreKeys.LOCALE, locale);
}
}
}
以下略...
SignOnNotifier会透过PetstoreComponentManager取得ShoppingClientFacade
reference,ShoppingClientFacade是Petstore在EJB tier的代理接口,Web tier所
有Request均需透过它来存取所需资料,这个Design Pattern的好处是可以降低EJB tier与Web tier间的藕合性,将商业逻辑集中控管在EJB tier。
PetstoreComponentManager,源码在
D:\petstore1.3.1\src\apps\petstore\src\com\sun\j2ee\blueprints\petstore\controller\web\
PetstoreComponentManager.java,约110列:
public CustomerLocal getCustomer(HttpSession session) {
ShoppingControllerLocal scEjb = getShoppingController(session);
try {
//取得ShoppingClientFacade reference
ShoppingClientFacadeLocal scf = scEjb.getShoppingClientFacade();
//scf.setUserId(userId);
//取得CustomerLocal reference
return scf.getCustomer();
} catch (FinderException e) {
System.err.println("PetstoreComponentManager finder error: " + e);
} catch (Exception e) {
System.err.println("PetstoreComponentManager error: " + e);
}
return null;
}
ShoppingClientFacadeLocalEJB为Session Bean,源码在
D:\petstore1.3.1\src\apps\petstore\src\com\sun\j2ee\blueprints\petstore\controller\ejb\
ShoppingClientFacadeLocalEJB.java,约101列:
/*
* Asume that the customer userId has been set
*/
public CustomerLocal getCustomer() throws FinderException {
//请加入侦察码
System.out.println("ShoppingClientFacadeLocalEJB.getCustomer()");
if (userId == null) {
throw new GeneralFailureException("ShoppingClientFacade: failed to look
up name of customer: userId is not set" );
}
try {
ServiceLocator sl = new ServiceLocator();
CustomerLocalHome home =(CustomerLocalHome)
sl.getLocalHome(JNDINames.CUSTOMER_EJBHOME);
customer = home.findByPrimaryKey(userId);
} catch (ServiceLocatorException slx) {
throw new GeneralFailureException("ShoppingClientFacade: failed to look
up name of customer: caught " + slx);
}
return customer;
}
CustomerEJB为Entity Bean,它与AccountEJB有一对一关系,AccountEJB也与ContactInfoEJB有一对一关系,三者皆为Entity Bean,直接对应资料库资料表CustomerEJBTable, AccountEJBTable, ContactInfoEJBTable,源码在D:\petstore1.3.1\src\components\customer\src\com\sun\j2ee\blueprints\customer\