KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > ccm > sessiondemo > SessionDemo


1 // ====================================================================
2
//
3
// ECM: The Extensible Container Model
4
// Copyright (C) 2004 THALES
5
// Contact: openccm-ecm@objectweb.org
6
//
7
// This library is free software; you can redistribute it and/or
8
// modify it under the terms of the GNU Lesser General Public
9
// License as published by the Free Software Foundation; either
10
// version 2.1 of the License, or any later version.
11
//
12
// This library 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 library; if not, write to the Free Software
19
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20
// USA
21
//
22
// Initial developer(s): Mathieu Vadet.
23
// Initial Funding: IST COACH European project (IST-2001-34445)
24
// http://www.ist-coach.org
25
//
26
// ====================================================================
27

28
29
30 package org.objectweb.ccm.sessiondemo;
31
32 import org.objectweb.corba.runtime.*;
33
34 /**
35  ** Demo2 application deployment.
36  **/

37 public class SessionDemo
38 implements Runnable JavaDoc, java.awt.event.ActionListener JavaDoc
39 {
40     // main
41
private ORBService _orb_service;
42     private ClientHome _client_home;
43     private ServerHome _server_home;
44
45     public
46     SessionDemo(ORBService orbs)
47     {
48         // main
49
_orb_service = orbs;
50         _client_home = null;
51         _server_home = null;
52     }
53
54     //
55
// java.lang.Runnable
56
//
57

58     final public void
59     run()
60     {
61         try {
62             // need to register value factory for Components::Cookie
63
ValueFactory vfact = new ValueFactoryImpl(org.omg.Components.CookieHelper.id(), new CookieFactoryImpl());
64             _orb_service.register_valuefactory(vfact);
65
66             // obtain the INS scheme of the registration service
67
RegistrationService regs = org.objectweb.corba.runtime.Runtime.getRegistrationService();
68             INSRegistrationScheme scheme = (INSRegistrationScheme)regs.get_scheme(INSRegistrationScheme.SCHEME_ID);
69
70             // obtain component homes
71
System.err.println("## Obtain homes");
72             org.omg.CORBA.Object JavaDoc obj = null;
73             obj = scheme.lookup("ClientHome", _orb_service);
74             _client_home = ClientHomeHelper.narrow(obj);
75             obj = scheme.lookup("ServerHome", _orb_service);
76             _server_home = ServerHomeHelper.narrow(obj);
77
78             // create GUI for component creation
79
javax.swing.JPanel JavaDoc panel = new javax.swing.JPanel JavaDoc(new java.awt.BorderLayout JavaDoc());
80             javax.swing.JButton JavaDoc newb = new javax.swing.JButton JavaDoc("new client");
81             newb.setActionCommand("new");
82             newb.addActionListener(this);
83             panel.add(newb, java.awt.BorderLayout.NORTH);
84
85             javax.swing.JFrame JavaDoc frame = new javax.swing.JFrame JavaDoc("Client factory");
86             frame.getContentPane().add(panel);
87             frame.pack();
88             frame.show();
89
90         } catch (Exception JavaDoc ex) {
91             ex.printStackTrace();
92             throw new Error JavaDoc(ex.getMessage());
93         }
94
95         System.out.println("Again ....");
96     }
97
98     //
99
// java.awt.event.ActionListener
100
//
101

102     final public void
103     actionPerformed(java.awt.event.ActionEvent JavaDoc e)
104     {
105         String JavaDoc cmd = e.getActionCommand();
106
107         try {
108             Client cl1 = _client_home.create();
109             cl1.connect_server_home(_server_home);
110             cl1.configuration_complete();
111         } catch (Exception JavaDoc ex) {
112             ex.printStackTrace();
113             throw new Error JavaDoc(ex.getMessage());
114         }
115
116     }
117
118     static public Runnable JavaDoc
119     main(ORBService orbs)
120     {
121         return new SessionDemo(orbs);
122     }
123 }
124
125
126
127
128
129
130
131
Popular Tags