KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.lang.reflect.InvocationTargetException JavaDoc;
25 import javax.ejb.LocalHome JavaDoc;
26 import org.jboss.annotation.ejb.LocalBinding;
27 import org.jboss.ejb3.JBossProxy;
28 import org.jboss.ejb3.NonSerializableFactory;
29 import org.jboss.ejb3.ProxyFactoryHelper;
30
31
32 /**
33  * Comment
34  *
35  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
36  * @version $Revision: 56518 $
37  */

38 public class StatelessLocalProxyFactory extends BaseStatelessProxyFactory
39 {
40    protected Class JavaDoc[] getInterfaces()
41    {
42       Class JavaDoc[] interfaces;
43
44       Class JavaDoc[] localInterfaces = ProxyFactoryHelper.getLocalInterfaces(container);
45       StatelessContainer statelessContainer = (StatelessContainer) container;
46       interfaces = new Class JavaDoc[localInterfaces.length + 2];
47
48       System.arraycopy(localInterfaces, 0, interfaces, 0, localInterfaces.length);
49       interfaces[localInterfaces.length] = JBossProxy.class;
50       interfaces[localInterfaces.length + 1] = javax.ejb.EJBLocalObject JavaDoc.class;
51
52       return interfaces;
53    }
54
55    protected void initializeJndiName()
56    {
57       jndiName = ProxyFactoryHelper.getLocalJndiName(container);
58    }
59
60    @Override JavaDoc
61    public void start() throws Exception JavaDoc
62    {
63       super.start();
64       StatelessContainer statelessContainer = (StatelessContainer) container;
65       LocalHome JavaDoc localHome = (LocalHome JavaDoc) statelessContainer.resolveAnnotation(LocalHome JavaDoc.class);
66       if (localHome != null)
67       {
68          Class JavaDoc[] interfaces = {localHome.value()};
69          Object JavaDoc homeProxy = java.lang.reflect.Proxy.newProxyInstance(container.getBeanClass().getClassLoader(),
70                                                                      interfaces, new StatelessLocalProxy(container));
71          NonSerializableFactory.rebind(container.getInitialContext(), jndiName + "Home", homeProxy);
72       }
73    }
74
75    @Override JavaDoc
76    public void stop() throws Exception JavaDoc
77    {
78       super.stop();
79       StatelessContainer statelessContainer = (StatelessContainer) container;
80       LocalHome JavaDoc localHome = (LocalHome JavaDoc) statelessContainer.resolveAnnotation(LocalHome JavaDoc.class);
81       if (localHome != null)
82       {
83          NonSerializableFactory.unbind(container.getInitialContext(), jndiName + "Home");
84       }
85    }
86
87
88    public Object JavaDoc createProxy()
89    {
90       /*
91       try
92       {
93          Object[] args = {new StatelessLocalProxy(container)};
94          return proxyConstructor.newInstance(args);
95       }
96       catch (InstantiationException e)
97       {
98          throw new RuntimeException(e); //To change body of catch statement use Options | File Templates.
99       }
100       catch (IllegalAccessException e)
101       {
102          throw new RuntimeException(e); //To change body of catch statement use Options | File Templates.
103       }
104       catch (IllegalArgumentException e)
105       {
106          throw new RuntimeException(e); //To change body of catch statement use Options | File Templates.
107       }
108       catch (InvocationTargetException e)
109       {
110          throw new RuntimeException(e.getTargetException()); //To change body of catch statement use Options | File Templates.
111       }
112       */

113       return constructProxy(new StatelessLocalProxy(container));
114    }
115
116    protected StatelessHandleImpl getHandle()
117    {
118       StatelessHandleImpl handle = new StatelessHandleImpl();
119       LocalBinding remoteBinding = (LocalBinding) advisor.resolveAnnotation(LocalBinding.class);
120       if (remoteBinding != null)
121          handle.jndiName = remoteBinding.jndiBinding();
122
123       return handle;
124    }
125
126 }
127
Popular Tags