KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > pss > demo1 > Server


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2004 INRIA & USTL - LIFL - GOAL
5 Contact: openccm@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): Christophe Demarey.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.pss.demo1;
28
29 /**
30  * This Server :
31  * - Initialize the ORB and retrieve the PSS
32  * - Register Storage Types and Storage Homes in the PSS
33  * - Create a new session from demo properties
34  * - Instantiate a new Form, activate it and waiting for requests.
35  *
36  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
37  *
38  * @version 0.2
39  */

40 public class Server
41 {
42     // ==================================================================
43
//
44
// Internal state.
45
//
46
// ==================================================================
47

48     // ==================================================================
49
//
50
// Constructor.
51
//
52
// ==================================================================
53

54     // ==================================================================
55
//
56
// Internal methods.
57
//
58
// ==================================================================
59

60     // ==================================================================
61
//
62
// Public methods.
63
//
64
// ==================================================================
65

66     /**
67      * The application entry point.
68      *
69      * @param args - Application arguments.
70      */

71     public static void main( String JavaDoc [] args )
72     {
73         /* ===== Step 1 : Init the ORB ===== */
74         org.objectweb.openccm.corba.TheORB.initialize(args);
75
76         /* ===== Step 2 : Create the connector and register storage factories ===== */
77         org.omg.CosPersistentState.ConnectorRegistry connectorRegistry = null;
78         connectorRegistry = org.omg.CosPersistentState.ConnectorRegistryHelper.narrow(
79                 org.objectweb.openccm.corba.TheORB.resolve_initial_reference("PSS") );
80         org.objectweb.openccm.pss.runtime.common.api.Connector connector = null;
81         connector = org.objectweb.openccm.pss.runtime.common.lib.ConnectorFactory.create();
82         try
83         {
84             connector.register_storage_home_factory("PSDL:openccm.objectweb.org/pss/demo1/SH_Person:1.0",
85                                                     Class.forName("org.objectweb.openccm.pss.demo1.SH_Person") );
86             connector.register_storage_object_factory("PSDL:openccm.objectweb.org/pss/demo1/ST_Person:1.0",
87                                                       Class.forName("org.objectweb.openccm.pss.demo1.PersonBaseImpl") );
88             connector.register_storage_home_factory("PSDL:openccm.objectweb.org/pss/demo1/SH_Address:1.0",
89                                                     Class.forName("org.objectweb.openccm.pss.demo1.SH_Address") );
90             connector.register_storage_object_factory("PSDL:openccm.objectweb.org/pss/demo1/ST_Address:1.0",
91                                                       Class.forName("org.objectweb.openccm.pss.demo1.ST_Address") );
92         }catch(ClassNotFoundException JavaDoc e){
93             e.printStackTrace();
94         }
95         connectorRegistry.register_connector(connector);
96
97
98         /* ===== Step 3 : Retrieve the connector and create a session (catalog) ===== */
99         // This code should be simplified outside this demo.
100
// The connector name must be known by PSS user.
101
try
102         {
103             connector = (org.objectweb.openccm.pss.runtime.common.api.Connector)
104                             connectorRegistry.find_connector("org.objectweb.openccm.pss.runtime.JDO");
105         }catch(org.omg.CosPersistentState.NotFound e1){
106             try
107             {
108                 connector = (org.objectweb.openccm.pss.runtime.common.api.Connector)
109                                  connectorRegistry.find_connector("org.objectweb.openccm.pss.runtime.Hibernate");
110             }catch(org.omg.CosPersistentState.NotFound e2){
111                 e2.printStackTrace();
112             }
113         }
114
115         org.omg.CosPersistentState.Session mySession = null;
116         try {
117             org.omg.CosPersistentState.Parameter[] parameters = null;
118             org.omg.CosPersistentState.Parameter param = null;
119             org.omg.CORBA.Any JavaDoc a = null;
120
121             // Init parameters
122
parameters = new org.omg.CosPersistentState.Parameter[1];
123             
124             a = org.objectweb.openccm.corba.TheORB.getORB().create_any();
125             a.insert_string( "demo1.properties" );
126             param = new org.omg.CosPersistentState.Parameter("CONF_FILE", a);
127             parameters[0] = param;
128
129             // create the session
130
mySession = connector.create_basic_session( org.omg.CosPersistentState.READ_WRITE.value,
131                                                         parameters
132                                                       );
133             ((org.objectweb.openccm.pss.runtime.common.api.CatalogBase)mySession).set_connector(connector);
134         } catch (Exception JavaDoc e) {
135             e.printStackTrace();
136         }
137
138
139         /* ===== Step 4 : Create the Corba Form Object and register it in the NS ===== */
140
141         // Obtain the ORB.
142
org.omg.CORBA.ORB JavaDoc orb = org.objectweb.openccm.corba.TheORB.getORB();
143
144         // Obtain the Name Service.
145
System.out.println("Obtaining the Name Service...");
146         org.omg.CORBA.Object JavaDoc obj = null;
147         try {
148             obj = orb.resolve_initial_references("NameService");
149         } catch(org.omg.CORBA.ORBPackage.InvalidName JavaDoc ex) {
150             ex.printStackTrace();
151         }
152         org.omg.CosNaming.NamingContext JavaDoc nc = org.omg.CosNaming.NamingContextHelper.narrow(obj);
153
154         org.omg.CORBA.Object JavaDoc objPoa = null;
155         org.omg.PortableServer.POA JavaDoc rootPOA = null;
156
157         try {
158             objPoa = orb.resolve_initial_references( "RootPOA" );
159         } catch(org.omg.CORBA.ORBPackage.InvalidName JavaDoc ex) {
160             ex.printStackTrace();
161         }
162         rootPOA = org.omg.PortableServer.POAHelper.narrow( objPoa );
163         org.omg.PortableServer.POAManager JavaDoc manager = rootPOA.the_POAManager();
164
165         // Create the CORBA object
166
FormImpl form = new FormImpl( mySession );
167         obj = form._this( orb );
168
169         // Bind the pss::demo1::form in ths NS
170
org.omg.CosNaming.NameComponent JavaDoc[] name = new org.omg.CosNaming.NameComponent JavaDoc[1];
171         name[0] = new org.omg.CosNaming.NameComponent JavaDoc();
172         name[0].id = "My_PSS_demo1_form";
173         name[0].kind = "";
174
175         try {
176             nc.rebind(name, obj);
177         } catch (org.omg.CosNaming.NamingContextPackage.NotFound JavaDoc err) {
178             System.out.println("Object not found ! ");
179         } catch (org.omg.CosNaming.NamingContextPackage.CannotProceed JavaDoc err) {
180             System.out.println("CannotProceed exception !");
181         } catch (org.omg.CosNaming.NamingContextPackage.InvalidName JavaDoc err) {
182             System.out.println("InvalidName exception !");
183         }
184
185         // Wait for requests
186
System.out.println("The server is ready!");
187         try {
188             manager.activate();
189         } catch(org.omg.PortableServer.POAManagerPackage.AdapterInactive JavaDoc ex) {
190             ex.printStackTrace();
191         }
192         orb.run();
193     }
194 }
195
Popular Tags