1 22 package org.jboss.aop.microcontainer.aspects.jndi; 23 24 import java.util.Properties ; 25 26 import javax.naming.InitialContext ; 27 28 import org.jboss.aop.advice.Interceptor; 29 import org.jboss.aop.joinpoint.Invocation; 30 import org.jboss.aop.joinpoint.MethodInvocation; 31 import org.jboss.kernel.spi.dependency.KernelControllerContext; 32 import org.jboss.logging.Logger; 33 import org.jboss.util.naming.Util; 34 35 44 public class JndiIntroduction implements Interceptor 45 { 46 private static final Logger log = Logger.getLogger(JndiIntroduction.class); 47 private Properties env; 48 49 public String getName() 50 { 51 return getClass().getName(); 52 } 53 54 58 public Properties getEnv() 59 { 60 return env; 61 } 62 63 67 public void setEnv(Properties env) 68 { 69 this.env = env; 70 } 71 72 76 public Object invoke(Invocation invocation) throws Throwable 77 { 78 MethodInvocation mi = (MethodInvocation) invocation; 79 KernelControllerContext context = (KernelControllerContext) mi.getArguments()[0]; 80 81 boolean trace = log.isTraceEnabled(); 82 JndiBinding bindingInfo = (JndiBinding) invocation.resolveClassAnnotation(JndiBinding.class); 83 if( trace ) 84 log.trace("Checking method: "+mi.getMethod()+", bindingInfo: "+bindingInfo); 85 if ("setKernelControllerContext".equals(mi.getMethod().getName()) && bindingInfo != null) 87 { 88 InitialContext ctx = new InitialContext (env); 89 Object target = context.getTarget(); 90 Util.bind(ctx, bindingInfo.name(), target); 91 if( trace ) 92 log.trace("Bound to: "+bindingInfo.name()); 93 String [] aliases = bindingInfo.aliases(); 94 if( aliases != null ) 95 { 96 for(String name : aliases) 97 { 98 Util.bind(ctx, name, target); 99 if( trace ) 100 log.trace("Bound to alias: "+bindingInfo.name()); 101 } 102 } 103 } 104 else if( bindingInfo != null ) 106 { 107 InitialContext ctx = new InitialContext (env); 108 Util.unbind(ctx, bindingInfo.name()); 109 if( trace ) 110 log.trace("Unbound: "+bindingInfo.name()); 111 String [] aliases = bindingInfo.aliases(); 112 if( aliases != null ) 113 { 114 for(String name : aliases) 115 { 116 Util.unbind(ctx, name); 117 if( trace ) 118 log.trace("Unbound alias: "+bindingInfo.name()); 119 } 120 } 121 } 122 else if ( trace ) 123 { 124 log.trace("Ignoring null binding info"); 125 } 126 127 return null; 128 } 129 130 } 131 | Popular Tags |