Akashic Records

Getting all EJB home interface object from a HashMap 본문

오래된글/Articles

Getting all EJB home interface object from a HashMap

Andrew's Akashic Records 2018. 4. 19. 15:03
728x90

public class SingleHome{

 private String ref="java:comp/env/ejb";

 //EJB reference name use ejb/remote interface name

 private static HashMap homeMap;

 private SingleHome(){}

 

 public static SingleHome getSingleHome(){

   if (homeMap==null){

     homeMap=new HashMap();

   }

   return SingleHome();

 }


 public Object getDestHome(String remoteInterfaceName){

   String strLookup="ref"+remoteInterfaceName;

   String strClass=remoteInterfaceName+"Home";

   if (homeMap.containsKey(remoteInterfaceName))

     return homeMap.get(remoteInterfaceName);

   else {

     try{

       Context ctx=new InitialContext();

       Object obj=ctx.lookup(strLookup);

       Class clss=Class.forName(strClass);

       Object home=PortableRemoteObject.narrow(obj,clss);

     }catch (Exception e) {

       System.out.println(e.getMessage());

       System.out.println("you must guaranty EJB remote interface name as parameter.");

     }

     homemap.put(remoteInterfaceName,home);

     return home;

   }

}



//A class to invoke business methods in remote interface object


public class ABC{

...


SingleHome sHome=SingleHome.getSingleHome();

XXX eHome=(XXX)sHome.sHome.getDestHome("YYY");

//XXX is home interface name, YYY is remote interface name

//Getting remote interface object with mothods in home interface object

...


}


http://www.theserverside.com/patterns/thread.tss?thread_id=24494


728x90

'오래된글 > Articles' 카테고리의 다른 글

당신의 개발팀에 동기부여하는 5가지 방법  (0) 2018.04.19
Android Inter-App Communication  (0) 2018.04.19
안정성 패턴  (0) 2018.04.19
Android Thread 내에서 UI 핸들링  (0) 2018.04.19
Java VM Core Dump 분석  (0) 2018.04.19
Comments