KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > jmx > browser > model > connector > JBoss30EJBConnectionService


1 /*
2
3  * EJTools, the Enterprise Java Tools
4
5  *
6
7  * Distributable under LGPL license.
8
9  * See terms of license at www.gnu.org.
10
11  */

12
13 package org.ejtools.jmx.browser.model.connector;
14
15
16
17 import java.lang.reflect.Method JavaDoc;
18
19 import java.util.Hashtable JavaDoc;
20
21
22
23 import javax.management.MBeanServer JavaDoc;
24
25 import javax.naming.Context JavaDoc;
26
27 import javax.naming.InitialContext JavaDoc;
28
29 import javax.rmi.PortableRemoteObject JavaDoc;
30
31
32
33 import org.ejtools.jmx.MBeanServerProxy;
34
35 import org.ejtools.jmx.browser.model.service.ConnectionMetaData;
36
37
38
39
40
41 /**
42
43  * EJB Connector for JBoss 3.x series. Look up an EJB Home into the JNDI space and create
44
45  * an instance of an EJB, which is proxied to hide the remote aspects.
46
47  *
48
49  * @author letiembl
50
51  * @created 4 septembre 2002
52
53  * @version $Revision: 1.6 $
54
55  */

56
57 public class JBoss30EJBConnectionService extends AbstractConnectionService
58
59 {
60
61    /** Instace of the RMI adaptor */
62
63    protected Object JavaDoc adaptor = null;
64
65
66
67
68
69    /** Disconnection by removing the EJB instance. */
70
71    public void disconnect()
72
73    {
74
75       super.disconnect();
76
77       try
78
79       {
80
81          // Search for the stop method of the EJB Adaptor
82

83          Method JavaDoc m = this.adaptor.getClass().getMethod("remove", new Class JavaDoc[0]);
84
85          m.invoke(this.adaptor, new Object JavaDoc[0]);
86
87       }
88
89       catch (Exception JavaDoc e)
90
91       {
92
93          // Do nothing
94

95       }
96
97       this.setConnected(false);
98
99    }
100
101
102
103
104
105    /**
106
107     * Creation of the local proxy to access the remote MBean server.
108
109     *
110
111     * @exception Exception Description of the Exception
112
113     */

114
115    protected void createMBeanServer()
116
117       throws Exception JavaDoc
118
119    {
120
121       System.setProperty("jmx.serial.form", "1.1");
122
123
124
125       Hashtable JavaDoc props = new Hashtable JavaDoc();
126
127       props.put(Context.INITIAL_CONTEXT_FACTORY, this.profile.getProperty(ConnectionMetaData.FACTORY));
128
129       props.put(Context.URL_PKG_PREFIXES, this.profile.getProperty(ConnectionMetaData.PACKAGES));
130
131       props.put(Context.PROVIDER_URL, this.profile.getProperty(ConnectionMetaData.URL));
132
133       props.put(Context.SECURITY_PRINCIPAL, this.profile.getProperty(ConnectionMetaData.PRINCIPAL));
134
135       props.put(Context.SECURITY_CREDENTIALS, this.profile.getProperty(ConnectionMetaData.CREDENTIALS));
136
137
138
139       InitialContext JavaDoc context = new InitialContext JavaDoc(props);
140
141       Object JavaDoc ref = context.lookup(this.profile.getProperty(ConnectionMetaData.CONTEXT));
142
143
144
145       Class JavaDoc clazzAdaptorHome = Thread.currentThread().getContextClassLoader().loadClass("org.jboss.jmx.adaptor.interfaces.AdaptorHome");
146
147       Object JavaDoc home = PortableRemoteObject.narrow(ref, clazzAdaptorHome);
148
149       Method JavaDoc createMethod = clazzAdaptorHome.getMethod("create", new Class JavaDoc[0]);
150
151       this.adaptor = createMethod.invoke(home, new Object JavaDoc[0]);
152
153
154
155       MBeanServer JavaDoc server = MBeanServerProxy.createMBeanProxy(this.adaptor);
156
157       this.setMBeanServer(server);
158
159    }
160
161 }
162
163
Popular Tags