1 2 5 14 package org.jacorb.trading.db.pse.offers; 15 16 17 import java.io.*; 18 import java.util.*; 19 import COM.odi.*; 20 import COM.odi.util.*; 21 import org.omg.CORBA.*; 22 import org.omg.CosTrading.Lookup; 23 import org.omg.CosTrading.RegisterPackage.*; 24 import org.omg.CosTrading.ProxyPackage.*; 25 import org.omg.CosTrading.Property; 26 import org.omg.CosTrading.Policy; 27 import org.omg.CosTradingDynamic.*; 28 import org.jacorb.trading.db.OfferDatabase; 29 import org.jacorb.trading.db.pse.util.TransactionMgr; 30 import org.jacorb.trading.util.*; 31 32 33 public class OfferDatabaseImpl implements OfferDatabase 34 { 35 private Database m_database; 36 private TransactionMgr m_txnMgr; 37 private OSHashtable m_offerLists; 38 39 private static final String LISTS_ROOT = "offer_lists"; 40 41 42 private OfferDatabaseImpl() 43 { 44 } 45 46 47 public OfferDatabaseImpl(COM.odi.Database database, TransactionMgr txnMgr) 48 { 49 m_database = database; 50 m_txnMgr = txnMgr; 51 52 boolean foundRoot = false; 53 Transaction tr = null; 54 55 try { 56 tr = Transaction.begin(ObjectStore.READONLY); 57 m_offerLists = (OSHashtable)m_database.getRoot(LISTS_ROOT); 58 tr.commit(ObjectStore.RETAIN_HOLLOW); 59 foundRoot = true; 60 } 61 catch (DatabaseRootNotFoundException e) { 62 tr.abort(ObjectStore.RETAIN_HOLLOW); 63 } 64 65 if (! foundRoot) { 66 tr = Transaction.begin(ObjectStore.UPDATE); 67 m_offerLists = new OSHashtable(); 68 m_database.createRoot(LISTS_ROOT, m_offerLists); 69 tr.commit(ObjectStore.RETAIN_HOLLOW); 70 } 71 } 72 73 74 75 public boolean validateOfferId(String offerId) 76 { 77 return OfferList.validateOfferId(offerId); 78 } 79 80 81 82 public boolean isTypeSupported(org.omg.CORBA.Any any) 83 { 84 boolean result; 85 86 if (PropUtil.isDynamicProperty(any.type())) { 89 DynamicProp dp = DynamicPropHelper.extract(any); 90 result = AnyValue.isTypeSupported(dp.extra_info.type()); 91 } 92 else 93 result = AnyValue.isTypeSupported(any.type()); 94 95 return result; 96 } 97 98 99 100 public void begin(int mode) 101 { 102 m_txnMgr.begin(); 103 } 104 105 106 107 public void end() 108 { 109 m_txnMgr.commit(ObjectStore.RETAIN_HOLLOW); 110 } 111 112 113 114 public boolean exists(String offerId) 115 { 116 boolean result = false; 117 118 OfferList list = (OfferList)m_offerLists.get(whichService(offerId)); 119 if (list != null) 120 result = list.exists(offerId); 121 122 return result; 123 } 124 125 126 127 public boolean isProxy(String offerId) 128 { 129 boolean result = false; 130 131 OfferList list = (OfferList)m_offerLists.get(whichService(offerId)); 132 if (list != null) 133 result = list.isProxy(offerId); 134 135 return result; 136 } 137 138 139 140 public String create( 141 String serviceType, 142 org.omg.CORBA.Object obj, 143 Property[] props) 144 { 145 OfferList list = (OfferList)m_offerLists.get(serviceType); 146 if (list == null) { 147 list = new OfferList(serviceType); 148 m_offerLists.put(serviceType, list); 149 } 150 151 return list.create(obj, props); 152 } 153 154 155 156 public String createProxy( 157 Lookup target, 158 String serviceType, 159 Property[] props, 160 boolean ifMatchAll, 161 String recipe, 162 Policy[] policies) 163 { 164 OfferList list = (OfferList)m_offerLists.get(serviceType); 165 if (list == null) { 166 list = new OfferList(serviceType); 167 m_offerLists.put(serviceType, list); 168 } 169 170 return list.createProxy(target, props, ifMatchAll, recipe, policies); 171 } 172 173 174 175 public void remove(String offerId) 176 { 177 OfferList list = (OfferList)m_offerLists.get(whichService(offerId)); 178 if (list != null) 179 list.remove(offerId); 180 } 181 182 183 184 public void removeProxy(String offerId) 185 { 186 OfferList list = (OfferList)m_offerLists.get(whichService(offerId)); 187 if (list != null) 188 list.removeProxy(offerId); 189 } 190 191 192 193 public OfferInfo describe(String offerId) 194 { 195 OfferInfo result = null; 196 197 OfferList list = (OfferList)m_offerLists.get(whichService(offerId)); 198 if (list != null) 199 result = list.describe(offerId); 200 201 return result; 202 } 203 204 205 206 public ProxyInfo describeProxy(String offerId) 207 { 208 ProxyInfo result = null; 209 210 OfferList list = (OfferList)m_offerLists.get(whichService(offerId)); 211 if (list != null) 212 result = list.describeProxy(offerId); 213 214 return result; 215 } 216 217 218 219 public void modify(String offerId, Property[] props) 220 { 221 OfferList list = (OfferList)m_offerLists.get(whichService(offerId)); 222 if (list != null) 223 list.modify(offerId, props); 224 } 225 226 227 228 public Hashtable getOffers(String serviceType) 229 { 230 Hashtable result = null; 231 232 OfferList list = (OfferList)m_offerLists.get(serviceType); 233 if (list != null) 234 result = list.getOffers(); 235 236 return result; 237 } 238 239 240 241 public String [] getOfferIds(String serviceType) 242 { 243 String [] result = null; 244 245 OfferList list = (OfferList)m_offerLists.get(serviceType); 246 if (list != null) 247 result = list.getOfferIds(); 248 249 return result; 250 } 251 252 253 254 public Hashtable getProxyOffers(String serviceType) 255 { 256 Hashtable result = null; 257 258 OfferList list = (OfferList)m_offerLists.get(serviceType); 259 if (list != null) 260 result = list.getProxyOffers(); 261 262 return result; 263 } 264 265 266 267 public String [] getProxyOfferIds(String serviceType) 268 { 269 String [] result = null; 270 271 OfferList list = (OfferList)m_offerLists.get(serviceType); 272 if (list != null) 273 result = list.getProxyOfferIds(); 274 275 return result; 276 } 277 278 279 280 public String whichService(String offerId) 281 { 282 return OfferList.whichService(offerId); 283 } 284 } 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | Popular Tags |