1 22 package org.jboss.mx.interceptor; 23 24 import javax.management.MBeanServer ; 25 import javax.management.ObjectName ; 26 27 import org.jboss.logging.Logger; 28 import org.jboss.mx.server.Invocation; 29 30 40 public abstract class AbstractInterceptor 41 implements Interceptor 42 { 43 44 46 49 protected String name = "<no name>"; 50 51 54 protected boolean isShared = false; 55 56 61 protected Logger log; 62 63 64 66 70 public AbstractInterceptor() 71 { 72 log = Logger.getLogger(getClass()); 73 } 74 75 83 public AbstractInterceptor(String name) 84 { 85 if (name == null || name.equals("")) 86 throw new IllegalArgumentException ("null name"); 87 88 this.name = name; 89 90 log = Logger.getLogger(getClass()); 91 } 92 93 94 96 101 public void setName(String name) 102 { 103 this.name = name; 104 } 105 106 107 109 130 public Object invoke(Invocation invocation) throws Throwable 131 { 132 Interceptor ic = invocation.nextInterceptor(); 133 134 if (ic == null) 138 return invocation.dispatch(); 139 140 if (ic.isShared()) 142 { 143 SharedInterceptor shared = (SharedInterceptor)ic; 145 146 MBeanServer server = shared.getMBeanServer(); 149 150 ObjectName name = shared.getObjectName(); 152 153 return server.invoke( 154 name, "invoke", 155 new Object [] { invocation }, new String [] { Invocation.class.getName() } ); 158 } 159 160 else 162 { 163 return ic.invoke(invocation); 164 } 165 } 166 167 public String getName() 168 { 169 return name; 170 } 171 172 public boolean isShared() 173 { 174 return isShared; 175 } 176 177 public void setLogger(Logger log) 178 { 179 this.log = log; 180 } 181 182 public void init() throws Exception {} 183 184 public void start() {} 185 186 public void stop() throws Exception {} 187 188 public void destroy() {} 189 190 191 193 198 public String toString() 199 { 200 String className = getClass().getName(); 201 int index = className.lastIndexOf('.'); 202 203 return className.substring((index < 0) ? 0 : index) + "[name=" + name + "]"; 204 } 205 } 206 207 208 | Popular Tags |