正在加载图片...
oublicvoidsessioncreated(httpsessionEventse)i Httpsession session=se. getsessiono /產生服務連結容器 sl= ServiceLocator. getInstanceo /腐本 Listener存入 Session session.setAttribute( WebKeys COMPONENT MANAGER, this) ServiceLacator. java,原始碼在 Petstore homesrclcomponents\servicelocatorlsrcIcom\sun j2eeblueprintsserviceloca torlweb’此類別寫法滿特別的大家又可多學種程式設計技巧·追縱前輩原始 碼·除了能夠了解各種功能如何設計之外’程式碼分解( Refactor丶撰寫風格 設計技巧·對我們來說都是很重要的收穫! Servicelacator基本上它是一個BJB 及JMS資源連結服務提供者·且它的服務不因使用者不同而有所改變,所以它 使用 static寫法來達到這個效果。 public class ServiceLocator i private InitialContext ic; private Map cache; //used to hold references to EJBHomes/JMS Resources for private static Servicelocator me /初次宣告此物件時會執行初始化動作 me = new Servicelocator(; i catch(ServiceLocator Exception se)( System. err println(se); seprintStackTrace(System. err); /建構子產生JNDI連結及同步化 Hash Map容器 private ServicelocatorO throws ServiceLocator Exception ic= new InitialContexto cache= Collections. synchronizedMap(new HashMapo); i catch(Naming Exception ne)ipublic void sessionCreated(HttpSessionEvent se) { HttpSession session = se.getSession(); //產生服務連結容器 sl = ServiceLocator.getInstance(); //將本 Listener 存入 Session session.setAttribute(WebKeys.COMPONENT_MANAGER, this); } ServiceLacator.java,原始碼在 Petstore_home\src\components\servicelocator\src\com\sun\j2ee\blueprints\serviceloca tor\web,此類別寫法滿特別的,大家又可多學一種程式設計技巧,追縱前輩原始 碼,除了能夠了解各種功能如何設計之外,程式碼分解(Refactor)、撰寫風格、 設計技巧,對我們來說都是很重要的收穫!ServiceLacator 基本上它是一個 EJB 及 JMS 資源連結服務提供者,且它的服務不因使用者不同而有所改變,所以它 使用 static 寫法來達到這個效果。 public class ServiceLocator { private InitialContext ic; private Map cache; //used to hold references to EJBHomes/JMS Resources for //re-use private static ServiceLocator me; //初次宣告此物件時會執行初始化動作 static { try { me = new ServiceLocator(); } catch(ServiceLocatorException se) { System.err.println(se); se.printStackTrace(System.err); } } //建構子,產生 JNDI 連結及同步化 HashMap 容器 private ServiceLocator() throws ServiceLocatorException { try { ic = new InitialContext(); cache = Collections.synchronizedMap(new HashMap()); } catch (NamingException ne) {
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有