1 26 27 package org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.binder; 28 29 import org.objectweb.openccm.descriptor.componentassembly.*; 31 import org.objectweb.openccm.corba.TheTradingService; 32 import org.objectweb.openccm.corba.trader.QueryPoliciesHelper; 33 34 47 public class TraderqueryDeployer 48 { 49 50 private static final String header = "Trading Service query problem: "; 51 52 58 59 protected String _oid; 60 61 67 70 public 71 TraderqueryDeployer () 72 { 73 this._oid = null; 75 } 76 77 83 90 protected boolean 91 isReturnCardPolicyDefined(java.util.List policies) 92 { 93 for (java.util.Iterator iter = policies.iterator() ; iter.hasNext() ; ) 94 { 95 Traderpolicy tp = (Traderpolicy)iter.next(); 96 String policy_name = tp.getTraderpolicyname().getValue().trim().toLowerCase(); 97 if (policy_name.equals("return_card")) return true; 98 } 99 return false; 100 } 101 102 112 public org.omg.CORBA.Object 113 lookup(Traderquery desc) 114 { 115 String st = desc.getTraderservicetypename().getValue(); 117 String constraint = desc.getTraderconstraint().getValue(); 118 String pref = "first"; if (desc.getTraderpreference() != null) 121 pref = desc.getTraderpreference().getValue(); 122 123 java.util.List policies = desc.getTraderpolicyList(); 125 java.util.List cos_policies = new java.util.LinkedList (); 126 for (java.util.Iterator iter = policies.iterator() ; iter.hasNext() ; ) 127 { 128 Traderpolicy tp = (Traderpolicy)iter.next(); 129 org.omg.CosTrading.Policy cos_policy = construct_policy(tp); 130 if (cos_policy != null) cos_policies.add(cos_policy); 131 } 132 if (! isReturnCardPolicyDefined(policies)) { 134 org.omg.CosTrading.Policy return_card_policy = QueryPoliciesHelper.construct_policy("return_card", "1"); 135 cos_policies.add(return_card_policy); 136 } 137 org.omg.CosTrading.Policy[] cos_policies_arr = (org.omg.CosTrading.Policy[])cos_policies.toArray(new org.omg.CosTrading.Policy[0]); 138 139 java.util.List props = desc.getTraderspecifiedpropList(); 141 org.omg.CosTrading.LookupPackage.SpecifiedProps cos_props = construct_props(props); 142 143 144 org.omg.CosTrading.OfferSeqHolder offerSeq; 146 offerSeq = new org.omg.CosTrading.OfferSeqHolder(); 147 org.omg.CosTrading.OfferIteratorHolder offerIter; 148 offerIter = new org.omg.CosTrading.OfferIteratorHolder(); 149 org.omg.CosTrading.PolicyNameSeqHolder limits; 150 limits = new org.omg.CosTrading.PolicyNameSeqHolder(); 151 152 org.omg.CORBA.Object result = null; 154 try { 155 TheTradingService.getLookup().query(st, constraint, 157 pref, cos_policies_arr, 158 cos_props, 1, 159 offerSeq, offerIter, 160 limits); 161 if (offerSeq.value.length != 0) { 163 result = offerSeq.value[0].reference; 165 } 166 if (offerIter.value != null) { 167 if (result == null) { 170 org.omg.CosTrading.OfferSeqHolder offerSeqIter = new org.omg.CosTrading.OfferSeqHolder(); 171 offerIter.value.next_n(1, offerSeqIter); 172 if (offerSeqIter.value.length != 0) result = (offerSeqIter.value)[0].reference; 173 } 174 offerIter.value.destroy(); 176 } 177 return result; 179 } catch (org.omg.CosTrading.IllegalServiceType ex) { 180 System.err.println(TraderqueryDeployer.header + 181 "bad service type name '" + st + "'."); 182 } catch (org.omg.CosTrading.UnknownServiceType ex) { 183 System.err.println(TraderqueryDeployer.header + 184 "bad service type name '" + st + "'."); 185 } catch (org.omg.CosTrading.IllegalConstraint ex) { 186 System.err.println(TraderqueryDeployer.header + 187 "bad constraint '" + constraint + "'."); 188 } catch (org.omg.CosTrading.LookupPackage.IllegalPreference ex) { 189 System.err.println(TraderqueryDeployer.header + 190 "bad preference '" + pref + "'."); 191 } catch (org.omg.CosTrading.LookupPackage.IllegalPolicyName ex) { 192 System.err.println(TraderqueryDeployer.header + 193 "bad policy name '" + ex.name + "'."); 194 } catch (org.omg.CosTrading.LookupPackage.PolicyTypeMismatch ex) { 195 System.err.println(TraderqueryDeployer.header + 196 "bad policy type for '" + ex.the_policy.name + "'."); 197 } catch (org.omg.CosTrading.LookupPackage.InvalidPolicyValue ex) { 198 System.err.println(TraderqueryDeployer.header + 199 "bad policy value for '" + ex.the_policy.name + "'."); 200 } catch (org.omg.CosTrading.IllegalPropertyName ex) { 201 System.err.println(TraderqueryDeployer.header + 202 "bad property name '" + ex.name + "'."); 203 } catch (org.omg.CosTrading.DuplicatePropertyName ex) { 204 System.err.println(TraderqueryDeployer.header + 205 "duplicated property name '" + ex.name + "'."); 206 } catch (org.omg.CosTrading.DuplicatePolicyName ex) { 207 System.err.println(TraderqueryDeployer.header + 208 "duplicated policy name " + ex.name + "."); 209 } 210 return null; 211 } 212 213 227 protected org.omg.CosTrading.Policy 228 construct_policy(Traderpolicy tp) 229 { 230 String name = tp.getTraderpolicyname().getValue(); 231 String value = tp.getTraderpolicyvalue().getValue(); 232 return QueryPoliciesHelper.construct_policy(name, value); 233 } 234 235 243 protected org.omg.CosTrading.LookupPackage.SpecifiedProps 244 construct_props(java.util.List trader_props) 245 { 246 if (trader_props.size() == 0) { 248 return org.objectweb.openccm.corba.trader.SpecifiedPropsWrapper.create_none(); 249 } 250 251 java.util.List cos_props = new java.util.LinkedList (); 254 for (java.util.Iterator iter = trader_props.iterator() ; iter.hasNext() ; ) 255 { 256 Traderspecifiedprop tsp = (Traderspecifiedprop)iter.next(); 257 String prop_name = tsp.getValue(); 258 cos_props.add(prop_name); 259 } 260 String [] names = (String [])cos_props.toArray(new String [0]); 261 return org.objectweb.openccm.corba.trader.SpecifiedPropsWrapper.create_some(names); 262 } 263 264 270 277 public org.omg.CORBA.Object 278 deploy(Traderquery reg) 279 { 280 return lookup(reg); 281 } 282 } 283 | Popular Tags |