1 22 package org.jboss.harness; 23 24 import javax.naming.InitialContext ; 25 import javax.naming.NamingException ; 26 import javax.rmi.PortableRemoteObject ; 27 import java.io.InputStream ; 28 import java.util.Properties ; 29 30 36 public class HATestClient 37 { 38 39 public Object lookup(String name, Class className) throws Exception 40 { 41 try 42 { 43 InitialContext jndiContext = new InitialContext (getPropAsResource(HAJNDITestHarness.SIMPLE_CONFIG_SERVER_PROP)); 44 Object ref = jndiContext.lookup(name); 45 return PortableRemoteObject.narrow(ref, className); 46 } 47 catch (NamingException ex) 48 { 49 throw new Exception ("Object is not bound in the context: " + name); 50 } 51 } 52 53 private Properties getPropAsResource(String name) throws Exception 54 { 55 InputStream is = getClass().getResourceAsStream("/META-INF/" + name); 56 if (is == null) 57 { 58 throw new Exception ("Unable to locate resource: " + name); 59 } 60 Properties confProp = new Properties (); 61 confProp.load(is); 62 return confProp; 63 } 64 65 } 66 | Popular Tags |