KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > service > ServiceLocalProxy


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.service;
23
24 import java.lang.reflect.Method JavaDoc;
25 import java.lang.reflect.Proxy JavaDoc;
26 import java.io.ObjectInput JavaDoc;
27 import java.io.IOException JavaDoc;
28 import java.io.ObjectOutput JavaDoc;
29 import org.jboss.aspects.asynch.AsynchMixin;
30 import org.jboss.aspects.asynch.AsynchProvider;
31 import org.jboss.aspects.asynch.FutureHolder;
32 import org.jboss.ejb3.Container;
33 import org.jboss.ejb3.JBossProxy;
34 import org.jboss.ejb3.LocalProxy;
35 import org.jboss.ejb3.ProxyUtils;
36
37 /**
38  * @author <a HREF="mailto:kabir.khan@jboss.org">Kabir Khan</a>
39  * @version $Revision: 43261 $
40  */

41 public class ServiceLocalProxy extends LocalProxy
42 {
43    AsynchProvider provider;
44
45    public ServiceLocalProxy()
46    {
47    }
48
49    public ServiceLocalProxy(Container container)
50    {
51       super(container);
52    }
53
54    public ServiceLocalProxy(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((JBossProxy) proxy, this, method, args);
69       if (ret != null)
70       {
71          return ret;
72       }
73
74       ServiceContainer sc = (ServiceContainer) container;
75       return sc.localInvoke(method, args, (FutureHolder) provider);
76    }
77
78    public Object JavaDoc getAsynchronousProxy(Object JavaDoc proxy)
79    {
80       Class JavaDoc[] infs = proxy.getClass().getInterfaces();
81       if (!ProxyUtils.isAsynchronous(infs))
82       {
83          Class JavaDoc[] interfaces = ProxyUtils.addAsynchProviderInterface(infs);
84          AsynchMixin mixin = new AsynchMixin();
85          ServiceLocalProxy handler = new ServiceLocalProxy(mixin, container);
86          return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), interfaces, handler);
87       }
88
89       //I was already asynchronous
90
return proxy;
91    }
92
93    //@Override
94
public void readExternal(ObjectInput JavaDoc in) throws IOException JavaDoc, ClassNotFoundException JavaDoc
95    {
96       super.readExternal(in);
97       provider = (AsynchProvider)in.readObject();
98    }
99
100    //@Override
101
public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc
102    {
103       super.writeExternal(out);
104       out.writeObject(provider);
105    }
106
107    public String JavaDoc toString()
108    {
109       return container.getEjbName().toString();
110    }
111
112 }
113
Popular Tags