1 27 package olstore.framework; 28 29 30 import java.util.Collections; 31 import java.util.HashMap; 32 import java.util.Map; 33 34 import javax.ejb.EJBLocalHome; 35 import javax.naming.Context; 36 import javax.naming.InitialContext; 37 import javax.naming.NamingException; 38 39 import olstore.entity.AddressUtil; 40 import olstore.entity.FriendUtil; 41 import olstore.entity.ItemUtil; 42 import olstore.entity.OrderUtil; 43 import olstore.entity.PictureUtil; 44 import olstore.entity.PropertyUtil; 45 import olstore.entity.TypeUtil; 46 import olstore.entity.UserUtil; 47 import olstore.session.ShoppingCartUtil; 48 import olstore.session.helper.ItemHelperUtil; 49 import olstore.session.helper.TypeHelperUtil; 50 import olstore.session.helper.UserHelperUtil; 51 52 55 public class EJBHomeFactory { 56 private Map homes; 57 private static EJBHomeFactory factory; 58 private Context context; 59 60 private static final String NAMESPACE = "java:comp/env/ejb/"; 61 62 public static final String ITEM = NAMESPACE + "ItemLocal"; 63 public static final String ITEM_HELPER = NAMESPACE + "ItemHelperLocal"; 64 public static final String TYPE_HELPER = NAMESPACE + "TypeHelperLocal"; 65 public static final String PROP = NAMESPACE + "PropertyLocal"; 66 public static final String PIC = NAMESPACE + "PictureLocal"; 67 public static final String TYPE = NAMESPACE + "TypeLocal"; 68 public static final String USER = NAMESPACE + "UserLocal"; 69 public static final String FRIENDS = NAMESPACE + "FriendLocal"; 70 public static final String ORDER = NAMESPACE + "OrderLocal"; 71 public static final String ADDRESS=NAMESPACE + "AddressLocal"; 72 73 public static final String USER_HELPER= NAMESPACE+"UserHelperLocal"; 74 public static final String SHOPPINGCART= NAMESPACE+ "ShoppingCartLocal"; 75 76 77 78 81 private EJBHomeFactory() throws NamingException { 82 homes = Collections.synchronizedMap ( new HashMap() ); 83 context = new InitialContext (); 84 } 85 86 89 public static EJBHomeFactory getInstance() throws NamingException { 90 if ( factory == null ) { 91 factory = new EJBHomeFactory(); 92 } 93 return factory; 94 } 95 96 99 public EJBLocalHome getLocalHome ( String jndiName ) throws NamingException { 100 EJBLocalHome home = null; 101 if(jndiName.equals(ITEM)) 102 home = (EJBLocalHome) ItemUtil.getLocalHome(); 103 if(jndiName.equals(ITEM_HELPER)) 104 home = (EJBLocalHome) ItemHelperUtil.getLocalHome(); 105 if(jndiName.equals(TYPE_HELPER)) 106 home = (EJBLocalHome) TypeHelperUtil.getLocalHome(); 107 if(jndiName.equals(PROP)) 108 home = (EJBLocalHome) PropertyUtil.getLocalHome(); 109 if(jndiName.equals(PIC)) 110 home = (EJBLocalHome) PictureUtil.getLocalHome(); 111 if(jndiName.equals(TYPE)) 112 home = (EJBLocalHome) TypeUtil.getLocalHome(); 113 if(jndiName.equals(USER)) 114 home = (EJBLocalHome) UserUtil.getLocalHome(); 115 if(jndiName.equals(FRIENDS)) 116 home = (EJBLocalHome) FriendUtil.getLocalHome(); 117 if(jndiName.equals(ORDER)) 118 home = (EJBLocalHome) OrderUtil.getLocalHome(); 119 if(jndiName.equals(ADDRESS)) 120 home = (EJBLocalHome) AddressUtil.getLocalHome(); 121 if(jndiName.equals(USER_HELPER)) 122 home = (EJBLocalHome) UserHelperUtil.getLocalHome(); 123 if(jndiName.equals(SHOPPINGCART)) 124 home = (EJBLocalHome) ShoppingCartUtil.getLocalHome(); 125 126 return home; 132 } 133 } 134 | Popular Tags |