1 // Tags: not-a-test |
|
2 // Copyright (c) Object Oriented Concepts, Inc. Billerica, MA, USA |
|
3 |
|
4 // Adapted for Mauve by Audrius Meskauskas <audriusa@bluewin.ch> |
|
5 |
|
6 // This file is part of Mauve. |
|
7 |
|
8 // Mauve is free software; you can redistribute it and/or modify |
|
9 // it under the terms of the GNU General Public License as published by |
|
10 // the Free Software Foundation; either version 2, or (at your option) |
|
11 // any later version. |
|
12 |
|
13 // Mauve is distributed in the hope that it will be useful, |
|
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 // GNU General Public License for more details. |
|
17 |
|
18 // You should have received a copy of the GNU General Public License |
|
19 // along with Mauve; see the file COPYING. If not, write to |
|
20 // the Free Software Foundation, 59 Temple Place - Suite 330, |
|
21 // Boston, MA 02111-1307, USA. |
|
22 |
|
23 /* |
|
24 This code originally came from the OMG's CORBA Open Source Testing project, |
|
25 which lived at cost.omg.org. That site no longer exists. |
|
26 |
|
27 All the contributing companies agreed to release their tests under the |
|
28 terms of the GNU Lesser General Public License, available in the file |
|
29 COPYING.LIB. |
|
30 |
|
31 The code has been modified integrating into Mauve test environment and |
|
32 removing tests that are not yet supported by Suns jre 1.4. Hence the license |
|
33 is now GPL. |
|
34 |
|
35 We downloaded the code from http://sourceforge.net/projects/corba-cost/, |
|
36 administrated by Duncan Grisby. |
|
37 */ |
|
38 |
|
39 |
|
40 // ********************************************************************** |
|
41 // |
|
42 // Copyright (c) 2001 |
|
43 // Object Oriented Concepts, Inc. |
|
44 // Billerica, MA, USA |
|
45 // |
|
46 // All Rights Reserved |
|
47 // |
|
48 // ********************************************************************** |
|
49 |
|
50 |
|
51 package gnu.testlet.org.omg.PortableServer.POA; |
|
52 |
|
53 import org.omg.CORBA.ORB; |
|
54 import org.omg.CORBA.Policy; |
|
55 import org.omg.PortableServer.POA; |
|
56 import org.omg.PortableServer.POAManager; |
|
57 import org.omg.PortableServer.POAPackage.AdapterAlreadyExists; |
|
58 import org.omg.PortableServer.POAPackage.InvalidPolicy; |
|
59 import org.omg.PortableServer.POAPackage.WrongPolicy; |
|
60 |
|
61 import java.io.File; |
|
62 import java.io.FileOutputStream; |
|
63 import java.io.IOException; |
|
64 import java.io.PrintWriter; |
|
65 |
|
66 final class TestLocationForwardServerMain |
|
67 { |
|
68 static String ior = null; |
|
69 |
|
70 static final class Server_impl |
|
71 extends TestLocationForwardServerPOA |
|
72 { |
|
73 private ORB orb_; |
|
74 private TestLocationForwardActivator_impl activator_; |
|
75 private org.omg.CORBA.Object servant_; |
|
76 |
|
77 Server_impl(ORB orb, TestLocationForwardActivator_impl activator, |
|
78 org.omg.CORBA.Object servant |
|
79 ) |
|
80 { |
|
81 orb_ = orb; |
|
82 activator_ = activator; |
|
83 servant_ = servant; |
|
84 } |
|
85 |
|
86 public void setForwardRequest(org.omg.CORBA.Object obj) |
|
87 { |
|
88 activator_.setForwardRequest(obj); |
|
89 } |
|
90 |
|
91 public org.omg.CORBA.Object get_servant() |
|
92 { |
|
93 return servant_; |
|
94 } |
|
95 |
|
96 public void deactivate() |
|
97 { |
|
98 orb_.shutdown(false); |
|
99 } |
|
100 } |
|
101 |
|
102 public static void main(String[] args) |
|
103 { |
|
104 java.util.Properties props = System.getProperties(); |
|
105 |
|
106 ORB orb = null; |
|
107 |
|
108 // |
|
109 // Create ORB |
|
110 // |
|
111 orb = ORB.init(args, props); |
|
112 |
|
113 POA root = TestUtil.GetRootPOA(orb); |
|
114 |
|
115 POA poa; |
|
116 Policy[] policies; |
|
117 |
|
118 POAManager manager = root.the_POAManager(); |
|
119 |
|
120 // |
|
121 // Create POAs |
|
122 // |
|
123 policies = new Policy[ 4 ]; |
|
124 policies [ 0 ] = |
|
125 root.create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.USER_ID); |
|
126 policies [ 1 ] = |
|
127 root.create_id_uniqueness_policy(org.omg.PortableServer.IdUniquenessPolicyValue.UNIQUE_ID); |
|
128 policies [ 2 ] = |
|
129 root.create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.RETAIN); |
|
130 policies [ 3 ] = |
|
131 root.create_request_processing_policy(org.omg.PortableServer.RequestProcessingPolicyValue.USE_SERVANT_MANAGER); |
|
132 |
|
133 try |
|
134 { |
|
135 poa = root.create_POA("poa", manager, policies); |
|
136 } |
|
137 catch (AdapterAlreadyExists ex) |
|
138 { |
|
139 throw new RuntimeException(ex); |
|
140 } |
|
141 catch (InvalidPolicy ex) |
|
142 { |
|
143 throw new RuntimeException(ex); |
|
144 } |
|
145 |
|
146 TestLocationForwardActivator_impl activatorImpl = |
|
147 new TestLocationForwardActivator_impl(); |
|
148 org.omg.PortableServer.ServantActivator activator = |
|
149 activatorImpl._this(orb); |
|
150 |
|
151 try |
|
152 { |
|
153 poa.set_servant_manager(activator); |
|
154 } |
|
155 catch (WrongPolicy ex) |
|
156 { |
|
157 throw new RuntimeException(ex); |
|
158 } |
|
159 |
|
160 byte[] oid = "test".getBytes(); |
|
161 org.omg.CORBA.Object obj = |
|
162 poa.create_reference_with_id(oid, "IDL:Test:1.0"); |
|
163 |
|
164 TestLocationForward_impl testImpl = new TestLocationForward_impl(orb); |
|
165 |
|
166 activatorImpl.setActivatedServant(testImpl); |
|
167 |
|
168 Server_impl serverImpl = new Server_impl(orb, activatorImpl, obj); |
|
169 TestLocationForwardServer server = serverImpl._this(orb); |
|
170 |
|
171 // |
|
172 // Save reference |
|
173 // |
|
174 String refFile = "Test.ref"; |
|
175 try |
|
176 { |
|
177 FileOutputStream file = new FileOutputStream(refFile); |
|
178 PrintWriter out = new PrintWriter(file); |
|
179 out.println(ior = orb.object_to_string(server)); |
|
180 out.flush(); |
|
181 file.close(); |
|
182 } |
|
183 catch (IOException ex) |
|
184 { |
|
185 throw new RuntimeException(ex); |
|
186 } |
|
187 |
|
188 // |
|
189 // Run implementation |
|
190 // |
|
191 try |
|
192 { |
|
193 manager.activate(); |
|
194 } |
|
195 catch (org.omg.PortableServer.POAManagerPackage.AdapterInactive ex) |
|
196 { |
|
197 throw new RuntimeException(ex); |
|
198 } |
|
199 |
|
200 orb.run(); |
|
201 |
|
202 File file = new File(refFile); |
|
203 file.delete(); |
|
204 |
|
205 orb.destroy(); |
|
206 } |
|
207 } |
|