KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > trading > test > ExampleSetup


1 package org.jacorb.trading.test;
2
3 import org.omg.CosTrading.*;
4 import org.omg.CosTrading.RegisterPackage.*;
5 import org.omg.CosTrading.LookupPackage.*;
6 import org.omg.CosTradingRepos.*;
7 import org.omg.CosTradingRepos.ServiceTypeRepositoryPackage.*;
8 import org.omg.CORBA.*;
9 import java.io.*;
10
11 /**
12  * This class provides four traders with eight different offers (two each)
13  * and connects them fully.
14  *
15  * @author Nicolas Noffke
16  */

17
18 public class ExampleSetup
19 {
20     public static void main(String JavaDoc[] args)
21     {
22     try
23         {
24         if (args.length == 0)
25             {
26         System.out.println("Usage: ExampleSetup <iorfile-stem>");
27         System.exit(0);
28         }
29
30         org.omg.CORBA.ORB JavaDoc _orb = org.omg.CORBA.ORB.init(args, null);
31
32         BufferedReader in =
33                 new BufferedReader(new FileReader(new File(args[0] + "1")));
34         String JavaDoc ref = in.readLine();
35         in.close();
36         Lookup _lookup1 = LookupHelper.narrow(_orb.string_to_object(ref));
37         Link _link1 = LinkHelper.narrow(_lookup1.link_if());
38         ServiceTypeRepository _repos1 =
39                 ServiceTypeRepositoryHelper.narrow(_lookup1.type_repos());
40
41         Register _reg1 = RegisterHelper.narrow(_lookup1.register_if());
42
43
44         in = new BufferedReader(new FileReader(new File(args[0] + "2")));
45         ref = in.readLine();
46         in.close();
47         Lookup _lookup2 = LookupHelper.narrow(_orb.string_to_object(ref));
48         Link _link2 = LinkHelper.narrow(_lookup2.link_if());
49         ServiceTypeRepository _repos2 = ServiceTypeRepositoryHelper.narrow(_lookup2.type_repos());
50         Register _reg2 = RegisterHelper.narrow(_lookup2.register_if());
51
52
53         in = new BufferedReader(new FileReader(new File(args[0] + "3")));
54         ref = in.readLine();
55         in.close();
56         Lookup _lookup3 = LookupHelper.narrow(_orb.string_to_object(ref));
57         Link _link3 = LinkHelper.narrow(_lookup3.link_if());
58         ServiceTypeRepository _repos3 = ServiceTypeRepositoryHelper.narrow(_lookup3.type_repos());
59         Register _reg3 = RegisterHelper.narrow(_lookup3.register_if());
60
61
62         in = new BufferedReader(new FileReader(new File(args[0] + "4")));
63         ref = in.readLine();
64         in.close();
65         Lookup _lookup4 = LookupHelper.narrow(_orb.string_to_object(ref));
66         Link _link4 = LinkHelper.narrow(_lookup4.link_if());
67         ServiceTypeRepository _repos4 = ServiceTypeRepositoryHelper.narrow(_lookup4.type_repos());
68         Register _reg4 = RegisterHelper.narrow(_lookup4.register_if());
69
70
71         PropStruct[] _props = new PropStruct[2];
72         _props[0] = new PropStruct();
73         _props[0].name = "Art";
74         _props[0].value_type = _orb.get_primitive_tc(TCKind.tk_string);
75         _props[0].mode = PropertyMode.PROP_MANDATORY;
76         
77         _props[1] = new PropStruct();
78         _props[1].name = "Preis";
79         _props[1].value_type = _orb.get_primitive_tc(TCKind.tk_string);
80         _props[1].mode = PropertyMode.PROP_MANDATORY;
81           
82
83         _repos1.add_type("Orchideen", "IDL:Orchid:1.0", _props, new String JavaDoc[0]);
84         _repos2.add_type("Orchideen", "IDL:Orchid:1.0", _props, new String JavaDoc[0]);
85         _repos3.add_type("Orchideen", "IDL:Orchid:1.0", _props, new String JavaDoc[0]);
86         _repos4.add_type("Orchideen", "IDL:Orchid:1.0", _props, new String JavaDoc[0]);
87         
88 // String[] types;
89
// SpecifiedServiceTypes whichTypes = new SpecifiedServiceTypes();
90
// whichTypes.__default();
91
// types = _repos.list_types(whichTypes);
92

93         Property[] _prop = new Property[2];
94         _prop[0] = new Property();
95         _prop[0].name = "Art";
96         _prop[0].value = _orb.create_any();
97         _prop[0].value.insert_string("Phalaenopsis");
98         
99         _prop[1] = new Property();
100         _prop[1].name = "Preis";
101         _prop[1].value = _orb.create_any();
102         _prop[1].value.insert_string("8");
103         
104         
105         String JavaDoc id = _reg1.export(_reg1, "Orchideen", _prop);
106         System.out.println("Offer id = " + id);
107
108         _prop[0].name = "Art";
109         _prop[0].value = _orb.create_any();
110         _prop[0].value.insert_string("Chilochista");
111
112         _prop[1].name = "Preis";
113         _prop[1].value = _orb.create_any();
114         _prop[1].value.insert_string("6");
115                 
116         id = _reg1.export(_reg1, "Orchideen", _prop);
117         System.out.println("Offer id = " + id);
118         
119         //
120
_prop[0].value.insert_string("Cambria");
121         _prop[1].value.insert_string("8");
122         id = _reg2.export(_reg2, "Orchideen", _prop);
123         System.out.println("Offer id = " + id);
124
125         _prop[0].value.insert_string("Paphilopedilum");
126         _prop[1].value.insert_string("6");
127         id = _reg2.export(_reg2, "Orchideen", _prop);
128         System.out.println("Offer id = " + id);
129
130         //
131
_prop[0].value.insert_string("Oncidium");
132         _prop[1].value.insert_string("8");
133         id = _reg3.export(_reg3, "Orchideen", _prop);
134         System.out.println("Offer id = " + id);
135
136         _prop[0].value.insert_string("Dendrobium");
137         _prop[1].value.insert_string("6");
138         id = _reg3.export(_reg3, "Orchideen", _prop);
139         System.out.println("Offer id = " + id);
140
141         //
142
_prop[0].value.insert_string("Miltonia");
143         _prop[1].value.insert_string("8");
144         id = _reg4.export(_reg4, "Orchideen", _prop);
145         System.out.println("Offer id = " + id);
146
147         _prop[0].value.insert_string("Cymbidium");
148         _prop[1].value.insert_string("6");
149         id = _reg4.export(_reg4, "Orchideen", _prop);
150         System.out.println("Offer id = " + id);
151
152          _link1.add_link("link1", _lookup2, FollowOption.always, FollowOption.always);
153          _link1.add_link("link2", _lookup3, FollowOption.always, FollowOption.always);
154           _link1.add_link("link3", _lookup4, FollowOption.always, FollowOption.always);
155
156          _link2.add_link("link1", _lookup1, FollowOption.always, FollowOption.always);
157          _link2.add_link("link2", _lookup3, FollowOption.always, FollowOption.always);
158          _link2.add_link("link3", _lookup4, FollowOption.always, FollowOption.always);
159          // _link2.add_link("link4", _lookup4, FollowOption.always, FollowOption.always);
160

161          _link3.add_link("link1", _lookup2, FollowOption.always, FollowOption.always);
162          _link3.add_link("link2", _lookup1, FollowOption.always, FollowOption.always);
163          _link3.add_link("link3", _lookup4, FollowOption.always, FollowOption.always);
164         
165          _link4.add_link("link1", _lookup1, FollowOption.always, FollowOption.always);
166          _link4.add_link("link2", _lookup3, FollowOption.always, FollowOption.always);
167          _link4.add_link("link3", _lookup2, FollowOption.always, FollowOption.always);
168     }
169     catch (Exception JavaDoc e){
170         e.printStackTrace();
171     }
172     }
173     
174 } // jtrtest
175

176
177
178
Popular Tags