1 26 27 package org.objectweb.openccm.pss.demo1; 28 29 40 public class Server 41 { 42 48 54 60 66 71 public static void main( String [] args ) 72 { 73 74 org.objectweb.openccm.corba.TheORB.initialize(args); 75 76 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 e){ 93 e.printStackTrace(); 94 } 95 connectorRegistry.register_connector(connector); 96 97 98 99 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 a = null; 120 121 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 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 e) { 135 e.printStackTrace(); 136 } 137 138 139 140 141 org.omg.CORBA.ORB orb = org.objectweb.openccm.corba.TheORB.getORB(); 143 144 System.out.println("Obtaining the Name Service..."); 146 org.omg.CORBA.Object obj = null; 147 try { 148 obj = orb.resolve_initial_references("NameService"); 149 } catch(org.omg.CORBA.ORBPackage.InvalidName ex) { 150 ex.printStackTrace(); 151 } 152 org.omg.CosNaming.NamingContext nc = org.omg.CosNaming.NamingContextHelper.narrow(obj); 153 154 org.omg.CORBA.Object objPoa = null; 155 org.omg.PortableServer.POA rootPOA = null; 156 157 try { 158 objPoa = orb.resolve_initial_references( "RootPOA" ); 159 } catch(org.omg.CORBA.ORBPackage.InvalidName ex) { 160 ex.printStackTrace(); 161 } 162 rootPOA = org.omg.PortableServer.POAHelper.narrow( objPoa ); 163 org.omg.PortableServer.POAManager manager = rootPOA.the_POAManager(); 164 165 FormImpl form = new FormImpl( mySession ); 167 obj = form._this( orb ); 168 169 org.omg.CosNaming.NameComponent [] name = new org.omg.CosNaming.NameComponent [1]; 171 name[0] = new org.omg.CosNaming.NameComponent (); 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 err) { 178 System.out.println("Object not found ! "); 179 } catch (org.omg.CosNaming.NamingContextPackage.CannotProceed err) { 180 System.out.println("CannotProceed exception !"); 181 } catch (org.omg.CosNaming.NamingContextPackage.InvalidName err) { 182 System.out.println("InvalidName exception !"); 183 } 184 185 System.out.println("The server is ready!"); 187 try { 188 manager.activate(); 189 } catch(org.omg.PortableServer.POAManagerPackage.AdapterInactive ex) { 190 ex.printStackTrace(); 191 } 192 orb.run(); 193 } 194 } 195 | Popular Tags |