KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > trading > client > proxy > ProxyLookupImpl


1 // Copyright (C) 1998-1999
2
// Object Oriented Concepts, Inc.
3
// **********************************************************************
4
//
5
// Copyright (c) 1997
6
// Mark Spruiell (mark@intellisoft.com)
7
//
8
// See the COPYING file for more information
9
//
10
// **********************************************************************
11

12 package org.jacorb.trading.client.proxy;
13
14 import java.io.*;
15 import java.util.*;
16 import org.omg.CORBA.*;
17 import org.omg.CosTrading.*;
18 import org.omg.CosTrading.LookupPackage.*;
19 import org.jacorb.trading.client.util.*;
20
21 public class ProxyLookupImpl extends org.omg.CosTrading.LookupPOA
22 {
23     public ProxyLookupImpl()
24     {
25     }
26
27
28     /**
29      * Overridden from Visibroker's _LookupImplBase; we do this
30      * instead of the unportable super(objectName) we'd have to put in
31      * the constructor; the presence of this method should not affect
32      * use with other ORBs
33      */

34     public String JavaDoc _object_name()
35     {
36     return "ProxyDemo";
37     }
38
39
40     // operations inherited from CosTrading::TraderComponents
41

42     public Lookup lookup_if()
43     {
44     throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
45     }
46
47
48     public Register register_if()
49     {
50     throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
51     }
52
53
54     public Link link_if()
55     {
56     throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
57     }
58
59
60     public Proxy proxy_if()
61     {
62     throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
63     }
64
65
66     public Admin admin_if()
67     {
68     throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
69     }
70
71
72     // operations inherited from CosTrading::SupportAttributes
73

74     public boolean supports_modifiable_properties()
75     {
76     throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
77     }
78
79
80     public boolean supports_dynamic_properties()
81     {
82     throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
83     }
84
85
86     public boolean supports_proxy_offers()
87     {
88     throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
89     }
90
91
92     public org.omg.CORBA.Object JavaDoc type_repos()
93     {
94     throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
95     }
96
97
98     // operations inherited from CosTrading::SupportAttributes
99

100
101     public int def_search_card()
102     {
103     throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
104     }
105
106
107     public int max_search_card()
108     {
109     throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
110     }
111
112
113     public int def_match_card()
114     {
115     throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
116     }
117
118
119     public int max_match_card()
120     {
121     throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
122     }
123
124
125     public int def_return_card()
126     {
127     throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
128     }
129
130
131     public int max_return_card()
132     {
133     throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
134     }
135
136
137     public int max_list()
138     {
139     throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
140     }
141
142
143     public int def_hop_count()
144     {
145     throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
146     }
147
148
149     public int max_hop_count()
150     {
151     throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
152     }
153
154
155     public FollowOption def_follow_policy()
156     {
157     throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
158     }
159
160
161     public FollowOption max_follow_policy()
162     {
163     throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
164     }
165
166
167
168     // operations inherited from CosTrading::Lookup
169

170     public void query(
171               String JavaDoc type,
172               String JavaDoc constr,
173               String JavaDoc pref,
174               org.omg.CosTrading.Policy[] policies,
175               SpecifiedProps desired_props,
176               int how_many,
177               OfferSeqHolder offers,
178               OfferIteratorHolder offer_itr,
179               PolicyNameSeqHolder limits_applied)
180     throws IllegalServiceType,
181     UnknownServiceType,
182     IllegalConstraint,
183     IllegalPreference,
184     IllegalPolicyName,
185     PolicyTypeMismatch,
186     InvalidPolicyValue,
187     IllegalPropertyName,
188     DuplicatePropertyName,
189     DuplicatePolicyName
190     {
191     PrintWriter pw = new PrintWriter(System.out);
192     pw.println("Type = " + type);
193     pw.println("Constraint = '" + constr + "'");
194     pw.println("Preference = '" + pref + "'");
195
196     for (int i = 0; i < policies.length; i++)
197     {
198         pw.print("Policy[" + i + "] = {" + policies[i].name + ", ");
199         AnyUtil.print(_orb(), pw, policies[i].value);
200         pw.println("}");
201     }
202     pw.flush();
203
204     /********
205          // sleep for a while - also used for testing
206          try {
207          Thread.currentThread().sleep(10000); // 10 secs
208          }
209          catch (InterruptedException e) {
210          }
211     ********/

212
213     Offer[] arr = createOffers();
214
215     // process the offers
216
int seqCount = Math.min(arr.length, how_many);
217
218     offers.value = new Offer[seqCount];
219     int count = 0;
220     while (count < seqCount) {
221         offers.value[count] = arr[count];
222         count++;
223     }
224
225     // construct an iterator if necessary
226
if (seqCount < arr.length) {
227         // create a sequence holding the remaining offers
228
int restCount = arr.length - seqCount;
229         Offer[] rest = new Offer[restCount];
230
231         int pos = 0;
232         while (pos < restCount) {
233         rest[pos] = arr[count];
234         pos++;
235         count++;
236         }
237
238         OfferIteratorImpl iter = new OfferIteratorImpl(rest, 0);
239         // iter._orb( _orb() );
240
offer_itr.value = iter._this();
241     }
242
243     limits_applied.value = new String JavaDoc[0];
244     }
245
246
247     protected Offer[] createOffers()
248     {
249     Offer[] result;
250
251     ORB orb = org.omg.CORBA.ORB.init();
252     Random rand = new Random();
253     int numOffers = Math.abs(rand.nextInt()) % 4;
254     result = new Offer[numOffers];
255
256     for (int i = 0; i < numOffers; i++) {
257         // just use this as the offer's object
258
result[i] = new Offer();
259         result[i].reference = this._this(); // GB: _this()
260
result[i].properties = new Property[3];
261
262         int num = 0;
263
264         // the "name" property
265
result[i].properties[num] = new Property();
266         result[i].properties[num].name = "name";
267         result[i].properties[num].value = orb.create_any();
268         result[i].properties[num].value.insert_string("proxy offer " + i);
269         num++;
270
271         // the "cost" property
272
result[i].properties[num] = new Property();
273         result[i].properties[num].name = "cost";
274         result[i].properties[num].value = orb.create_any();
275         result[i].properties[num].value.insert_double(
276                               Math.abs(rand.nextDouble()));
277         num++;
278
279         // the "version" property
280
result[i].properties[num] = new Property();
281         result[i].properties[num].name = "version";
282         result[i].properties[num].value = orb.create_any();
283         result[i].properties[num].value.insert_string("1.0" + i);
284         num++;
285     }
286
287     return result;
288     }
289 }
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
Popular Tags