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