1 22 package org.jboss.test.naming.interceptors; 23 24 import javax.naming.InitialContext ; 25 import org.jboss.mx.interceptor.AbstractInterceptor; 26 import org.jboss.mx.server.Invocation; 27 import org.jboss.logging.Logger; 28 import org.jnp.interfaces.NamingContext; 29 import org.jnp.interfaces.Naming; 30 31 37 public class ProxyFactoryInterceptor 38 extends AbstractInterceptor 39 { 40 private static Logger log = Logger.getLogger(ProxyFactoryInterceptor.class); 41 private String proxyName; 42 private Naming proxy; 43 44 public void setProxyName(String proxyName) 45 { 46 this.proxyName = proxyName; 47 } 48 49 public Object invoke(Invocation invocation) throws Throwable 51 { 52 String opName = invocation.getName(); 53 log.info("invoke, opName="+opName); 54 Object value = invocation.nextInterceptor().invoke(invocation); 55 if( value instanceof NamingContext ) 56 { 57 initNamingProxy(); 58 NamingContext ctx = (NamingContext) value; 59 ctx.setNaming(proxy); 60 } 61 return value; 62 } 63 64 private void initNamingProxy() 65 throws Throwable 66 { 67 if( proxy != null ) 68 return; 69 70 try 71 { 72 InitialContext ctx = new InitialContext (); 73 proxy = (Naming) ctx.lookup(proxyName); 74 } 75 catch(Exception e) 76 { 77 log.error("Failed to lookup: "+proxyName, e); 78 throw e; 79 } 80 } 81 } 82 | Popular Tags |