1 26 27 package org.objectweb.openccm.explorer.CosTrading; 28 29 30 import org.objectweb.openccm.corba.trader.SpecifiedPropsWrapper; 31 import org.omg.CosTrading.Policy; 32 import org.omg.CosTrading.Lookup; 33 import org.omg.CosTrading.Offer; 34 35 import javax.swing.JOptionPane ; 36 37 45 public class Query { 46 47 53 54 protected String label_; 55 56 59 protected Lookup lookup_; 60 61 62 protected String service_type_; 63 64 65 protected String constraint_; 66 67 68 protected String pref_; 69 70 71 protected Policy[] policies_; 72 73 74 protected Queries parent_; 75 76 private boolean removed = false; 77 78 84 94 public Query(String query_label, Queries parent, String service_type, 95 String constraint, String pref, Policy[] policies) 96 { 97 label_ = query_label; 98 parent_ = parent; 99 lookup_ = parent.getLookup(); 100 service_type_ = service_type; 101 constraint_ = constraint; 102 pref_ = pref; 103 policies_ = policies; 104 } 105 106 112 119 protected void fatalError(String message) { 120 removed = true; 121 JOptionPane.showMessageDialog(null, message, "Error on query '" + label_ + "'", JOptionPane.ERROR_MESSAGE); 122 parent_.removeQuery(this); 123 } 124 125 131 136 public Offer[] getOffers() { 137 return getOffers(100); 138 } 139 140 146 public Offer[] getOffers(int how_many_step) { 147 148 if (removed) return new Offer[0]; 149 150 org.omg.CosTrading.LookupPackage.SpecifiedProps cos_props; 152 cos_props = SpecifiedPropsWrapper.create_all(); 153 154 org.omg.CosTrading.OfferSeqHolder offerSeq; 156 offerSeq = new org.omg.CosTrading.OfferSeqHolder(); 157 org.omg.CosTrading.OfferIteratorHolder offerIter; 158 offerIter = new org.omg.CosTrading.OfferIteratorHolder(); 159 org.omg.CosTrading.PolicyNameSeqHolder limits; 160 limits = new org.omg.CosTrading.PolicyNameSeqHolder(); 161 162 try { 164 lookup_.query(service_type_, constraint_, pref_, policies_, 165 cos_props, how_many_step, offerSeq, offerIter, limits); 166 167 java.util.Vector offerAnswer = new java.util.Vector (); 169 for (int i = 0 ; i < offerSeq.value.length ; i++) { 170 org.omg.CosTrading.Offer offer = (offerSeq.value)[i]; 171 offerAnswer.add(offer); 172 } 173 174 if (offerIter.value != null) { 176 org.omg.CosTrading.OfferSeqHolder offerSeqIter = new org.omg.CosTrading.OfferSeqHolder(); 177 boolean more; 178 do { 179 more = offerIter.value.next_n(how_many_step, offerSeqIter); 180 for (int i = 0 ; i < offerSeqIter.value.length ; i++) { 181 org.omg.CosTrading.Offer offer = (offerSeqIter.value)[i]; 182 offerAnswer.add(offer); 183 } 184 } while(more); 185 offerIter.value.destroy(); 186 } 187 return (Offer[]) offerAnswer.toArray(new Offer[0]); 188 189 } catch (org.omg.CosTrading.IllegalServiceType ex) { 190 fatalError("bad service type name '" + service_type_ + "'."); 191 } catch (org.omg.CosTrading.UnknownServiceType ex) { 192 fatalError("bad service type name '" + service_type_ + "'."); 193 } catch (org.omg.CosTrading.IllegalConstraint ex) { 194 fatalError("bad constraint '" + constraint_ + "'."); 195 } catch (org.omg.CosTrading.LookupPackage.IllegalPreference ex) { 196 fatalError("bad preference '" + pref_ + "'."); 197 } catch (org.omg.CosTrading.LookupPackage.IllegalPolicyName ex) { 198 fatalError("bad policy name '" + ex.name + "'."); 199 } catch (org.omg.CosTrading.LookupPackage.PolicyTypeMismatch ex) { 200 fatalError("bad policy type for '" + ex.the_policy.name + "'."); 201 } catch (org.omg.CosTrading.LookupPackage.InvalidPolicyValue ex) { 202 fatalError("bad policy value for '" + ex.the_policy.name + "'."); 203 } catch (org.omg.CosTrading.IllegalPropertyName ex) { 204 fatalError("bad property name '" + ex.name + "'."); 205 } catch (org.omg.CosTrading.DuplicatePropertyName ex) { 206 fatalError("duplicated property name '" + ex.name + "'."); 207 } catch (org.omg.CosTrading.DuplicatePolicyName ex) { 208 fatalError("duplicated policy name " + ex.name + "."); 209 } 210 return new Offer[0]; 211 } 212 213 218 public Lookup getLookup() { 219 return lookup_; 220 } 221 222 227 public String getQueryLabel() { 228 return label_; 229 } 230 231 236 public String getServiceTypeName() { 237 return service_type_; 238 } 239 240 245 public String getConstraint() { 246 return constraint_; 247 } 248 249 254 public String getPref() { 255 return pref_; 256 } 257 258 263 public Policy[] getPolicies() { 264 return policies_; 265 } 266 267 } 268 | Popular Tags |