1 package Jt.ejb; 2 3 import javax.ejb.*; 4 import javax.naming.*; 5 import java.rmi.*; 6 import java.util.Properties ; 7 import java.util.*; 8 import Jt.*; 9 10 11 14 15 public class JtServiceLocator extends JtObject { 16 17 private String url = "t3://localhost:7001"; private String user = null; 19 private String password = null; 20 private String factory = "weblogic.jndi.WLInitialContextFactory"; private String jndiName = "JtSessionFacade"; Class sclass = JtSessionFacadeHome.class; 24 25 26 30 31 public void setSclass (Class sclass) { 32 this.sclass = sclass; 33 34 } 35 36 37 40 41 42 public Class getSclass () { 43 return (sclass); 44 } 45 46 47 51 52 public void setUrl (String url) { 53 this.url = url; 54 55 } 56 57 60 61 public String getUrl () { 62 return (url); 63 } 64 65 66 70 71 public void setUser (String user) { 72 this.user = user; 73 } 74 75 78 79 public String getUser () { 80 return (user); 81 } 82 83 84 88 89 public void setPassword (String password) { 90 this.password = password; 91 } 92 93 94 97 98 public String getPassword () { 99 return (password); 100 } 101 102 106 107 public void setFactory (String factory) { 108 this.factory = factory; 109 } 110 111 112 115 116 117 public String getFactory () { 118 return (factory); 119 } 120 121 125 126 public void setJndiName (String jndiName) { 127 this.jndiName = jndiName; 128 } 129 130 131 134 135 public String getJndiName () { 136 return (jndiName); 137 } 138 139 140 142 private Object activate () { 143 144 Object dhome = null; 145 147 try { 148 149 Context ctx = getInitialContext(); 150 Object objref = ctx.lookup (jndiName); 152 153 dhome = (Object ) 154 javax.rmi.PortableRemoteObject.narrow (objref, sclass); 155 156 157 } catch (Exception e) { 158 handleException (e); 159 } 160 return (dhome); 161 162 } 163 164 165 private Object test () { 166 167 return (sendMessage (this, new JtMessage ("JtACTIVATE"))); 168 169 } 170 171 179 180 public Object processMessage (Object event) { 181 182 String msgid = null; 183 JtMessage e = (JtMessage) event; 184 Object content; 185 186 if (e == null) 187 return null; 188 189 msgid = (String ) e.getMsgId (); 190 191 if (msgid == null) 192 return null; 193 194 content = e.getMsgContent(); 195 196 198 if (msgid.equals ("JtACTIVATE")) { 199 200 return (activate ()); 201 202 } 203 204 205 if (msgid.equals ("JtTEST")) { 206 207 return (test ()); 208 209 } 210 211 212 if (msgid.equals ("JtREMOVE")) { 213 214 return (null); 215 216 } 217 218 handleError ("JtServiceLocator.processMessage: invalid message id:" + msgid); 219 return (null); 220 221 } 222 223 224 228 229 private Context getInitialContext() throws Exception { 230 Properties p = new Properties (); 231 p.put(Context.INITIAL_CONTEXT_FACTORY, 232 factory); 233 p.put(Context.PROVIDER_URL, url); 234 if (user != null) { 235 p.put(Context.SECURITY_PRINCIPAL, user); 237 if (password == null) 238 password = ""; 239 p.put(Context.SECURITY_CREDENTIALS, password); 240 } 241 return new InitialContext(p); 242 } 243 244 245 248 249 public static void main (String [] args) { 250 JtObject main; 251 JtServiceLocator locator; 252 Object jtservice; 253 255 256 main = new JtObject (); 257 258 259 261 locator = (JtServiceLocator) main.createObject ("Jt.ejb.JtServiceLocator", "locator"); 262 263 265 main.setValue (locator, "jndiName", "JtSessionFacade"); 266 main.setValue (locator, "sclass", JtSessionFacadeHome.class); 267 268 269 271 jtservice = (Object ) main.sendMessage ("locator", new JtMessage ("JtTEST")); 272 273 274 if (jtservice != null) 275 System.out.println ("JtServiceLocator: GO"); 276 else 277 System.out.println ("JtServiceLocator: FAIL"); 278 279 280 282 main.removeObject ("locator"); 283 284 285 } 286 } 287 | Popular Tags |