KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > stateful > StatefulHomeRemoteProxy


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.stateful;
23
24 import java.lang.reflect.Method JavaDoc;
25 import javax.ejb.EJBMetaData JavaDoc;
26 import javax.ejb.HomeHandle JavaDoc;
27 import org.jboss.aop.Dispatcher;
28 import org.jboss.aop.advice.Interceptor;
29 import org.jboss.aop.util.MethodHashing;
30 import org.jboss.aop.util.PayloadKey;
31 import org.jboss.aspects.remoting.InvokeRemoteInterceptor;
32 import org.jboss.ejb3.ProxyUtils;
33 import org.jboss.logging.Logger;
34 import org.jboss.remoting.InvokerLocator;
35
36 /**
37  * Comment
38  *
39  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
40  * @version $Revision: 40600 $
41  */

42 public class StatefulHomeRemoteProxy extends org.jboss.ejb3.session.BaseSessionRemoteProxy
43 {
44    private static final Logger log = Logger.getLogger(StatefulHomeRemoteProxy.class);
45
46    protected InvokerLocator uri;
47    private HomeHandle JavaDoc homeHandle;
48    private EJBMetaData JavaDoc ejbMetaData;
49
50    public StatefulHomeRemoteProxy(Object JavaDoc containerId, Interceptor[] interceptors, InvokerLocator uri)
51    {
52       super(containerId, interceptors);
53       this.uri = uri;
54    }
55
56    public StatefulHomeRemoteProxy(Object JavaDoc containerId, Interceptor[] interceptors, InvokerLocator uri, Object JavaDoc id)
57    {
58       super(containerId, interceptors);
59       this.uri = uri;
60       this.id = id;
61    }
62
63    protected StatefulHomeRemoteProxy()
64    {
65    }
66
67    public void setHandle(StatefulHandleImpl handle)
68    {
69       this.handle = handle;
70       handle.id = id;
71    }
72
73    public void setHomeHandle(HomeHandle JavaDoc homeHandle)
74    {
75       this.homeHandle = homeHandle;
76    }
77
78    public void setEjbMetaData(EJBMetaData JavaDoc ejbMetaData)
79    {
80       this.ejbMetaData = ejbMetaData;
81    }
82
83    public Object JavaDoc invoke(Object JavaDoc proxy, Method JavaDoc method, Object JavaDoc[] args)
84            throws Throwable JavaDoc
85    {
86       long hash = MethodHashing.calculateHash(method);
87       Object JavaDoc ret = ProxyUtils.handleCallLocally(hash, proxy, this, method, args);
88       if (ret != null)
89       {
90          return ret;
91       }
92
93       ret = handleEjb21CallLocally(method, args);
94       if (ret != null)
95       {
96          return ret;
97       }
98
99       StatefulRemoteInvocation sri = new StatefulRemoteInvocation(interceptors, hash, method, method, null, null);
100       sri.setArguments(args);
101       sri.setInstanceResolver(metadata);
102       sri.getMetaData().addMetaData(Dispatcher.DISPATCHER, Dispatcher.OID, containerId, PayloadKey.AS_IS);
103       sri.getMetaData().addMetaData(InvokeRemoteInterceptor.REMOTING, InvokeRemoteInterceptor.INVOKER_LOCATOR, uri, PayloadKey.AS_IS);
104       sri.getMetaData().addMetaData(InvokeRemoteInterceptor.REMOTING, InvokeRemoteInterceptor.SUBSYSTEM, "AOP", PayloadKey.AS_IS);
105
106       return sri.invokeNext();
107    }
108
109    public Object JavaDoc getAsynchronousProxy(Object JavaDoc proxy)
110    {
111       throw new RuntimeException JavaDoc("NOT IMPLEMENTED");
112    }
113
114    public String JavaDoc toString()
115    {
116       return containerId.toString() + ":Home";
117    }
118
119    private Object JavaDoc handleEjb21CallLocally(Method JavaDoc method, Object JavaDoc[] args)
120    {
121       if (method.equals(ProxyUtils.GET_HOME_HANDLE))
122       {
123          return homeHandle;
124       }
125       else if (method.equals(ProxyUtils.GET_EJB_METADATA))
126       {
127          return ejbMetaData;
128       }
129
130       return null;
131    }
132 }
133
Popular Tags