This project has retired. For details please refer to its
Attic page.
BusinessQueryManagerImpl xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.ws.scout.registry;
18
19 import java.net.PasswordAuthentication;
20 import java.util.ArrayList;
21 import java.util.Collection;
22 import java.util.Iterator;
23 import java.util.LinkedHashSet;
24 import java.util.List;
25 import java.util.Set;
26
27 import javax.xml.registry.BulkResponse;
28 import javax.xml.registry.BusinessLifeCycleManager;
29 import javax.xml.registry.BusinessQueryManager;
30 import javax.xml.registry.InvalidRequestException;
31 import javax.xml.registry.JAXRException;
32 import javax.xml.registry.LifeCycleManager;
33 import javax.xml.registry.RegistryService;
34 import javax.xml.registry.UnsupportedCapabilityException;
35 import javax.xml.registry.infomodel.Association;
36 import javax.xml.registry.infomodel.ClassificationScheme;
37 import javax.xml.registry.infomodel.Concept;
38 import javax.xml.registry.infomodel.Key;
39 import javax.xml.registry.infomodel.LocalizedString;
40 import javax.xml.registry.infomodel.Organization;
41 import javax.xml.registry.infomodel.RegistryObject;
42 import javax.xml.registry.infomodel.Service;
43 import javax.xml.registry.infomodel.ServiceBinding;
44
45 import org.apache.commons.logging.Log;
46 import org.apache.commons.logging.LogFactory;
47 import org.apache.ws.scout.model.uddi.v2.AssertionStatusItem;
48 import org.apache.ws.scout.model.uddi.v2.AssertionStatusReport;
49 import org.apache.ws.scout.model.uddi.v2.AuthToken;
50 import org.apache.ws.scout.model.uddi.v2.BindingDetail;
51 import org.apache.ws.scout.model.uddi.v2.BindingTemplate;
52 import org.apache.ws.scout.model.uddi.v2.BusinessDetail;
53 import org.apache.ws.scout.model.uddi.v2.BusinessInfo;
54 import org.apache.ws.scout.model.uddi.v2.BusinessInfos;
55 import org.apache.ws.scout.model.uddi.v2.BusinessList;
56 import org.apache.ws.scout.model.uddi.v2.BusinessService;
57 import org.apache.ws.scout.model.uddi.v2.FindQualifiers;
58 import org.apache.ws.scout.model.uddi.v2.KeyedReference;
59 import org.apache.ws.scout.model.uddi.v2.Name;
60 import org.apache.ws.scout.model.uddi.v2.ObjectFactory;
61 import org.apache.ws.scout.model.uddi.v2.PublisherAssertion;
62 import org.apache.ws.scout.model.uddi.v2.PublisherAssertions;
63 import org.apache.ws.scout.model.uddi.v2.RegisteredInfo;
64 import org.apache.ws.scout.model.uddi.v2.ServiceDetail;
65 import org.apache.ws.scout.model.uddi.v2.ServiceInfo;
66 import org.apache.ws.scout.model.uddi.v2.ServiceInfos;
67 import org.apache.ws.scout.model.uddi.v2.ServiceList;
68 import org.apache.ws.scout.model.uddi.v2.TModel;
69 import org.apache.ws.scout.model.uddi.v2.TModelDetail;
70 import org.apache.ws.scout.model.uddi.v2.TModelInfo;
71 import org.apache.ws.scout.model.uddi.v2.TModelInfos;
72 import org.apache.ws.scout.model.uddi.v2.TModelList;
73 import org.apache.ws.scout.registry.infomodel.AssociationImpl;
74 import org.apache.ws.scout.registry.infomodel.ClassificationSchemeImpl;
75 import org.apache.ws.scout.registry.infomodel.ConceptImpl;
76 import org.apache.ws.scout.registry.infomodel.InternationalStringImpl;
77 import org.apache.ws.scout.registry.infomodel.KeyImpl;
78 import org.apache.ws.scout.registry.infomodel.ServiceBindingImpl;
79 import org.apache.ws.scout.registry.infomodel.ServiceImpl;
80 import org.apache.ws.scout.util.EnumerationHelper;
81 import org.apache.ws.scout.util.ScoutJaxrUddiHelper;
82 import org.apache.ws.scout.util.ScoutUddiJaxrHelper;
83
84
85
86
87
88
89
90
91
92
93 public class BusinessQueryManagerImpl implements BusinessQueryManager
94 {
95 private final RegistryServiceImpl registryService;
96 private Log log = LogFactory.getLog(this.getClass());
97
98 private static ObjectFactorytFactory.html#ObjectFactory">ObjectFactory objectFactory = new ObjectFactory();
99
100 public BusinessQueryManagerImpl(RegistryServiceImpl registry)
101 {
102 this.registryService = registry;
103 }
104
105 public RegistryService getRegistryService()
106 {
107 return registryService;
108 }
109
110
111
112
113
114
115
116
117
118
119
120
121
122 public BulkResponse findOrganizations(Collection findQualifiers,
123 Collection namePatterns,
124 Collection classifications,
125 Collection specifications,
126 Collection externalIdentifiers,
127 Collection externalLinks) throws JAXRException
128 {
129 IRegistry/../../../org/apache/ws/scout/registry/IRegistry.html#IRegistry">IRegistry registry = (IRegistry) registryService.getRegistry();
130 try
131 {
132 FindQualifiers juddiFindQualifiers = mapFindQualifiers(findQualifiers);
133 Name[] nameArray = mapNamePatterns(namePatterns);
134 BusinessList result = registry.findBusiness(nameArray,
135 null,
136 ScoutJaxrUddiHelper.getIdentifierBagFromExternalIdentifiers(externalIdentifiers),
137 ScoutJaxrUddiHelper.getCategoryBagFromClassifications(classifications),
138 null,
139 juddiFindQualifiers,
140 registryService.getMaxRows());
141
142 BusinessInfo[] bizInfoArr =null;
143 BusinessInfos bizInfos = result.getBusinessInfos();
144 LinkedHashSet<Organization> orgs = new LinkedHashSet<Organization>();
145 if(bizInfos != null)
146 {
147 List<BusinessInfo> bizInfoList = bizInfos.getBusinessInfo();
148 for (BusinessInfo businessInfo : bizInfoList) {
149
150 BusinessDetail detail = registry.getBusinessDetail(businessInfo.getBusinessKey());
151 orgs.add(((BusinessLifeCycleManagerImpl)registryService.getLifeCycleManagerImpl()).createOrganization(detail));
152 }
153 bizInfoArr = new BusinessInfo[bizInfoList.size()];
154 bizInfoList.toArray(bizInfoArr);
155 }
156 return new BulkResponseImpl(orgs);
157 } catch (RegistryException e)
158 {
159 throw new JAXRException(e);
160 }
161 }
162
163 public BulkResponse findAssociations(Collection findQualifiers,
164 String sourceObjectId,
165 String targetObjectId,
166 Collection associationTypes) throws JAXRException
167 {
168
169 IRegistry/../../../org/apache/ws/scout/registry/IRegistry.html#IRegistry">IRegistry registry = (IRegistry) registryService.getRegistry();
170 try
171 {
172 ConnectionImpl con = ((RegistryServiceImpl)getRegistryService()).getConnection();
173 AuthToken auth = this.getAuthToken(con,registry);
174 PublisherAssertions result = null;
175 try {
176 result = registry.getPublisherAssertions(auth.getAuthInfo());
177 } catch (RegistryException rve) {
178 String username = getUsernameFromCredentials(con.getCredentials());
179 if (AuthTokenSingleton.getToken(username) != null) {
180 AuthTokenSingleton.deleteAuthToken(username);
181 }
182 auth = getAuthToken(con, registry);
183 result = registry.getPublisherAssertions(auth.getAuthInfo());
184 }
185
186 List<PublisherAssertion> publisherAssertionList = result.getPublisherAssertion();
187 LinkedHashSet<Association> col = new LinkedHashSet<Association>();
188 for (PublisherAssertion pas : publisherAssertionList) {
189 String sourceKey = pas.getFromKey();
190 String targetKey = pas.getToKey();
191
192 if ((sourceObjectId==null || sourceObjectId.equals(sourceKey))
193 && (targetObjectId==null || targetObjectId.equals(targetKey))) {
194 Collection<Key> orgcol = new ArrayList<Key>();
195 orgcol.add(new KeyImpl(sourceKey));
196 orgcol.add(new KeyImpl(targetKey));
197 BulkResponse bl = getRegistryObjects(orgcol, LifeCycleManager.ORGANIZATION);
198 Association asso = ScoutUddiJaxrHelper.getAssociation(bl.getCollection(),
199 registryService.getBusinessLifeCycleManager());
200 KeyedReference keyr = pas.getKeyedReference();
201 Concept c = new ConceptImpl(getRegistryService().getBusinessLifeCycleManager());
202 c.setName(new InternationalStringImpl(keyr.getKeyName()));
203 c.setKey( new KeyImpl(keyr.getTModelKey()) );
204 c.setValue(keyr.getKeyValue());
205 asso.setAssociationType(c);
206 col.add(asso);
207 }
208
209 }
210 return new BulkResponseImpl(col);
211 } catch (RegistryException e)
212 {
213 throw new JAXRException(e);
214 }
215 }
216
217 public BulkResponse findCallerAssociations(Collection findQualifiers,
218 Boolean confirmedByCaller,
219 Boolean confirmedByOtherParty,
220 Collection associationTypes) throws JAXRException
221 {
222
223 IRegistry/../../../org/apache/ws/scout/registry/IRegistry.html#IRegistry">IRegistry registry = (IRegistry) registryService.getRegistry();
224 try
225 {
226 ConnectionImpl con = ((RegistryServiceImpl)getRegistryService()).getConnection();
227 AuthToken auth = this.getAuthToken(con,registry);
228
229 AssertionStatusReport report = null;
230 String confirm = "";
231 boolean caller = confirmedByCaller.booleanValue();
232 boolean other = confirmedByOtherParty.booleanValue();
233
234 if(caller && other )
235 confirm = Constants.COMPLETION_STATUS_COMPLETE;
236 else
237 if(!caller && other )
238 confirm = Constants.COMPLETION_STATUS_FROMKEY_INCOMPLETE;
239 else
240 if(caller && !other )
241 confirm = Constants.COMPLETION_STATUS_TOKEY_INCOMPLETE;
242
243 report = null;
244 try {
245 report = registry.getAssertionStatusReport(auth.getAuthInfo(),confirm);
246 } catch (RegistryException rve) {
247 String username = getUsernameFromCredentials(con.getCredentials());
248 if (AuthTokenSingleton.getToken(username) != null) {
249 AuthTokenSingleton.deleteAuthToken(username);
250 }
251 auth = getAuthToken(con, registry);
252 report = registry.getAssertionStatusReport(auth.getAuthInfo(),confirm);
253 }
254
255 List<AssertionStatusItem> assertionStatusItemList = report.getAssertionStatusItem();
256 LinkedHashSet<Association> col = new LinkedHashSet<Association>();
257 for (AssertionStatusItem asi : assertionStatusItemList) {
258 String sourceKey = asi.getFromKey();
259 String targetKey = asi.getToKey();
260 Collection<Key> orgcol = new ArrayList<Key>();
261 orgcol.add(new KeyImpl(sourceKey));
262 orgcol.add(new KeyImpl(targetKey));
263 BulkResponse bl = getRegistryObjects(orgcol, LifeCycleManager.ORGANIZATION);
264 Association asso = ScoutUddiJaxrHelper.getAssociation(bl.getCollection(),
265 registryService.getBusinessLifeCycleManager());
266
267 ((AssociationImpl)asso).setConfirmedBySourceOwner(caller);
268 ((AssociationImpl)asso).setConfirmedByTargetOwner(other);
269
270 if(confirm != Constants.COMPLETION_STATUS_COMPLETE)
271 ((AssociationImpl)asso).setConfirmed(false);
272
273 Concept c = new ConceptImpl(getRegistryService().getBusinessLifeCycleManager());
274 KeyedReference keyr = asi.getKeyedReference();
275 c.setKey(new KeyImpl(keyr.getTModelKey()));
276 c.setName(new InternationalStringImpl(keyr.getKeyName()));
277 c.setValue(keyr.getKeyValue());
278 asso.setKey(new KeyImpl(keyr.getTModelKey()));
279 asso.setAssociationType(c);
280 col.add(asso);
281 }
282
283
284 return new BulkResponseImpl(col);
285 } catch (RegistryException e)
286 {
287 throw new JAXRException(e);
288 }
289 }
290
291
292
293
294
295
296
297
298
299 public ClassificationScheme findClassificationSchemeByName(Collection findQualifiers,
300 String namePatterns) throws JAXRException
301 {
302 ClassificationScheme scheme = null;
303
304 if (namePatterns.indexOf("uddi-org:types") != -1) {
305
306 scheme = new ClassificationSchemeImpl(registryService.getLifeCycleManagerImpl());
307 scheme.setName(new InternationalStringImpl(namePatterns));
308 scheme.setKey(new KeyImpl(Constants.TMODEL_TYPES_TMODEL_KEY));
309 }
310 else if (namePatterns.indexOf("dnb-com:D-U-N-S") != -1) {
311
312 scheme = new ClassificationSchemeImpl(registryService.getLifeCycleManagerImpl());
313 scheme.setName(new InternationalStringImpl(namePatterns));
314 scheme.setKey(new KeyImpl(Constants.TMODEL_D_U_N_S_TMODEL_KEY));
315 }
316 else if (namePatterns.indexOf("uddi-org:iso-ch:3166:1999") != -1)
317 {
318 scheme = new ClassificationSchemeImpl(registryService.getLifeCycleManagerImpl());
319 scheme.setName(new InternationalStringImpl(namePatterns));
320 scheme.setKey(new KeyImpl(Constants.TMODEL_ISO_CH_TMODEL_KEY));
321 }
322 else if (namePatterns.indexOf("uddi-org:iso-ch:3166-1999") != -1)
323 {
324 scheme = new ClassificationSchemeImpl(registryService.getLifeCycleManagerImpl());
325 scheme.setName(new InternationalStringImpl(namePatterns));
326 scheme.setKey(new KeyImpl(Constants.TMODEL_ISO_CH_TMODEL_KEY));
327 }
328 else if (namePatterns.indexOf("iso-ch:3166:1999") != -1)
329 {
330 scheme = new ClassificationSchemeImpl(registryService.getLifeCycleManagerImpl());
331 scheme.setName(new InternationalStringImpl(namePatterns));
332 scheme.setKey(new KeyImpl(Constants.TMODEL_ISO_CH_TMODEL_KEY));
333 }
334 else if (namePatterns.indexOf("iso-ch:3166-1999") != -1)
335 {
336 scheme = new ClassificationSchemeImpl(registryService.getLifeCycleManagerImpl());
337 scheme.setName(new InternationalStringImpl(namePatterns));
338 scheme.setKey(new KeyImpl(Constants.TMODEL_ISO_CH_TMODEL_KEY));
339 }
340 else if (namePatterns.indexOf("unspsc-org:unspsc") != -1) {
341
342 scheme = new ClassificationSchemeImpl(registryService.getLifeCycleManagerImpl());
343 scheme.setName(new InternationalStringImpl(namePatterns));
344 scheme.setKey(new KeyImpl(Constants.TMODEL_UNSPSC_TMODEL_KEY));
345 }
346 else if (namePatterns.indexOf("ntis-gov:naics") != -1) {
347
348 scheme = new ClassificationSchemeImpl(registryService.getLifeCycleManagerImpl());
349 scheme.setName(new InternationalStringImpl(namePatterns));
350 scheme.setKey(new KeyImpl(Constants.TMODEL_NAICS_TMODEL_KEY));
351 }
352 else
353 {
354
355
356
357
358
359 if ("AssociationType".equals(namePatterns)) {
360 scheme = new ClassificationSchemeImpl(registryService.getLifeCycleManagerImpl());
361
362 scheme.setName(new InternationalStringImpl(namePatterns));
363
364 scheme.setKey(new KeyImpl(Constants.TMODEL_UNSPSC_TMODEL_KEY));
365
366 addChildConcept((ClassificationSchemeImpl)scheme, "RelatedTo");
367 addChildConcept((ClassificationSchemeImpl)scheme, "HasChild");
368 addChildConcept((ClassificationSchemeImpl)scheme, "HasMember");
369 addChildConcept((ClassificationSchemeImpl)scheme, "HasParent");
370 addChildConcept((ClassificationSchemeImpl)scheme, "ExternallyLinks");
371 addChildConcept((ClassificationSchemeImpl)scheme, "Contains");
372 addChildConcept((ClassificationSchemeImpl)scheme, "EquivalentTo");
373 addChildConcept((ClassificationSchemeImpl)scheme, "Extends");
374 addChildConcept((ClassificationSchemeImpl)scheme, "Implements");
375 addChildConcept((ClassificationSchemeImpl)scheme, "InstanceOf");
376 addChildConcept((ClassificationSchemeImpl)scheme, "Supersedes");
377 addChildConcept((ClassificationSchemeImpl)scheme, "Uses");
378 addChildConcept((ClassificationSchemeImpl)scheme, "Replaces");
379 addChildConcept((ClassificationSchemeImpl)scheme, "ResponsibleFor");
380 addChildConcept((ClassificationSchemeImpl)scheme, "SubmitterOf");
381 }
382 else if ("ObjectType".equals(namePatterns)) {
383 scheme = new ClassificationSchemeImpl(registryService.getLifeCycleManagerImpl());
384
385 scheme.setName(new InternationalStringImpl(namePatterns));
386
387 scheme.setKey(new KeyImpl(Constants.TMODEL_UNSPSC_TMODEL_KEY));
388
389 addChildConcept((ClassificationSchemeImpl)scheme, "CPP");
390 addChildConcept((ClassificationSchemeImpl)scheme, "CPA");
391 addChildConcept((ClassificationSchemeImpl)scheme, "Process");
392 addChildConcept((ClassificationSchemeImpl)scheme, "WSDL");
393 addChildConcept((ClassificationSchemeImpl)scheme, "Association");
394 addChildConcept((ClassificationSchemeImpl)scheme, "AuditableEvent");
395 addChildConcept((ClassificationSchemeImpl)scheme, "Classification");
396 addChildConcept((ClassificationSchemeImpl)scheme, "Concept");
397 addChildConcept((ClassificationSchemeImpl)scheme, "ExternalIdentifier");
398 addChildConcept((ClassificationSchemeImpl)scheme, "ExternalLink");
399 addChildConcept((ClassificationSchemeImpl)scheme, "ExtrinsicObject");
400 addChildConcept((ClassificationSchemeImpl)scheme, "Organization");
401 addChildConcept((ClassificationSchemeImpl)scheme, "Package");
402 addChildConcept((ClassificationSchemeImpl)scheme, "Service");
403 addChildConcept((ClassificationSchemeImpl)scheme, "ServiceBinding");
404 addChildConcept((ClassificationSchemeImpl)scheme, "User");
405 }
406 else if ("PhoneType".equals(namePatterns)) {
407 scheme = new ClassificationSchemeImpl(registryService.getLifeCycleManagerImpl());
408
409 scheme.setName(new InternationalStringImpl(namePatterns));
410
411 scheme.setKey(new KeyImpl(Constants.TMODEL_UNSPSC_TMODEL_KEY));
412
413 addChildConcept((ClassificationSchemeImpl)scheme, "OfficePhone");
414 addChildConcept((ClassificationSchemeImpl)scheme, "HomePhone");
415 addChildConcept((ClassificationSchemeImpl)scheme, "MobilePhone");
416 addChildConcept((ClassificationSchemeImpl)scheme, "Beeper");
417 addChildConcept((ClassificationSchemeImpl)scheme, "FAX");
418 }
419 else if ("URLType".equals(namePatterns)) {
420 scheme = new ClassificationSchemeImpl(registryService.getLifeCycleManagerImpl());
421
422 scheme.setName(new InternationalStringImpl(namePatterns));
423
424 scheme.setKey(new KeyImpl(Constants.TMODEL_UNSPSC_TMODEL_KEY));
425
426 addChildConcept((ClassificationSchemeImpl)scheme, "HTTP");
427 addChildConcept((ClassificationSchemeImpl)scheme, "HTTPS");
428 addChildConcept((ClassificationSchemeImpl)scheme, "SMTP");
429 addChildConcept((ClassificationSchemeImpl)scheme, "PHONE");
430 addChildConcept((ClassificationSchemeImpl)scheme, "FAX");
431 addChildConcept((ClassificationSchemeImpl)scheme, "OTHER");
432 }
433 else if ("PostalAddressAttributes".equals(namePatterns)) {
434 scheme = new ClassificationSchemeImpl(registryService.getLifeCycleManagerImpl());
435
436 scheme.setName(new InternationalStringImpl(namePatterns));
437
438 scheme.setKey(new KeyImpl(Constants.TMODEL_UNSPSC_TMODEL_KEY));
439
440 addChildConcept((ClassificationSchemeImpl)scheme, "StreetNumber");
441 addChildConcept((ClassificationSchemeImpl)scheme, "Street");
442 addChildConcept((ClassificationSchemeImpl)scheme, "City");
443 addChildConcept((ClassificationSchemeImpl)scheme, "State");
444 addChildConcept((ClassificationSchemeImpl)scheme, "PostalCode");
445 addChildConcept((ClassificationSchemeImpl)scheme, "Country");
446 }
447 else {
448
449
450 IRegistry/../../../org/apache/ws/scout/registry/IRegistry.html#IRegistry">IRegistry registry = (IRegistry) registryService.getRegistry();
451 FindQualifiers juddiFindQualifiers = mapFindQualifiers(findQualifiers);
452 try
453 {
454
455 TModelList list = registry.findTModel(namePatterns, null, null, juddiFindQualifiers, 3);
456 if (list != null) {
457 TModelInfos infos = list.getTModelInfos();
458 if (infos != null) {
459 List<TModelInfo> tmodelInfoList = infos.getTModelInfo();
460 if (tmodelInfoList.size() > 1) {
461 throw new InvalidRequestException("Multiple matches found:" + tmodelInfoList.size());
462 }
463 if (tmodelInfoList.size() ==1) {
464 TModelInfo info = tmodelInfoList.get(0);
465 scheme = new ClassificationSchemeImpl(registryService.getLifeCycleManagerImpl());
466 scheme.setName(new InternationalStringImpl(info.getName().getValue()));
467 scheme.setKey(new KeyImpl(info.getTModelKey()));
468 }
469 }
470 }
471
472 } catch (RegistryException e)
473 {
474 throw new JAXRException(e.getLocalizedMessage());
475 }
476 }
477 }
478 return scheme;
479 }
480
481
482
483
484
485
486
487
488 private void addChildConcept(ClassificationSchemeImpl scheme, String name)
489 throws JAXRException {
490 Concept c = new ConceptImpl(registryService.getLifeCycleManagerImpl());
491
492 c.setName(new InternationalStringImpl(name));
493 c.setValue(name);
494 ((ConceptImpl)c).setScheme((ClassificationSchemeImpl)scheme);
495
496 scheme.addChildConcept(c);
497 }
498
499 public BulkResponse findClassificationSchemes(Collection findQualifiers,
500 Collection namePatterns,
501 Collection classifications,
502 Collection externalLinks) throws JAXRException
503 {
504
505 LinkedHashSet<ClassificationScheme> col = new LinkedHashSet<ClassificationScheme>();
506 Iterator iter = namePatterns.iterator();
507 String name = "";
508 while(iter.hasNext())
509 {
510 name = (String)iter.next();
511 break;
512 }
513
514 ClassificationScheme classificationScheme = findClassificationSchemeByName(findQualifiers,name);
515 if (classificationScheme!=null) {
516 col.add(classificationScheme);
517 }
518 return new BulkResponseImpl(col);
519 }
520
521 public Concept findConceptByPath(String path) throws JAXRException
522 {
523
524
525
526
527
528 return EnumerationHelper.getConceptByPath(path);
529 }
530
531 public BulkResponse findConcepts(Collection findQualifiers,
532 Collection namePatterns,
533 Collection classifications,
534 Collection externalIdentifiers,
535 Collection externalLinks) throws JAXRException
536 {
537 LinkedHashSet<Concept> col = new LinkedHashSet<Concept>();
538
539
540 IRegistry/../../../org/apache/ws/scout/registry/IRegistry.html#IRegistry">IRegistry registry = (IRegistry) registryService.getRegistry();
541 FindQualifiers juddiFindQualifiers = mapFindQualifiers(findQualifiers);
542 Iterator iter = null;
543 if (namePatterns != null) iter = namePatterns.iterator();
544 while (iter.hasNext())
545 {
546 String namestr = (String) iter.next();
547 try
548 {
549 TModelList list = registry.findTModel(namestr,
550 ScoutJaxrUddiHelper.getCategoryBagFromClassifications(classifications),
551 ScoutJaxrUddiHelper.getIdentifierBagFromExternalIdentifiers(externalIdentifiers),
552 juddiFindQualifiers, 10);
553
554 if (list != null && list.getTModelInfos()!=null) {
555 List<TModelInfo> tmodelInfoList = list.getTModelInfos().getTModelInfo();
556 if (tmodelInfoList!=null) {
557 for (TModelInfo info: tmodelInfoList) {
558 col.add(ScoutUddiJaxrHelper.getConcept(info, this.registryService.getBusinessLifeCycleManager()));
559 }
560 }
561 }
562 } catch (RegistryException e) {
563 throw new JAXRException(e.getLocalizedMessage());
564 }
565 }
566
567 return new BulkResponseImpl(col);
568 }
569
570 public BulkResponse findRegistryPackages(Collection findQualifiers,
571 Collection namePatterns,
572 Collection classifications,
573 Collection externalLinks) throws JAXRException
574 {
575 throw new UnsupportedCapabilityException();
576 }
577
578 public BulkResponse findServiceBindings(Key serviceKey,
579 Collection findQualifiers,
580 Collection classifications,
581 Collection specifications) throws JAXRException
582 {
583 BulkResponseImplsponseImpl.html#BulkResponseImpl">BulkResponseImpl blkRes = new BulkResponseImpl();
584
585 IRegistry../../../org/apache/ws/scout/registry/IRegistry.html#IRegistry">IRegistry iRegistry = (IRegistry) registryService.getRegistry();
586 FindQualifiers juddiFindQualifiers = mapFindQualifiers(findQualifiers);
587
588 try
589 {
590
591 BindingDetail bindingDetail = iRegistry.findBinding(serviceKey.getId(),
592 ScoutJaxrUddiHelper.getCategoryBagFromClassifications(classifications),
593 ScoutJaxrUddiHelper.getTModelBagFromSpecifications(specifications),
594 juddiFindQualifiers,registryService.getMaxRows());
595
596
597
598
599 if (bindingDetail != null) {
600
601 List<BindingTemplate> bindingTemplateList = bindingDetail.getBindingTemplate();
602 BindingTemplate[] bindarr = new BindingTemplate[bindingTemplateList.size()];
603 bindingTemplateList.toArray(bindarr);
604
605 LinkedHashSet<ServiceBinding> col = new LinkedHashSet<ServiceBinding>();
606
607 for (int i=0; bindarr != null && i < bindarr.length; i++) {
608 BindingTemplate si = bindarr[i];
609 ServiceBinding sb = ScoutUddiJaxrHelper.getServiceBinding(si,
610 registryService.getBusinessLifeCycleManager());
611 col.add(sb);
612
613 Service s = (Service)getRegistryObject(serviceKey.getId(), LifeCycleManager.SERVICE);
614 ((ServiceBindingImpl)sb).setService(s);
615 }
616
617 blkRes.setCollection(col);
618 }
619 }
620 catch (RegistryException e) {
621 throw new JAXRException(e.getLocalizedMessage());
622 }
623
624 return blkRes;
625 }
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643 public BulkResponse findServices(Key orgKey, Collection findQualifiers,
644 Collection namePatterns,
645 Collection classifications,
646 Collection specificationa) throws JAXRException
647 {
648 BulkResponseImplsponseImpl.html#BulkResponseImpl">BulkResponseImpl blkRes = new BulkResponseImpl();
649
650 IRegistry../../../org/apache/ws/scout/registry/IRegistry.html#IRegistry">IRegistry iRegistry = (IRegistry) registryService.getRegistry();
651 FindQualifiers juddiFindQualifiers = mapFindQualifiers(findQualifiers);
652 Name[] juddiNames = mapNamePatterns(namePatterns);
653
654 try
655 {
656
657
658
659
660 String id = null;
661
662 if (orgKey != null) {
663 id = orgKey.getId();
664 }
665
666 ServiceList serviceList = iRegistry.findService(id,
667 juddiNames,
668 ScoutJaxrUddiHelper.getCategoryBagFromClassifications(classifications),
669 null,
670 juddiFindQualifiers, registryService.getMaxRows());
671
672
673
674
675 if (serviceList != null) {
676
677 ServiceInfos serviceInfos = serviceList.getServiceInfos();
678 LinkedHashSet<Service> col = new LinkedHashSet<Service>();
679
680 if(serviceInfos != null && serviceInfos.getServiceInfo()!=null) {
681 for (ServiceInfo si : serviceInfos.getServiceInfo()) {
682 Service srv = (Service) getRegistryObject(si.getServiceKey(), LifeCycleManager.SERVICE);
683 col.add(srv);
684 }
685
686 }
687 blkRes.setCollection(col);
688 }
689 }
690 catch (RegistryException e) {
691 throw new JAXRException(e.getLocalizedMessage());
692 }
693
694 return blkRes;
695 }
696
697 public RegistryObject getRegistryObject(String id) throws JAXRException
698 {
699 throw new UnsupportedCapabilityException();
700 }
701
702 public RegistryObject getRegistryObject(String id, String objectType) throws JAXRException
703 {
704 IRegistry/../../../org/apache/ws/scout/registry/IRegistry.html#IRegistry">IRegistry registry = (IRegistry) registryService.getRegistry();
705 BusinessLifeCycleManager lcm = registryService.getBusinessLifeCycleManager();
706
707 if (LifeCycleManager.CLASSIFICATION_SCHEME.equalsIgnoreCase(objectType)) {
708
709 try {
710
711 TModelDetail tmodeldetail = registry.getTModelDetail(id);
712 Concept c = ScoutUddiJaxrHelper.getConcept(tmodeldetail, lcm);
713
714
715
716
717
718 ClassificationScheme scheme = new ClassificationSchemeImpl(lcm);
719
720 scheme.setName(c.getName());
721 scheme.setDescription(c.getDescription());
722 scheme.setKey(c.getKey());
723
724 return scheme;
725 }
726 catch (RegistryException e) {
727 throw new JAXRException(e.getLocalizedMessage());
728 }
729 }
730 else if (LifeCycleManager.ORGANIZATION.equalsIgnoreCase(objectType)) {
731 try
732 {
733 BusinessDetail orgdetail = registry.getBusinessDetail(id);
734 return ScoutUddiJaxrHelper.getOrganization(orgdetail, lcm);
735 }
736 catch (RegistryException e) {
737 throw new JAXRException(e.getLocalizedMessage());
738 }
739
740 }
741 else if (LifeCycleManager.CONCEPT.equalsIgnoreCase(objectType)) {
742
743 try
744 {
745 TModelDetail tmodeldetail = registry.getTModelDetail(id);
746 return ScoutUddiJaxrHelper.getConcept(tmodeldetail, lcm);
747 }
748 catch (RegistryException e) {
749 throw new JAXRException(e.getLocalizedMessage());
750 }
751 }
752 else if (LifeCycleManager.SERVICE.equalsIgnoreCase(objectType)) {
753
754 try {
755 ServiceDetail sd = registry.getServiceDetail(id);
756 if (sd != null && sd.getBusinessService()!=null) {
757 for (BusinessService businessService : sd.getBusinessService()) {
758 Service service = getServiceFromBusinessService(businessService, lcm);
759 return service;
760 }
761 }
762 }
763 catch (RegistryException e) {
764 throw new RuntimeException(e);
765 }
766 }
767
768 return null;
769 }
770
771
772
773
774
775
776
777
778
779
780
781 protected Service getServiceFromBusinessService(BusinessService bs, LifeCycleManager lcm)
782 throws JAXRException {
783
784 ServiceImpl./../../org/apache/ws/scout/registry/infomodel/ServiceImpl.html#ServiceImpl">ServiceImpl service = (ServiceImpl) ScoutUddiJaxrHelper.getService(bs, lcm);
785 service.setSubmittingOrganizationKey(bs.getBusinessKey());
786
787 return service;
788 }
789
790
791
792
793
794
795
796
797
798
799
800 public BulkResponse getRegistryObjects() throws JAXRException
801 {
802 String types[] = {
803 LifeCycleManager.ORGANIZATION,
804 LifeCycleManager.SERVICE};
805
806 LinkedHashSet<Object> c = new LinkedHashSet<Object>();
807
808 for (int i = 0; i < types.length; i++) {
809 try {
810 BulkResponse bk = getRegistryObjects(types[i]);
811
812 if (bk.getCollection() != null) {
813 c.addAll(bk.getCollection());
814 }
815 } catch(JAXRException e) {
816 log.debug("ignore - just a problem with that type? " + e.getMessage(), e);
817 }
818 }
819
820 return new BulkResponseImpl(c);
821 }
822
823 public BulkResponse getRegistryObjects(Collection objectKeys) throws JAXRException
824 {
825 throw new UnsupportedCapabilityException();
826 }
827
828 public BulkResponse getRegistryObjects(Collection objectKeys, String objectType) throws JAXRException
829 {
830 IRegistry/../../../org/apache/ws/scout/registry/IRegistry.html#IRegistry">IRegistry registry = (IRegistry) registryService.getRegistry();
831
832 String[] keys = new String[objectKeys.size()];
833 int currLoc = 0;
834 for (Key key : (Collection<Key>) objectKeys) {
835 keys[currLoc] = key.getId();
836 currLoc++;
837 }
838 LinkedHashSet<RegistryObject> col = new LinkedHashSet<RegistryObject>();
839 LifeCycleManager lcm = registryService.getLifeCycleManagerImpl();
840
841 if (LifeCycleManager.CLASSIFICATION_SCHEME.equalsIgnoreCase(objectType))
842 {
843 try
844 {
845 TModelDetail tmodeldetail = registry.getTModelDetail(keys);
846 List<TModel> tmodelList = tmodeldetail.getTModel();
847
848 for (TModel tModel: tmodelList)
849 {
850 col.add(ScoutUddiJaxrHelper.getConcept(tModel, lcm));
851 }
852
853 } catch (RegistryException e)
854 {
855 throw new JAXRException(e.getLocalizedMessage());
856 }
857 }
858 else if (LifeCycleManager.ORGANIZATION.equalsIgnoreCase(objectType))
859 {
860 ConnectionImpl con = ((RegistryServiceImpl)getRegistryService()).getConnection();
861 AuthToken auth = this.getAuthToken(con,registry);
862
863 try
864 {
865 RegisteredInfo ri = null;
866 try {
867 ri = registry.getRegisteredInfo(auth.getAuthInfo());
868 } catch (RegistryException rve) {
869 String username = getUsernameFromCredentials(con.getCredentials());
870 if (AuthTokenSingleton.getToken(username) != null) {
871 AuthTokenSingleton.deleteAuthToken(username);
872 }
873 auth = getAuthToken(con, registry);
874 ri = registry.getRegisteredInfo(auth.getAuthInfo());
875 }
876
877 if (ri != null) {
878 for (String key:keys) {
879 BusinessDetail detail = registry.getBusinessDetail(key);
880 col.add(((BusinessLifeCycleManagerImpl)registryService.getLifeCycleManagerImpl()).createOrganization(detail));
881 }
882
883 }
884 } catch (RegistryException e) {
885 throw new JAXRException(e.getLocalizedMessage());
886 }
887 }
888 else if (LifeCycleManager.CONCEPT.equalsIgnoreCase(objectType))
889 {
890 try {
891 TModelDetail tmodeldetail = registry.getTModelDetail(keys);
892 List<TModel> tmodelList = tmodeldetail.getTModel();
893
894 for (TModel tmodel: tmodelList)
895 {
896 col.add(ScoutUddiJaxrHelper.getConcept(tmodel, lcm));
897 }
898
899 }
900 catch (RegistryException e)
901 {
902 throw new JAXRException(e.getLocalizedMessage());
903 }
904 }
905 else if (LifeCycleManager.SERVICE.equalsIgnoreCase(objectType)) {
906
907 try {
908 ServiceDetail serviceDetail = registry.getServiceDetail(keys);
909
910 if (serviceDetail != null) {
911 List<BusinessService> bizServiceList = serviceDetail.getBusinessService();
912
913 for (BusinessService businessService: bizServiceList) {
914
915 Service service = getServiceFromBusinessService(businessService, lcm);
916
917 col.add(service);
918 }
919 }
920 }
921 catch (RegistryException e) {
922 throw new JAXRException(e);
923 }
924 }
925 else {
926 throw new JAXRException("Unsupported type " + objectType +
927 " for getRegistryObjects() in Apache Scout");
928 }
929
930 return new BulkResponseImpl(col);
931
932 }
933
934 public BulkResponse getRegistryObjects(String id) throws JAXRException
935 {
936 if (LifeCycleManager.ORGANIZATION.equalsIgnoreCase(id)) {
937 IRegistry/../../../org/apache/ws/scout/registry/IRegistry.html#IRegistry">IRegistry registry = (IRegistry) registryService.getRegistry();
938 ConnectionImpl con = ((RegistryServiceImpl)getRegistryService()).getConnection();
939 AuthToken auth = this.getAuthToken(con,registry);
940 LinkedHashSet<Organization> orgs = null;
941 try
942 {
943 RegisteredInfo ri = null;
944 try {
945 ri = registry.getRegisteredInfo(auth.getAuthInfo());
946 } catch (RegistryException rve) {
947 String username = getUsernameFromCredentials(con.getCredentials());
948 if (AuthTokenSingleton.getToken(username) != null) {
949 AuthTokenSingleton.deleteAuthToken(username);
950 }
951 auth = getAuthToken(con, registry);
952 ri = registry.getRegisteredInfo(auth.getAuthInfo());
953 }
954
955 if (ri != null && ri.getBusinessInfos()!=null) {
956 List<BusinessInfo> bizInfoList = ri.getBusinessInfos().getBusinessInfo();
957 orgs = new LinkedHashSet<Organization>();
958 for (BusinessInfo businessInfo : bizInfoList) {
959 BusinessDetail detail = registry.getBusinessDetail(businessInfo.getBusinessKey());
960 orgs.add(((BusinessLifeCycleManagerImpl)registryService.getLifeCycleManagerImpl()).createOrganization(detail));
961 }
962 }
963
964 } catch (RegistryException re) {
965 throw new JAXRException(re);
966 }
967 return new BulkResponseImpl(orgs);
968 }
969 else if (LifeCycleManager.SERVICE.equalsIgnoreCase(id)) {
970 List<String> a = new ArrayList<String>();
971 a.add("%");
972
973 BulkResponse br = this.findServices(null,null, a, null, null);
974
975 return br;
976 }
977 else
978 {
979 throw new JAXRException("Unsupported type for getRegistryObjects() :" + id);
980 }
981
982 }
983
984 static FindQualifiers mapFindQualifiers(Collection jaxrQualifiers) throws UnsupportedCapabilityException
985 {
986 if (jaxrQualifiers == null)
987 {
988 return null;
989 }
990 FindQualifiers result = objectFactory.createFindQualifiers();
991 for (Iterator i = jaxrQualifiers.iterator(); i.hasNext();)
992 {
993 String jaxrQualifier = (String) i.next();
994 String juddiQualifier = jaxrQualifier;
995 if (juddiQualifier == null)
996 {
997 throw new UnsupportedCapabilityException("jUDDI does not support FindQualifer: " + jaxrQualifier);
998 }
999 result.getFindQualifier().add(juddiQualifier);
1000 }
1001 return result;
1002 }
1003
1004 static Name[] mapNamePatterns(Collection namePatterns)
1005 throws JAXRException
1006 {
1007 if (namePatterns == null)
1008 return null;
1009 Name[] result = new Name[namePatterns.size()];
1010 int currLoc = 0;
1011 for (Iterator i = namePatterns.iterator(); i.hasNext();)
1012 {
1013 Object obj = i.next();
1014 Name name = objectFactory.createName();
1015 if (obj instanceof String) {
1016 name.setValue((String)obj);
1017 } else if (obj instanceof LocalizedString) {
1018 LocalizedString ls = (LocalizedString)obj;
1019 name.setValue(ls.getValue());
1020 name.setLang(ls.getLocale().getLanguage());
1021 }
1022 result[currLoc] = name;
1023 currLoc++;
1024 }
1025 return result;
1026 }
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036 private AuthToken getAuthToken(ConnectionImpl connection, IRegistry ireg)
1037 throws JAXRException {
1038 Set creds = connection.getCredentials();
1039 Iterator it = creds.iterator();
1040 String username = "", pwd = "";
1041 while (it.hasNext()) {
1042 PasswordAuthentication pass = (PasswordAuthentication) it.next();
1043 username = pass.getUserName();
1044 pwd = new String(pass.getPassword());
1045 }
1046
1047 if (AuthTokenSingleton.getToken(username) != null) {
1048 return (AuthToken) AuthTokenSingleton.getToken(username);
1049 }
1050
1051 AuthToken token = null;
1052 try {
1053 token = ireg.getAuthToken(username, pwd);
1054 }
1055 catch (Exception e) {
1056 throw new JAXRException(e);
1057 }
1058 AuthTokenSingleton.addAuthToken(username, token);
1059
1060 return token;
1061 }
1062
1063 private String getUsernameFromCredentials(Set credentials) {
1064 String username = "", pwd = "";
1065
1066 if (credentials != null) {
1067 Iterator it = credentials.iterator();
1068 while (it.hasNext()) {
1069 PasswordAuthentication pass = (PasswordAuthentication) it.next();
1070 username = pass.getUserName();
1071 }
1072 }
1073 return username;
1074 }
1075
1076 }