KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.ejb3.stateless;
8
9 import org.jboss.aop.Advisor;
10 import org.jboss.ejb3.Container;
11 import org.jboss.ejb3.ProxyFactory;
12 import org.jboss.logging.Logger;
13 import org.jboss.naming.Util;
14
15 import javax.naming.Context JavaDoc;
16 import javax.naming.InitialContext JavaDoc;
17
18 import java.lang.reflect.Constructor JavaDoc;
19 import java.lang.reflect.InvocationHandler JavaDoc;
20
21 /**
22  * Comment
23  *
24  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
25  * @version $Revision: 1.3.2.2 $
26  */

27 public abstract class BaseStatelesslProxyFactory implements ProxyFactory
28 {
29    private static final Logger log = Logger.getLogger(BaseStatelesslProxyFactory.class);
30    
31    protected Class JavaDoc proxyClass;
32    protected Constructor JavaDoc proxyConstructor;
33    protected Context JavaDoc proxyFactoryContext;
34    protected String JavaDoc jndiName;
35    protected Container container;
36    protected Advisor advisor;
37    
38    public void init() throws Exception JavaDoc
39    {
40       initializeJndiName();
41       Class JavaDoc[] interfaces = getInterfaces();
42       Class JavaDoc proxyClass = java.lang.reflect.Proxy.getProxyClass(container.getBeanClass().getClassLoader(), interfaces);
43       final Class JavaDoc[] constructorParams =
44       {InvocationHandler JavaDoc.class};
45       proxyConstructor = proxyClass.getConstructor(constructorParams);
46    }
47
48    public void start() throws Exception JavaDoc
49    {
50       init();
51
52       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
53       Object JavaDoc proxy = createProxy();
54       Util.rebind(ctx, jndiName, proxy);
55    }
56
57    public void stop() throws Exception JavaDoc
58    {
59       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
60       Util.unbind(ctx, jndiName);
61    }
62
63    protected abstract Class JavaDoc[] getInterfaces();
64
65    protected abstract void initializeJndiName();
66
67    public void setContainer(Container container)
68    {
69       this.container = container;
70       this.advisor = (Advisor) container;
71    }
72
73 }
74
Popular Tags