KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > trading > util > QueryContainer


1 package org.jacorb.trading.util;
2
3 import org.omg.CosTrading.*;
4 import org.omg.CosTrading.LookupPackage.*;
5 import org.omg.CORBA.*;
6 import java.lang.*;
7
8 /**
9  * This class bundles the parameters to Lookup.query(). QueryPropagator
10  * accesses the attributes directly, while Lookup.query() has to go
11  * via the getXXX()-methods. The synchronization with the executing
12  * QueryThread is done via a binary semaphore.
13  *
14  * @author Nicolas Noffke
15  * $Log: QueryContainer.java,v $
16  * Revision 1.5 2003/10/28 17:22:52 simon.mcqueen
17  * Javadoc fixes only. @author can only be used at class level.
18  *
19  * Revision 1.4 2002/03/19 09:25:46 nicolas
20  * updated copyright to 2002
21  *
22  * Revision 1.3 2002/03/19 11:10:13 brose
23  * *** empty log message ***
24  *
25  * Revision 1.2 2002/03/17 18:45:24 brose
26  * *** empty log message ***
27  *
28  * Revision 1.4 1999/11/25 16:08:19 brose
29  * cosmetics
30  *
31  * Revision 1.3 1999/11/08 08:11:52 brose
32  * *** empty log message ***
33  *
34  * Revision 1.2 1999/11/03 18:04:06 brose
35  * *** empty log message ***
36  *
37  * Revision 1.1 1999-10-06 12:06:59+02 brose
38  * *** empty log message ***
39  *
40  * Revision 1.2 1999-10-05 16:08:49+02 brose
41  * New directory structure for trading service
42  *
43  * Revision 1.1 1999-10-04 10:51:26+02 brose
44  * *** empty log message ***
45  *
46  */

47
48 public class QueryContainer {
49     protected String JavaDoc m_type;
50     protected String JavaDoc m_constr;
51     protected String JavaDoc m_pref;
52     protected org.omg.CosTrading.Policy[] m_policies;
53     protected SpecifiedProps m_desired_props;
54     protected int m_how_many;
55     protected OfferSeqHolder m_offers;
56     protected OfferIteratorHolder m_offer_itr;
57     protected PolicyNameSeqHolder m_limits_applied;
58     protected UserException m_exception = null;
59     protected Lookup m_target;
60     protected Semaphore m_mutex;
61
62     public int no = 0;
63     public static int count = 0;
64
65     /**
66      * The constructor. takes all "in"-Parameters from Lookup.query()
67      *
68      * @param type The ServiceType
69      * @param contr The Constraints
70      * @param pref The Preferences
71      * @param policies An array holding the queries policies
72      * @param desired_props The desired properties
73      * @param how_many No. of offers to be returned
74      * @param target The lookup-interface of the queries target trader
75      */

76     public QueryContainer(String JavaDoc type,
77               String JavaDoc constr,
78               String JavaDoc pref,
79               org.omg.CosTrading.Policy[] policies,
80               SpecifiedProps desired_props,
81               int how_many,
82               Lookup target) {
83     m_type = type;
84     m_constr = constr;
85     m_pref = pref;
86     m_policies = policies;
87     m_desired_props = desired_props;
88     m_how_many = how_many;
89     m_target = target;
90
91     no = count++;
92
93     // The "out"-Parameters of query are instanciated here,
94
// for lookup.query() does not have to store them as well.
95
m_offers = new OfferSeqHolder();
96     m_offer_itr = new OfferIteratorHolder();
97     m_limits_applied = new PolicyNameSeqHolder();
98
99     m_mutex = new Semaphore(0);
100     
101     }
102
103
104    /**
105      * Convenience constructor, for keeping the interface small. Takes
106      * another QueryContainer to get the "in"-Parameters of query().
107      *
108      * @param templ The template to take the values from
109      * @param target The lookup-interface of the queries target trader
110      */

111     public QueryContainer(QueryContainer templ, Lookup target){
112     this(templ.m_type, templ.m_constr, templ.m_pref,
113          templ.m_policies, templ.m_desired_props,
114          templ.m_how_many, target);
115     }
116
117     /**
118      * This method blocks until the result is ready.
119      */

120     public void resultReady(){
121     m_mutex.P(); // Blocks, until QueryThread issues V()
122
// m_mutex.V(); // not really necessary since object is never used again
123
}
124
125     /**
126      * Returns any UserException (i.e. the ones that query() explicitly throws)
127      * that was caught executing this query.<br>
128      * *Not* safe to call until resultReady returned.
129      *
130      * @return Null, if query returned correctly.
131      */

132     public UserException getException(){
133     return m_exception;
134     }
135     
136     /**
137      * Returnes the Offers returned by the remote query().<br>
138      * *Not* safe to call until resultReady returned.
139      *
140      * @return The offers
141      */

142     public OfferSeqHolder getOffers(){
143     return m_offers;
144     }
145
146     /**
147      * Returnes the OfferIterator returned by the remote query().<br>
148      * *Not* safe to call until resultReady returned.
149      *
150      * @return The offer iterator
151      */

152     public OfferIteratorHolder getItr(){
153     return m_offer_itr;
154     }
155
156     /**
157      * Returnes the policies_applied-sequence returned by the remote query.<br>
158      * *Not* safe to call until resultReady returned.
159      *
160      * @return The limits_applied policies
161      */

162     public PolicyNameSeqHolder getLimits(){
163     return m_limits_applied;
164     }
165     
166 } // QueryContainer
167

168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
Popular Tags