1 package hero.session; 2 3 import hero.interfaces.BnUserLocal; 4 import hero.interfaces.BnUserLocalHome; 5 import hero.interfaces.BnUserUtil; 6 import hero.interfaces.UserRegistrationLocal; 7 import hero.interfaces.UserRegistrationLocalHome; 8 import hero.interfaces.UserRegistrationUtil; 9 import hero.util.HeroException; 10 import hero.user.UserBase; 11 import hero.user.UserBaseException; 12 import hero.user.UserBaseService; 13 14 import java.rmi.RemoteException ; 15 import java.util.ArrayList ; 16 import java.util.Collection ; 17 import java.util.Iterator ; 18 import java.util.Map ; 19 20 import javax.ejb.CreateException ; 21 import javax.ejb.FinderException ; 22 import javax.ejb.SessionBean ; 23 import javax.ejb.SessionContext ; 24 25 26 44 45 public class UserServiceBean implements SessionBean { 46 SessionContext mContext; 47 48 56 public void ejbCreate() throws CreateException { 57 } 58 59 64 public BnUserLocal findUserLocal(String name) throws HeroException { 65 BnUserLocalHome uHome; 66 try { 67 uHome=BnUserUtil.getLocalHome(); 68 } catch (javax.naming.NamingException ne) { 69 throw new HeroException(ne.getMessage()); 70 } 71 72 try { 73 return(uHome.findByName(name)); 74 } catch (FinderException f){ 75 return(registerUser(name)); 76 } 77 } 78 79 84 public BnUserLocal findUser(String name) throws HeroException { 85 BnUserLocalHome uHome; 86 try { 87 uHome=BnUserUtil.getLocalHome(); 88 } catch (javax.naming.NamingException ne) { 89 throw new HeroException(ne.getMessage()); 90 } 91 try { 92 findUserInBase(name); 93 return(uHome.findByName(name)); 94 } catch (Exception f){ 95 return(registerUser(name)); 96 } 97 } 98 99 104 public Collection findUsers() throws HeroException { 105 BnUserLocalHome uHome; 106 try { 107 uHome=BnUserUtil.getLocalHome(); 108 } catch (javax.naming.NamingException ne) { 109 throw new HeroException(ne.getMessage()); 110 } 111 try { 112 return(findUsersInBase()); 113 } catch (Exception f){ 114 throw new HeroException(f.getMessage()); 115 } 116 } 117 118 123 public Map getUserInfos(String name) throws HeroException { 124 return(findUserInBase(name)); 125 } 126 127 private Map findUserInBase(String id) throws HeroException{ 128 Collection ucol=UserBaseService.getInstance().getUserBases(); 129 Iterator i=ucol.iterator(); 130 Map uinfos=null; 131 while (i.hasNext()) { 132 UserBase ub=(UserBase)i.next(); 133 try { 134 uinfos=ub.getUserInfos(id); 135 break; 136 } catch (UserBaseException u) { 137 throw new HeroException(u.getMessage()); 138 } 139 } 140 return uinfos; 141 } 142 143 private Collection findUsersInBase() throws HeroException{ 144 Collection ucol=UserBaseService.getInstance().getUserBases(); 145 Iterator i=ucol.iterator(); 146 Collection uinfos = new ArrayList (); 147 while (i.hasNext()) { 148 UserBase ub=(UserBase)i.next(); 149 try { 150 uinfos=ub.getUsers(); 151 break; 152 } catch (UserBaseException u) { 153 throw new HeroException(u.getMessage()); 154 } 155 } 156 return uinfos; 157 } 158 159 private BnUserLocal registerUser(String name) throws HeroException { 160 try{ 161 UserRegistrationLocalHome urh=UserRegistrationUtil.getLocalHome(); 162 UserRegistrationLocal ur=urh.create(); 163 return(ur.userCreate(name)); 164 }catch(Exception e){throw new HeroException(e.getMessage());} 165 166 } 167 168 171 public void setSessionContext(javax.ejb.SessionContext context) 172 throws RemoteException { 173 this.mContext = context; 174 } 175 178 public void unsetSessionContext() throws RemoteException { 179 } 180 183 public void ejbRemove() throws java.rmi.RemoteException { 184 } 185 188 public void ejbActivate() throws java.rmi.RemoteException { 189 } 190 193 public void ejbPassivate() throws java.rmi.RemoteException { 194 } 195 } | Popular Tags |