KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > stateless > StatelessLocalProxy


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.ejb3.stateless;
23
24 import javax.ejb.EJBException JavaDoc;
25
26 import java.lang.reflect.Method JavaDoc;
27 import java.lang.reflect.Proxy JavaDoc;
28 import org.jboss.aspects.asynch.AsynchMixin;
29 import org.jboss.aspects.asynch.AsynchProvider;
30 import org.jboss.aspects.asynch.FutureHolder;
31 import org.jboss.ejb3.Container;
32 import org.jboss.ejb3.LocalProxy;
33 import org.jboss.ejb3.ProxyUtils;
34
35 /**
36  * Comment
37  *
38  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
39  * @version $Revision: 41398 $
40  */

41 public class StatelessLocalProxy extends LocalProxy
42 {
43    AsynchProvider provider;
44
45    public StatelessLocalProxy()
46    {
47    }
48
49    public StatelessLocalProxy(Container container)
50    {
51       super(container);
52    }
53
54    public StatelessLocalProxy(AsynchProvider provider, Container container)
55    {
56       super(container);
57       this.provider = provider;
58    }
59
60    public Object JavaDoc invoke(Object JavaDoc proxy, Method JavaDoc method, Object JavaDoc[] args)
61            throws Throwable JavaDoc
62    {
63       if (method.getDeclaringClass() == AsynchProvider.class)
64       {
65          return provider.getFuture();
66       }
67
68       Object JavaDoc ret = ProxyUtils.handleCallLocally(proxy, this, method, args);
69       if (ret != null)
70       {
71          return ret;
72       }
73       
74       if (container == null)
75          throw new EJBException JavaDoc("Invalid invocation of local interface (null container)");
76
77       StatelessContainer stateless = (StatelessContainer) container;
78
79       return stateless.localInvoke(method, args, (FutureHolder) provider);
80    }
81
82    public Object JavaDoc getAsynchronousProxy(Object JavaDoc proxy)
83    {
84       Class JavaDoc[] infs = proxy.getClass().getInterfaces();
85       if (!ProxyUtils.isAsynchronous(infs))
86       {
87          Class JavaDoc[] interfaces = ProxyUtils.addAsynchProviderInterface(infs);
88          AsynchMixin mixin = new AsynchMixin();
89          StatelessLocalProxy handler = new StatelessLocalProxy(mixin, container);
90          return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), interfaces, handler);
91       }
92
93       //I was already asynchronous
94
return proxy;
95    }
96 /*
97    @Override
98    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
99    {
100       super.readExternal(in);
101       provider = (AsynchProvider)in.readObject();
102    }
103
104    @Override
105    public void writeExternal(ObjectOutput out) throws IOException
106    {
107       super.writeExternal(out);
108       out.writeObject(provider);
109    }
110 */

111
112    public String JavaDoc toString()
113    {
114       return container.getEjbName().toString();
115    }
116 }
117
Popular Tags