KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > trading > impl > AdminImpl


1
2 // Copyright (C) 1998-1999
3
// Object Oriented Concepts, Inc.
4

5 // **********************************************************************
6
//
7
// Copyright (c) 1997
8
// Mark Spruiell (mark@intellisoft.com)
9
//
10
// See the COPYING file for more information
11
//
12
// **********************************************************************
13

14 package org.jacorb.trading.impl;
15
16 import java.util.*;
17 import org.omg.CosTradingRepos.*;
18 import org.omg.CosTradingRepos.ServiceTypeRepositoryPackage.*;
19 import org.omg.CosTrading.*;
20 import org.jacorb.trading.constraint.*;
21 import org.jacorb.trading.db.OfferDatabase;
22 import org.jacorb.trading.util.*;
23
24 /**
25  * Implementation of CosTrading::Admin
26  */

27
28 public class AdminImpl
29     extends org.omg.CosTrading.AdminPOA
30 {
31     private TraderComp m_traderComp;
32     private SupportAttrib m_support;
33     private ImportAttrib m_import;
34     private LinkAttrib m_link;
35     private OfferDatabase m_db;
36     private ServiceTypeRepository m_repos;
37     private byte[] m_request_id_stem;
38
39     private AdminImpl()
40     {
41     }
42
43     public AdminImpl(
44              TraderComp traderComp,
45              SupportAttrib supportAttrib,
46              ImportAttrib importAttrib,
47              LinkAttrib linkAttrib,
48              OfferDatabase db,
49              byte[] stem)
50     {
51     m_traderComp = traderComp;
52     m_support = supportAttrib;
53     m_import = importAttrib;
54     m_link = linkAttrib;
55     m_db = db;
56     org.omg.CORBA.Object JavaDoc obj = supportAttrib.getTypeRepos();
57     m_repos = ServiceTypeRepositoryHelper.narrow(obj);
58     m_request_id_stem = stem;
59     }
60
61
62     // operations inherited from CosTrading::TraderComponents
63

64     public Lookup lookup_if()
65     {
66     return m_traderComp.getLookupInterface();
67     }
68
69
70     public Register register_if()
71     {
72     return m_traderComp.getRegisterInterface();
73     }
74
75
76     public Link link_if()
77     {
78     return m_traderComp.getLinkInterface();
79     }
80
81
82     public Proxy proxy_if()
83     {
84     return m_traderComp.getProxyInterface();
85     }
86
87
88     public Admin admin_if()
89     {
90     return m_traderComp.getAdminInterface();
91     }
92
93
94     // operations inherited from CosTrading::SupportAttributes
95

96     public boolean supports_modifiable_properties()
97     {
98     return m_support.getModifiableProperties();
99     }
100
101
102     public boolean supports_dynamic_properties()
103     {
104     return m_support.getDynamicProperties();
105     }
106
107
108     public boolean supports_proxy_offers()
109     {
110     return m_support.getProxyOffers();
111     }
112
113
114     public org.omg.CORBA.Object JavaDoc type_repos()
115     {
116     return m_support.getTypeRepos();
117     }
118
119
120     // operations inherited from CosTrading::SupportAttributes
121

122
123     public int def_search_card()
124     {
125     return m_import.getDefSearchCard();
126     }
127
128
129     public int max_search_card()
130     {
131     return m_import.getMaxSearchCard();
132     }
133
134
135     public int def_match_card()
136     {
137     return m_import.getDefMatchCard();
138     }
139
140
141     public int max_match_card()
142     {
143     return m_import.getMaxMatchCard();
144     }
145
146
147     public int def_return_card()
148     {
149     return m_import.getDefReturnCard();
150     }
151
152
153     public int max_return_card()
154     {
155     return m_import.getMaxReturnCard();
156     }
157
158
159     public int max_list()
160     {
161     return m_import.getMaxList();
162     }
163
164
165     public int def_hop_count()
166     {
167     return m_import.getDefHopCount();
168     }
169
170
171     public int max_hop_count()
172     {
173     return m_import.getMaxHopCount();
174     }
175
176
177     public FollowOption def_follow_policy()
178     {
179     return m_import.getDefFollowPolicy();
180     }
181
182
183     public FollowOption max_follow_policy()
184     {
185     return m_import.getMaxFollowPolicy();
186     }
187
188
189     // operations inherited from CosTrading::LinkAttributes
190

191
192     public FollowOption max_link_follow_policy()
193     {
194     return m_link.getMaxLinkFollowPolicy();
195     }
196
197
198     // operations inherited from CosTrading::Admin
199

200
201     public byte[] request_id_stem()
202     {
203     return m_request_id_stem;
204     }
205
206
207     public int set_def_search_card(int value)
208     {
209     return m_import.setDefSearchCard(value);
210     }
211
212
213     public int set_max_search_card(int value)
214     {
215     return m_import.setMaxSearchCard(value);
216     }
217
218
219     public int set_def_match_card(int value)
220     {
221     return m_import.setDefMatchCard(value);
222     }
223
224
225     public int set_max_match_card(int value)
226     {
227     return m_import.setMaxMatchCard(value);
228     }
229
230
231     public int set_def_return_card(int value)
232     {
233     return m_import.setDefReturnCard(value);
234     }
235
236
237     public int set_max_return_card(int value)
238     {
239     return m_import.setMaxReturnCard(value);
240     }
241
242
243     public int set_max_list(int value)
244     {
245     return m_import.setMaxList(value);
246     }
247
248
249     public boolean set_supports_modifiable_properties(boolean value)
250     {
251     return m_support.setModifiableProperties(value);
252     }
253
254
255     public boolean set_supports_dynamic_properties(boolean value)
256     {
257     return m_support.setDynamicProperties(value);
258     }
259
260
261     public boolean set_supports_proxy_offers(boolean value)
262     {
263     return m_support.setProxyOffers(value);
264     }
265
266
267     public int set_def_hop_count(int value)
268     {
269     return m_import.setDefHopCount(value);
270     }
271
272
273     public int set_max_hop_count(int value)
274     {
275     return m_import.setMaxHopCount(value);
276     }
277
278
279     public FollowOption set_def_follow_policy(FollowOption policy)
280     {
281     return m_import.setDefFollowPolicy(policy);
282     }
283
284
285     public FollowOption set_max_follow_policy(FollowOption policy)
286     {
287     return m_import.setMaxFollowPolicy(policy);
288     }
289
290
291     public FollowOption set_max_link_follow_policy(FollowOption policy)
292     {
293     return m_link.setMaxLinkFollowPolicy(policy);
294     }
295
296
297     public org.omg.CORBA.Object JavaDoc set_type_repos(org.omg.CORBA.Object JavaDoc repository)
298     {
299     return m_support.setTypeRepos(repository);
300     }
301
302
303     public byte[] set_request_id_stem(byte[] stem)
304     {
305     byte[] _old = m_request_id_stem;
306     m_request_id_stem = stem;
307     return _old;
308     }
309
310
311     public void list_offers(
312                 int how_many,
313                 OfferIdSeqHolder ids,
314                 OfferIdIteratorHolder id_itr)
315     throws NotImplemented
316     {
317     // obtain the list of all service type names
318
SpecifiedServiceTypes whichTypes = new SpecifiedServiceTypes();
319     //whichTypes._default(ListOption.all);
320
// whichTypes.all_dummy((short)0);
321
// GB:
322
whichTypes.__default();
323
324     String JavaDoc[] allNames = m_repos.list_types(whichTypes);
325
326     try {
327         m_db.begin(OfferDatabase.READ);
328
329         // construct a Vector of all offers for all types
330
Vector vec = new Vector();
331         for (int i = 0; i < allNames.length; i++) {
332         String JavaDoc[] seq = m_db.getOfferIds(allNames[i]);
333         if (seq != null)
334             for (int n = 0; n < seq.length; n++)
335             vec.addElement(seq[n]);
336         }
337
338         int offerCount = vec.size();
339         int seqCount = Math.min(offerCount, how_many);
340
341         ids.value = new String JavaDoc[seqCount];
342         int count = 0;
343         Enumeration e = vec.elements();
344         while (e.hasMoreElements() && count < seqCount) {
345         String JavaDoc id = (String JavaDoc)e.nextElement();
346         ids.value[count] = id;
347         count++;
348         }
349
350         // construct an iterator if necessary
351
if (seqCount < offerCount) {
352         // create a sequence holding the remaining offer IDs
353
int restCount = offerCount - seqCount;
354         String JavaDoc[] rest = new String JavaDoc[restCount];
355
356         int pos = 0;
357         while (e.hasMoreElements() && pos < restCount) {
358             String JavaDoc id = (String JavaDoc)e.nextElement();
359             rest[pos] = id;
360             pos++;
361         }
362
363         OfferIdIteratorImpl iter = new OfferIdIteratorImpl(rest);
364         iter._this_object( _orb() );
365         id_itr.value = iter._this();
366         }
367     }
368     finally {
369         m_db.end();
370     }
371     }
372
373
374     public void list_proxies(
375                  int how_many,
376                  OfferIdSeqHolder ids,
377                  OfferIdIteratorHolder id_itr)
378     throws NotImplemented
379     {
380     // obtain the list of all service type names
381
SpecifiedServiceTypes whichTypes = new SpecifiedServiceTypes();
382     //whichTypes._default(ListOption.all);
383
//GB: whichTypes.all_dummy((short)0);
384
whichTypes.__default();
385
386     String JavaDoc[] allNames = m_repos.list_types(whichTypes);
387
388     try {
389         m_db.begin(OfferDatabase.READ);
390
391         // construct a Vector of all offers for all types
392
Vector vec = new Vector();
393         for (int i = 0; i < allNames.length; i++) {
394         String JavaDoc[] seq = m_db.getProxyOfferIds(allNames[i]);
395         if (seq != null)
396             for (int n = 0; n < seq.length; n++)
397             vec.addElement(seq[n]);
398         }
399
400         int offerCount = vec.size();
401         int seqCount = Math.min(offerCount, how_many);
402
403         ids.value = new String JavaDoc[seqCount];
404         int count = 0;
405         Enumeration e = vec.elements();
406         while (e.hasMoreElements() && count < seqCount) {
407         String JavaDoc id = (String JavaDoc)e.nextElement();
408         ids.value[count] = id;
409         count++;
410         }
411
412         // construct an iterator if necessary
413
if (seqCount < offerCount) {
414         // create a sequence holding the remaining offer IDs
415
int restCount = offerCount - seqCount;
416         String JavaDoc[] rest = new String JavaDoc[restCount];
417
418         int pos = 0;
419         while (e.hasMoreElements() && pos < restCount) {
420             String JavaDoc id = (String JavaDoc)e.nextElement();
421             rest[pos] = id;
422             pos++;
423         }
424
425         OfferIdIteratorImpl iter = new OfferIdIteratorImpl(rest);
426         iter._this_object( _orb() );
427         id_itr.value = iter._this();
428         }
429     }
430     finally {
431         m_db.end();
432     }
433     }
434 }
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
Popular Tags