1 2 5 14 package org.jacorb.trading.db.pse.offers; 15 16 17 import java.util.*; 18 import COM.odi.*; 19 import COM.odi.util.*; 20 import org.omg.CORBA.*; 21 import org.omg.CosTrading.Lookup; 22 import org.omg.CosTrading.RegisterPackage.*; 23 import org.omg.CosTrading.ProxyPackage.*; 24 import org.omg.CosTrading.Property; 25 import org.omg.CosTrading.Policy; 26 27 28 public class OfferList 29 { 30 private String m_serviceType; 31 private OSHashtable m_offers; 32 private OSHashtable m_proxies; 33 private int m_nextId; 34 35 private static final char ID_SEP = '/'; 36 37 38 private OfferList() 39 { 40 } 41 42 43 public OfferList(String serviceType) 44 { 45 m_serviceType = serviceType; 46 m_offers = new OSHashtable(); 47 m_proxies = new OSHashtable(); 48 m_nextId = 1; 49 } 50 51 52 public String getServiceType() 53 { 54 return m_serviceType; 55 } 56 57 58 59 public static boolean validateOfferId(String offerId) 60 { 61 boolean result = false; 62 63 if (offerId != null) { 64 int index = offerId.indexOf(ID_SEP); 66 result = (index > 0); 67 } 68 69 return result; 70 } 71 72 73 public boolean exists(String offerId) 74 { 75 return (m_offers.containsKey(offerId) || m_proxies.containsKey(offerId)); 76 } 77 78 79 public boolean isProxy(String offerId) 80 { 81 return m_proxies.containsKey(offerId); 82 } 83 84 85 public String create(org.omg.CORBA.Object obj, Property[] props) 86 { 87 String result = null; 88 89 result = m_serviceType + ID_SEP + m_nextId; 90 m_nextId++; 91 Offer offer = new Offer(result, obj, props); 92 m_offers.put(result, offer); 93 94 return result; 95 } 96 97 98 public String createProxy( 99 Lookup target, 100 Property[] props, 101 boolean ifMatchAll, 102 String recipe, 103 Policy[] policies) 104 { 105 String result = null; 106 107 result = m_serviceType + ID_SEP + m_nextId; 108 m_nextId++; 109 ProxyOffer proxy = 110 new ProxyOffer(result, target, props, ifMatchAll, recipe, policies); 111 m_proxies.put(result, proxy); 112 113 return result; 114 } 115 116 117 public void remove(String offerId) 118 { 119 if (m_offers.containsKey(offerId)) 120 m_offers.remove(offerId); 121 } 122 123 124 public void removeProxy(String offerId) 125 { 126 if (m_proxies.containsKey(offerId)) 127 m_proxies.remove(offerId); 128 } 129 130 131 public OfferInfo describe(String offerId) 132 { 133 OfferInfo result = null; 134 135 Offer offer = (Offer)m_offers.get(offerId); 136 if (offer != null) { 137 result = offer.describe(); 138 result.type = m_serviceType; 139 } 140 141 return result; 142 } 143 144 145 public ProxyInfo describeProxy(String offerId) 146 { 147 ProxyInfo result = null; 148 149 ProxyOffer proxy = (ProxyOffer)m_proxies.get(offerId); 150 if (proxy != null) { 151 result = proxy.describe(); 152 result.type = m_serviceType; 153 } 154 155 return result; 156 } 157 158 159 public boolean modify(String offerId, Property[] props) 160 { 161 boolean result = false; 162 163 Offer offer = (Offer)m_offers.get(offerId); 164 if (offer != null) { 165 offer.modify(props); 166 result = true; 167 } 168 169 return result; 170 } 171 172 173 public Hashtable getOffers() 174 { 175 Hashtable result = new Hashtable(); 176 177 Enumeration e = m_offers.keys(); 178 while (e.hasMoreElements()) { 179 String offerId = (String )e.nextElement(); 180 Offer offer = (Offer)m_offers.get(offerId); 181 OfferInfo info = offer.describe(); 182 info.type = m_serviceType; 183 result.put(offerId, info); 184 } 185 186 return result; 187 } 188 189 190 public String [] getOfferIds() 191 { 192 String [] result = new String [m_offers.size()]; 193 194 int count = 0; 195 Enumeration e = m_offers.keys(); 196 while (e.hasMoreElements()) 197 result[count++] = (String )e.nextElement(); 198 199 return result; 200 } 201 202 203 public Hashtable getProxyOffers() 204 { 205 Hashtable result = new Hashtable(); 206 207 Enumeration e = m_proxies.keys(); 208 while (e.hasMoreElements()) { 209 String offerId = (String )e.nextElement(); 210 ProxyOffer proxy = (ProxyOffer)m_proxies.get(offerId); 211 ProxyInfo info = proxy.describe(); 212 info.type = m_serviceType; 213 result.put(offerId, info); 214 } 215 216 return result; 217 } 218 219 220 public String [] getProxyOfferIds() 221 { 222 String [] result = new String [m_proxies.size()]; 223 224 int count = 0; 225 Enumeration e = m_proxies.keys(); 226 while (e.hasMoreElements()) 227 result[count++] = (String )e.nextElement(); 228 229 return result; 230 } 231 232 233 public static String whichService(String offerId) 234 { 235 String result = null; 236 237 int index = offerId.indexOf(ID_SEP); 238 if (index > 0) 239 result = offerId.substring(0, index); 240 241 return result; 242 } 243 244 245 public int hashCode() 246 { 247 return m_serviceType.hashCode(); 248 } 249 250 251 public boolean equals(java.lang.Object o) 252 { 253 OfferList list = (OfferList)o; 254 return m_serviceType.equals(list.m_serviceType); 255 } 256 } 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | Popular Tags |