KickJava   Java API By Example, From Geeks To Geeks.

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


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.Register;
32 import org.omg.CosTrading.OfferIdIterator;
33 import org.omg.CosTrading.OfferIdSeqHolder;
34 import org.omg.CosTrading.OfferIdIteratorHolder;
35 import org.omg.CosTrading.RegisterPackage.OfferInfo;
36
37 /**
38  * Wrapper class used to provide a node in the administration console
39  * tree which children are <code>org.omg.CosTrading.Offer</code> instances.
40  *
41  * @author <a HREF="mailto:Sylvain.Leblanc@lifl.fr">Sylvain Leblanc</a>
42  * @version 0.1
43  */

44 public class Offers {
45
46     // ==================================================================
47
//
48
// Internal state.
49
//
50
// ==================================================================
51

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

56     protected Admin admin_;
57
58     /**
59      * The CosTrading Register interface used to obtain the CosTrading
60      * OfferInfo references from OfferIds.
61      */

62     protected Register reg_;
63
64     // ==================================================================
65
//
66
// Constructors.
67
//
68
// ==================================================================
69

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

76     public Offers(Admin admin) {
77         admin_ = admin;
78         reg_ = admin_.register_if();
79     }
80
81     // ==================================================================
82
//
83
// Internal methods.
84
//
85
// ==================================================================
86

87     // ==================================================================
88
//
89
// Public methods.
90
//
91
// ==================================================================
92

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

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

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