KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb > plugins > ProxyFactoryFinderInterceptor


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.ejb.plugins;
23
24 import javax.ejb.EJBException JavaDoc;
25
26 import org.jboss.ejb.Interceptor;
27 import org.jboss.invocation.Invocation;
28 import org.jboss.invocation.InvocationKey;
29 import org.jboss.naming.ENCThreadLocalKey;
30
31 /**
32  * This interceptor injects the ProxyFactory into the ThreadLocal container variable
33  *
34  * @author <a HREF="mailto:rickard.oberg@telkel.com">Rickard Öberg</a>
35  * @author <a HREF="mailto:Scott.Stark@jboss.org">Scott Stark</a>
36  * @version $Revision: 37459 $
37  */

38 public class ProxyFactoryFinderInterceptor
39    extends AbstractInterceptor
40 {
41
42    public void create() throws Exception JavaDoc
43    {
44    }
45
46    protected void setProxyFactory(String JavaDoc invokerBinding, Invocation mi) throws Exception JavaDoc
47    {
48       // if (BeanMetaData.LOCAL_INVOKER_PROXY_BINDING.equals(invokerBinding)) return;
49
if (invokerBinding == null)
50       {
51          log.trace("invokerBInding is null in ProxyFactoryFinder");
52          return;
53       }
54       /*
55       if (invokerBinding == null)
56       {
57          log.error("***************** invokerBinding is null ********");
58          log.error("Method name: " + mi.getMethod().getName());
59          log.error("jmx name: " + container.getJmxName().toString());
60          new Throwable().printStackTrace();
61          log.error("*************************");
62          throw new EJBException("Couldn't insert proxy factory, " +
63                "invokerBinding was null");
64       }
65       */

66       Object JavaDoc proxyFactory = container.lookupProxyFactory(invokerBinding);
67       if (proxyFactory == null)
68       {
69          String JavaDoc methodName;
70          if(mi.getMethod() != null) {
71             methodName = mi.getMethod().getName();
72          } else
73          {
74             methodName ="<no method>";
75          }
76
77          log.error("***************** proxyFactory is null ********");
78          log.error("Method name: " + methodName);
79          log.error("jmx name: " + container.getJmxName().toString());
80          log.error("invokerBinding: " + invokerBinding);
81          log.error("Stack trace", new Throwable JavaDoc());
82          log.error("*************************");
83          throw new EJBException JavaDoc("Couldn't find proxy factory");
84       }
85       container.setProxyFactory(proxyFactory);
86    }
87
88    public Object JavaDoc invokeHome(Invocation mi)
89       throws Exception JavaDoc
90    {
91       String JavaDoc invokerBinding =
92             (String JavaDoc)mi.getAsIsValue(InvocationKey.INVOKER_PROXY_BINDING);
93       setProxyFactory(invokerBinding, mi);
94
95       String JavaDoc oldInvokerBinding = ENCThreadLocalKey.getKey();
96       // Only override current ENC binding if we're not local
97
// if ((!BeanMetaData.LOCAL_INVOKER_PROXY_BINDING.equals(invokerBinding)) || oldInvokerBinding == null)
98
if (invokerBinding != null || oldInvokerBinding == null)
99       {
100          ENCThreadLocalKey.setKey(invokerBinding);
101       }
102
103       Interceptor next = getNext();
104       Object JavaDoc value = null;
105       try
106       {
107          value = next.invokeHome(mi);
108       }
109       finally
110       {
111          ENCThreadLocalKey.setKey(oldInvokerBinding);
112       }
113
114       return value;
115    }
116
117    public Object JavaDoc invoke(Invocation mi)
118       throws Exception JavaDoc
119    {
120       String JavaDoc invokerBinding =
121             (String JavaDoc)mi.getAsIsValue(InvocationKey.INVOKER_PROXY_BINDING);
122       setProxyFactory(invokerBinding, mi);
123
124       String JavaDoc oldInvokerBinding = ENCThreadLocalKey.getKey();
125       // Only override current ENC binding if we're not local or there has not been a previous call
126
// if ((!BeanMetaData.LOCAL_INVOKER_PROXY_BINDING.equals(invokerBinding)) || oldInvokerBinding == null)
127
if (invokerBinding != null || oldInvokerBinding == null)
128       {
129          ENCThreadLocalKey.setKey(invokerBinding);
130       }
131
132       Interceptor next = getNext();
133       Object JavaDoc value = null;
134       try
135       {
136          value = next.invoke(mi);
137       }
138       finally
139       {
140          ENCThreadLocalKey.setKey(oldInvokerBinding);
141       }
142
143       return value;
144    }
145
146 }
147
Popular Tags