1 7 package org.jboss.jms.container; 8 9 import java.lang.reflect.InvocationHandler ; 10 import java.lang.reflect.Method ; 11 import java.lang.reflect.Proxy ; 12 import java.util.Collections ; 13 import java.util.HashSet ; 14 import java.util.Set ; 15 16 import javax.jms.JMSException ; 17 18 import org.jboss.aop.Advised; 19 import org.jboss.aop.InstanceAdvisor; 20 import org.jboss.aop.MethodInfo; 21 import org.jboss.aop.advice.Interceptor; 22 import org.jboss.aop.joinpoint.Invocation; 23 import org.jboss.aop.joinpoint.MethodInvocation; 24 import org.jboss.aop.metadata.MetaDataResolver; 25 import org.jboss.aop.metadata.SimpleMetaData; 26 27 33 public class Container implements InvocationHandler 34 { 35 37 39 protected Interceptor[] interceptors; 40 41 protected SimpleMetaData metadata = new SimpleMetaData(); 42 43 46 private Object proxy; 47 48 51 private Container parent; 52 53 56 private Set children = Collections.synchronizedSet(new HashSet ()); 57 58 60 67 public static Container getContainer(Object object) 68 throws Throwable 69 { 70 Proxy proxy = (Proxy ) object; 71 return (Container) Proxy.getInvocationHandler(proxy); 72 } 73 74 80 public static Container getContainer(Invocation invocation) 81 { 82 return (Container) invocation.getMetaData("JMS", "Container"); 83 } 84 85 91 public static Object getProxy(Invocation invocation) 92 { 93 return getContainer(invocation).getProxy(); 94 } 95 96 98 105 public Container(Container parent, Interceptor[] interceptors, SimpleMetaData metadata) 106 throws JMSException 107 { 108 this.interceptors = interceptors; 109 this.parent = parent; 110 if (metadata != null) 111 this.metadata = metadata; 112 this.metadata.addMetaData("JMS", "Container", this); 113 114 if (parent != null) 115 parent.children.add(this); 116 } 117 118 120 public Object getProxy() 121 { 122 return proxy; 123 } 124 125 public void setProxy(Object proxy) 126 { 127 this.proxy = proxy; 128 } 129 130 public Container getParent() 131 { 132 return parent; 133 } 134 135 public Set getChildren() 136 { 137 return children; 138 } 139 140 public void addChild(Container child) 141 { 142 children.add(child); 143 } 144 145 public void removeChild(Container child) 146 { 147 children.remove(child); 148 } 149 150 public Object invoke (Invocation invocation) 151 throws Throwable 152 { 153 try 156 { 157 return invocation.invokeNext(interceptors); 158 } 159 finally 160 { 161 } 163 } 164 165 public Object invoke(Object proxy, Method method, Object [] args) throws Throwable 166 { 167 MethodInfo info = new MethodInfo(); 168 MethodInvocation invocation = new MethodInvocation(info, interceptors); 169 return invocation.invokeNext(); 173 } 174 175 177 179 181 } 183 | Popular Tags |