1 package Jt.ejb.examples; 2 3 import Jt.*; 4 import Jt.examples.*; 5 import Jt.jndi.*; 6 import java.io.*; 7 import Jt.ejb.*; 8 import Jt.ejb.examples.bmp.*; 9 10 11 15 public class RemoteBusinessObject extends JtObject { 16 17 JtJNDIAdapter jndiAdapter = null; 18 MemberLocalHome memberLocalHome = null; 19 boolean realized = false; 20 MemberLocal memberLocal = null; 21 String firstname, lastname; 22 23 24 25 public void setFirstname (String newFirstname) { 26 firstname = newFirstname; 27 } 28 29 public String getFirstname() { 30 return firstname; 31 } 32 33 public void setLastname (String newLastname) { 34 lastname = newLastname; 35 } 36 37 public String getLastname() { 38 return lastname; 39 } 40 41 44 45 public Object processMessage (Object event) { 46 47 String msgid = null; 48 JtMessage e = (JtMessage) event; 49 Object content; 50 51 if (e == null) 52 return null; 53 54 msgid = (String ) e.getMsgId (); 55 56 if (msgid == null) 57 return null; 58 59 content = e.getMsgContent(); 61 62 63 if (msgid.equals ("DISABLE")) { 64 if (!realized) { 65 realized = true; 66 realize (); 67 } 68 69 return (disable ((String ) content)); 70 } 71 72 73 if (msgid.equals ("DELETE")) { 74 if (!realized) { 75 realized = true; 76 realize (); 77 } 78 79 return (delete ((String ) content)); 80 } 81 82 if (msgid.equals ("CREATE")) { 83 if (!realized) { 84 realized = true; 85 realize (); 86 } 87 88 return (create ((String ) content, firstname, lastname)); 89 } 90 91 if (msgid.equals ("JtFIND")) { 92 if (!realized) { 93 realized = true; 94 realize (); 95 } 96 return (find ((String ) content)); 97 } 98 99 if (msgid.equals ("MODIFY")) { 100 if (!realized) { 101 realized = true; 102 realize (); 103 } 104 105 return (modify (e)); 106 } 107 108 109 return (super.processMessage (event)); 111 } 112 113 114 void realize () { 115 116 JtFactory main = new JtFactory (); JtMessage msg = new JtMessage ("JtLOOKUP"); 118 119 jndiAdapter = (JtJNDIAdapter) createObject ("Jt.jndi.JtJNDIAdapter", "jndiAdapter"); 120 121 msg.setMsgContent ("LocalBMPEntityExample"); 122 123 memberLocalHome = (MemberLocalHome) main.sendMessage (jndiAdapter, msg); 124 125 } 126 127 private Object disable (String email) { 128 129 130 if (find (email) == null) { 131 return (null); 132 } 133 memberLocal.setStatus (-1); 134 135 return (null); 136 137 138 } 139 140 141 142 private Object create (String email, String firstname, String lastname) { 143 144 145 String reply = null; 147 148 if (memberLocalHome == null) { 149 handleError ("Local Home Interface is null"); 150 return (null); 151 } 152 153 memberLocal = null; 154 155 try { 156 157 memberLocal = memberLocalHome.create (email, firstname, lastname); 158 159 160 if (memberLocal == null) 161 return (null); 162 176 reply = "OK"; 177 } catch (Exception ex) { 178 handleException (ex); 179 } 180 return (reply); 181 182 } 183 184 185 private Object delete (String email) { 186 187 188 String reply = null; 191 192 193 if (memberLocalHome == null) { 194 handleError ("Local Home Interface is null"); 195 return (null); 196 } 197 198 memberLocal = null; 199 200 try { 201 202 memberLocal = memberLocalHome.findByPrimaryKey (email); 203 204 if (memberLocal != null) 205 memberLocal.remove (); 206 207 reply = "OK"; 208 } catch (Exception ex) { 209 handleException (ex); 210 } 211 return (reply); 212 213 } 214 215 216 217 private Object modify (JtMessage imsg) { 218 219 220 String reply = null; 223 String email; 224 String tmp; 225 JtMessage msg; 226 JtValueObject valueObject; 227 228 if (imsg == null) 229 return (null); 230 231 email = (String ) imsg.getMsgContent (); 232 valueObject = (JtValueObject) imsg.getMsgData (); 233 234 if (email == null || valueObject == null) 235 return (null); 236 237 if (memberLocalHome == null) { 238 handleError ("Local Home Interface is null"); 239 return (null); 240 } 241 242 memberLocal = null; 243 244 249 251 try { 252 253 memberLocal = memberLocalHome.findByPrimaryKey (email); 254 255 if (memberLocal == null) 256 return (null); 257 272 memberLocal.setValueObject (valueObject); 273 reply = "OK"; 274 } catch (Exception ex) { 275 handleException (ex); 276 } 277 return (reply); 278 279 } 280 281 private Object find (String email) { 282 283 284 JtValueObject member = null; 286 287 288 if (memberLocalHome == null) { 289 handleError ("find: Local Home Interface is null"); 290 return (null); 291 } 292 293 memberLocal = null; 294 295 try { 296 297 memberLocal = memberLocalHome.findByPrimaryKey (email); 298 299 300 if (memberLocal == null) { 301 handleError ("find: findByPrimaryKey failed"); 302 return (null); 303 } 304 318 member = (JtValueObject) memberLocal.getValueObject (); 319 320 321 } catch (javax.ejb.FinderException fe) { 322 323 handleException (fe); 324 } catch (Exception ex) { 325 handleException (ex); 326 } 327 return (member); 328 329 } 330 331 332 } 333 334 335 336 | Popular Tags |