KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > explorer > CosTrading > ProxyOffers


1 /*===========================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2004 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Sylvain Leblanc.
23 Contributor(s): ______________________________________.
24
25 ===========================================================================*/

26
27 package org.objectweb.openccm.explorer.CosTrading;
28
29 /** OMG Trading Service imports. */
30 import org.omg.CosTrading.Admin;
31 import org.omg.CosTrading.Proxy;
32 import org.omg.CosTrading.OfferIdIterator;
33 import org.omg.CosTrading.ProxyPackage.ProxyInfo;
34 import org.omg.CosTrading.OfferIdSeqHolder;
35 import org.omg.CosTrading.OfferIdIteratorHolder;
36
37 /**
38  * Wrapper class used to provide a node in the administration console
39  * tree which children are
40  * <code>org.omg.CosTrading.ProxyPackage.ProxyInfo</code> instances.
41  *
42  * @author <a HREF="mailto:Sylvain.Leblanc@lifl.fr">Sylvain Leblanc</a>
43  * @version 0.1
44  */

45 public class ProxyOffers {
46
47     // ==================================================================
48
//
49
// Internal state.
50
//
51
// ==================================================================
52

53     /**
54      * The CosTrading Admin interface used to obtain the CosTrading
55      * Proxies OfferId.
56      */

57     protected Admin admin_;
58
59     /**
60      * The CosTrading Proxy interface used to obtain the CosTrading
61      * ProxyInfo references from OfferIds.
62      */

63     protected Proxy proxy_;
64
65     // ==================================================================
66
//
67
// Constructors.
68
//
69
// ==================================================================
70

71     /**
72      * Default constructor.
73      *
74      * @param admin The CosTrading Admin reference of the trader which
75      * contains Offers to view.
76      */

77     public ProxyOffers(Admin admin)
78     {
79         admin_ = admin;
80         proxy_ = admin.proxy_if();
81     }
82
83     // ==================================================================
84
//
85
// Internal methods.
86
//
87
// ==================================================================
88

89     // ==================================================================
90
//
91
// Public methods.
92
//
93
// ==================================================================
94

95     /**
96      * Returns all the CosTrading Proxy Offers contained in the
97      * trader. This method retrieves offers 100 by 100.
98      *
99      * @return All CosTrading Proxy Offers contained in the trader.
100      */

101     public ProxyInfo[] getOffers()
102     {
103         return getOffers(100);
104     }
105
106     /**
107      * Returns all the CosTrading proxy Offers contained in the
108      * trader.
109      *
110      * @param how_many_step The step used to retrieve offers.
111      * @return All CosTrading proxy Offers contained in the trader.
112      */

113     public ProxyInfo[] getOffers(int how_many_step)
114     {
115         // Retrieving offer id list
116
java.util.List JavaDoc oid_list = new java.util.LinkedList JavaDoc();
117         OfferIdSeqHolder oid_seq = new OfferIdSeqHolder();
118         OfferIdIteratorHolder oid_iter = new OfferIdIteratorHolder();
119         try {
120
121             // performing the distant "list_offers" op.
122
admin_.list_proxies(how_many_step, oid_seq, oid_iter);
123
124             // Storing offer ids returned in the sequence.
125
if (oid_seq.value.length == 0) return new ProxyInfo[0];
126             for (int i=0 ; i<oid_seq.value.length ; i++) {
127                 oid_list.add(oid_seq.value[i]);
128             }
129
130             // Storing offer ids in the iterator.
131
if (oid_iter.value != null) {
132                 OfferIdIterator iter = oid_iter.value;
133                 boolean again = iter.next_n(how_many_step, oid_seq);
134                 {
135                     for (int i=0 ; i<oid_seq.value.length ; i++) {
136                         oid_list.add(oid_seq.value[i]);
137                     }
138                     again = iter.next_n(how_many_step, oid_seq);
139                 } while (again);
140                 iter.destroy();
141             }
142         } catch (org.omg.CosTrading.NotImplemented ex) {
143             // Returning empty array
144
return new ProxyInfo[0];
145         }
146
147         // Constructing the ProxyInfo seq
148
java.util.List JavaDoc info_list = new java.util.LinkedList JavaDoc();
149         for (java.util.Iterator JavaDoc iter = oid_list.iterator() ; iter.hasNext() ; )
150         {
151             String JavaDoc oid = (String JavaDoc)iter.next();
152             try {
153                 ProxyInfo info = proxy_.describe_proxy(oid);
154                 info_list.add(info);
155             } catch (org.omg.CosTrading.IllegalOfferId ex) {
156                 // should not happened
157
} catch (org.omg.CosTrading.UnknownOfferId ex) {
158                 // the offer has been destroyed during the session
159
// try the next one
160
} catch (org.omg.CosTrading.ProxyPackage.NotProxyOfferId ex) {
161                 // should not happened until Trader bug
162
}
163         }
164
165         return (ProxyInfo[])info_list.toArray(new ProxyInfo[0]);
166     }
167
168 }
169
Popular Tags