View Javadoc
1 /* 2 * $Header: /cvsroot/ebxmlrr/jaxr/src/com/sun/xml/registry/ebxml/BulkResponseImpl.java,v 1.16 2003/07/23 01:14:51 farrukh_najmi Exp $ 3 * 4 * 5 */ 6 7 package com.sun.xml.registry.ebxml; 8 9 import javax.activation.DataHandler; 10 import javax.xml.registry.*; 11 import java.util.*; 12 13 import org.oasis.ebxml.registry.bindings.rs.*; 14 import org.oasis.ebxml.registry.bindings.rs.types.*; 15 import org.oasis.ebxml.registry.bindings.query.*; 16 import org.oasis.ebxml.registry.bindings.rim.ClassificationNodeType; 17 import org.oasis.ebxml.registry.bindings.rim.AuditableEventType; 18 import org.oasis.ebxml.registry.bindings.rim.ClassificationType; 19 import org.oasis.ebxml.registry.bindings.rim.ClassificationSchemeType; 20 import org.oasis.ebxml.registry.bindings.rim.LeafRegistryObjectListTypeItem; 21 import org.oasis.ebxml.registry.bindings.rim.OrganizationType; 22 import org.oasis.ebxml.registry.bindings.rim.AssociationType1; 23 import org.oasis.ebxml.registry.bindings.rim.RegistryPackage; 24 import org.oasis.ebxml.registry.bindings.rim.ExternalLink; 25 import org.oasis.ebxml.registry.bindings.rim.ExternalIdentifier; 26 import org.oasis.ebxml.registry.bindings.rim.ExtrinsicObject; 27 import org.oasis.ebxml.registry.bindings.rim.Service; 28 import org.oasis.ebxml.registry.bindings.rim.ServiceBinding; 29 import org.oasis.ebxml.registry.bindings.rim.SpecificationLink; 30 import org.oasis.ebxml.registry.bindings.rim.UserType; 31 32 import com.sun.xml.registry.ebxml.infomodel.*; 33 import javax.xml.registry.infomodel.*; 34 35 /*** 36 * Class Declaration for Class1 37 * 38 */ 39 public class BulkResponseImpl implements BulkResponse { 40 String requestId = null; 41 private int status; 42 private ArrayList collection = new ArrayList(); 43 private ArrayList registryExceptions; 44 45 /*** 46 * Construct an empty successful BulkResponse 47 */ 48 BulkResponseImpl() throws JAXRException { 49 status = STATUS_SUCCESS; 50 } 51 52 /*** 53 * Note: BulkResponseImpl is not an infomodel object even though this 54 * constructor looks like constructors in the infomodel subpackage. 55 * Therefore, the LifeCycleManagerImpl argument is not stored. 56 */ 57 public BulkResponseImpl(LifeCycleManagerImpl lcm, 58 RegistryResponse ebResponse, 59 HashMap responseAttachments) 60 throws JAXRException 61 { 62 requestId = lcm.createId(); 63 64 StatusType statusType = ebResponse.getStatus(); 65 if (statusType == StatusType.SUCCESS) { 66 status = STATUS_SUCCESS; 67 } else if (statusType == StatusType.UNAVAILABLE) { 68 status = STATUS_UNAVAILABLE; 69 } else { 70 status = STATUS_FAILURE; 71 } 72 73 RegistryResponseChoice rrc = ebResponse.getRegistryResponseChoice(); 74 if (rrc != null) { 75 AdhocQueryResponse aqr = rrc.getAdhocQueryResponse(); 76 if (aqr != null) { 77 SQLQueryResult sqlResult = aqr.getSQLQueryResult(); 78 if (sqlResult != null) { 79 processSqlQueryResult(sqlResult, lcm); 80 } else { 81 // assert(filterResult != null); 82 // B/c at this point Castor enforces this fact via 83 // validation 84 FilterQueryResult filterResult = aqr.getFilterQueryResult(); 85 processFilterQueryResult(filterResult, lcm); 86 } 87 } else { 88 GetContentResponse gcr = rrc.getGetContentResponse(); 89 processGetContentResponse(responseAttachments, lcm); 90 } 91 } 92 93 RegistryErrorList errList = ebResponse.getRegistryErrorList(); 94 if (errList != null) { 95 RegistryError[] errs = errList.getRegistryError(); 96 for (int i = 0; i < errs.length; i++) { 97 // XXX Need to add additional error info to exception somehow 98 addRegistryException(new FindException(errs[i].getContent())); 99 } 100 // XXX What to do about optional highestSeverity attr??? 101 // errList.getHighestSeverity(); 102 } 103 } 104 105 /*** 106 * Get the Collection of of objects returned as a response of a 107 * bulk operation. 108 * Caller thread will block here if result is not yet available. 109 * 110 * <p><DL><DT><B>Capability Level: 0 </B></DL> 111 * 112 */ 113 public Collection getCollection() throws JAXRException{ 114 return collection; 115 } 116 117 /*** 118 * Sets the Collection of objects returned for the response 119 * Package protected access meant to be called only by provider impl. 120 * 121 */ 122 void setCollection(Collection c) { 123 collection.clear(); 124 collection.addAll(c); 125 } 126 127 /*** 128 * Get the JAXRException(s) Collection in case of partial commit. 129 * Caller thread will block here if result is not yet available. 130 * Return null if result is available and there is no JAXRException(s). 131 * 132 * <p><DL><DT><B>Capability Level: 0 </B></DL> 133 * 134 */ 135 public Collection getExceptions() throws JAXRException { 136 return registryExceptions; 137 } 138 139 /*** 140 * Returns true if the reponse is a partial response due to large result set 141 * 142 * <p><DL><DT><B>Capability Level: 0 </B></DL> 143 * 144 */ 145 public boolean isPartialResponse() throws JAXRException{ 146 // Write your code here 147 return false; 148 } 149 150 /*** 151 * Returns the unique id for the request that generated this response. 152 * 153 * <p><DL><DT><B>Capability Level: 0 </B></DL> 154 * 155 */ 156 public String getRequestId() throws JAXRException{ 157 // Write your code here 158 return requestId; 159 } 160 161 /*** 162 * Returns the status for this response. 163 * 164 * <p><DL><DT><B>Capability Level: 0 </B></DL> 165 * 166 */ 167 public int getStatus() throws JAXRException { 168 return status; 169 } 170 171 void setStatus(int status) throws JAXRException { 172 this.status = status; 173 } 174 175 /*** 176 * Returns true if a response is available, false otherwise. 177 * This is a polling method and must not block. 178 * 179 * <p><DL><DT><B>Capability Level: 0 </B></DL> 180 * 181 */ 182 public boolean isAvailable() throws JAXRException{ 183 //?? stub 184 return true; 185 } 186 187 void addExceptions(Collection exes) { 188 if (registryExceptions == null) { 189 registryExceptions = new ArrayList(); 190 } 191 registryExceptions.addAll(exes); 192 } 193 194 private void addRegistryException(RegistryException rex) { 195 if (registryExceptions == null) { 196 registryExceptions = new ArrayList(); 197 } 198 registryExceptions.add(rex); 199 } 200 201 private void processSqlQueryResult(SQLQueryResult sqlResult, 202 LifeCycleManagerImpl lcm) 203 throws JAXRException 204 { 205 ObjectCache objCache = 206 ((RegistryServiceImpl)(lcm.getRegistryService())).getObjectCache(); 207 LeafRegistryObjectListTypeItem[] items 208 = sqlResult.getLeafRegistryObjectListTypeItem(); 209 for (int i = 0; i < items.length; i++) { 210 ClassificationSchemeType ebScheme 211 = items[i].getClassificationScheme(); 212 if (ebScheme != null) { 213 ClassificationSchemeImpl scheme 214 = new ClassificationSchemeImpl(lcm, ebScheme); 215 objCache.putRegistryObject(scheme); 216 collection.add(scheme); 217 continue; 218 } 219 220 ClassificationType ebClass = items[i].getClassification(); 221 if (ebClass != null) { 222 ClassificationImpl cls = null; 223 cls = new ClassificationImpl(lcm,ebClass,null); 224 objCache.putRegistryObject(cls); 225 collection.add(cls); 226 continue; 227 } 228 229 OrganizationType ebOrg = items[i].getOrganization(); 230 if (ebOrg != null) { 231 OrganizationImpl org = new OrganizationImpl(lcm, ebOrg); 232 objCache.putRegistryObject(org); 233 collection.add(org); 234 continue; 235 } 236 237 AssociationType1 ebAss = items[i].getAssociation(); 238 if (ebAss != null) { 239 AssociationImpl ass = new AssociationImpl(lcm, ebAss); 240 objCache.putRegistryObject(ass); 241 collection.add(ass); 242 continue; 243 } 244 245 RegistryPackage ebPkg = items[i].getRegistryPackage(); 246 if (ebPkg != null) { 247 RegistryPackageImpl pkg = new RegistryPackageImpl(lcm, ebPkg); 248 objCache.putRegistryObject(pkg); 249 collection.add(pkg); 250 continue; 251 } 252 253 ExternalLink ebExtLink = items[i].getExternalLink(); 254 if (ebExtLink != null) { 255 ExternalLinkImpl extLink = new ExternalLinkImpl(lcm, ebExtLink); 256 objCache.putRegistryObject(extLink); 257 collection.add(extLink); 258 continue; 259 } 260 261 ExternalIdentifier ebExtIdentifier 262 = items[i].getExternalIdentifier(); 263 if (ebExtIdentifier != null) { 264 //??Need to pass parent object and not null 265 ExternalIdentifierImpl extIdentifier 266 = new ExternalIdentifierImpl(lcm, ebExtIdentifier, null); 267 objCache.putRegistryObject(extIdentifier); 268 collection.add(extIdentifier); 269 continue; 270 } 271 272 ExtrinsicObject ebExtrinsicObj = items[i].getExtrinsicObject(); 273 if (ebExtrinsicObj != null) { 274 ExtrinsicObjectImpl extrinsicObj 275 = new ExtrinsicObjectImpl(lcm, ebExtrinsicObj); 276 objCache.putRegistryObject(extrinsicObj); 277 collection.add(extrinsicObj); 278 continue; 279 } 280 281 Service ebService = items[i].getService(); 282 if (ebService != null) { 283 ServiceImpl service 284 = new ServiceImpl(lcm, ebService); 285 objCache.putRegistryObject(service); 286 collection.add(service); 287 continue; 288 } 289 290 ServiceBinding ebBinding = items[i].getServiceBinding(); 291 if (ebBinding != null) { 292 ServiceBindingImpl binding 293 = new ServiceBindingImpl(lcm, ebBinding); 294 objCache.putRegistryObject(binding); 295 collection.add(binding); 296 continue; 297 } 298 299 SpecificationLink ebSpecLink = items[i].getSpecificationLink(); 300 if (ebSpecLink != null) { 301 SpecificationLinkImpl specLink 302 = new SpecificationLinkImpl(lcm, ebSpecLink); 303 objCache.putRegistryObject(specLink); 304 collection.add(specLink); 305 continue; 306 } 307 308 ClassificationNodeType ebCNode = items[i].getClassificationNode(); 309 if (ebCNode != null) { 310 ConceptImpl concept = new ConceptImpl(lcm, ebCNode); 311 objCache.putRegistryObject(concept); 312 collection.add(concept); 313 continue; 314 } 315 316 if (items[i].getObjectRef() != null) { 317 // ObjectRef-s are processed by leaf components 318 continue; 319 } 320 321 AuditableEventType ebAE = items[i].getAuditableEvent(); 322 if (ebAE != null) { 323 AuditableEventImpl ae = new AuditableEventImpl(lcm, ebAE); 324 objCache.putRegistryObject(ae); 325 collection.add(ae); 326 continue; 327 } 328 329 UserType ebUser = items[i].getUser(); 330 if (ebUser != null) { 331 UserImpl user = new UserImpl(lcm, ebUser); 332 objCache.putRegistryObject(user); 333 collection.add(user); 334 continue; 335 } 336 337 System.err.println("Not implemented " + sqlResult); 338 //throw new JAXRException("Not Yet Implemented"); 339 } 340 } 341 342 private void processFilterQueryResult(FilterQueryResult filterResult, 343 LifeCycleManagerImpl lcm) 344 throws JAXRException 345 { 346 throw new JAXRException("Only SQLQueryResult is implemented"); 347 348 } 349 350 private void processGetContentResponse(HashMap attachments, 351 LifeCycleManagerImpl lcm) 352 throws JAXRException 353 { 354 if (attachments == null) { 355 // Possible if request contains no ObjectRef-s, but not typical 356 return; 357 } 358 359 ObjectCache objCache = 360 ((RegistryServiceImpl)(lcm.getRegistryService())).getObjectCache(); 361 362 for (Iterator it = attachments.entrySet().iterator(); it.hasNext(); ) { 363 Map.Entry entry = (Map.Entry)it.next(); 364 String contentId = (String)entry.getKey(); 365 ExtrinsicObjectImpl extrinsicObj = (ExtrinsicObjectImpl) 366 objCache.getReference(contentId, "ExtrinsicObject").get(); 367 DataHandler dh = (DataHandler)entry.getValue(); 368 extrinsicObj.setRepositoryItem(dh); 369 collection.add(extrinsicObj); 370 } 371 } 372 373 RegistryObject getRegistryObject() throws JAXRException { 374 RegistryObject ro = null; 375 376 // check for errors 377 Collection exceptions = getExceptions(); 378 379 if (exceptions != null) { 380 Iterator iter = exceptions.iterator(); 381 Exception exception = null; 382 383 while (iter.hasNext()) { 384 exception = (Exception) iter.next(); 385 throw new JAXRException(exception); 386 } 387 } 388 389 Collection results = getCollection(); 390 Iterator iter = results.iterator(); 391 if (iter.hasNext()) { 392 ro = (RegistryObject)iter.next(); 393 } 394 395 return ro; 396 } 397 }

This page was automatically generated by Maven