This project has retired. For details please refer to its
Attic page.
ScoutUddiV3JaxrHelper xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.ws.scout.util;
18
19 import java.util.ArrayList;
20 import java.util.Collection;
21 import java.util.HashMap;
22 import java.util.Iterator;
23 import java.util.List;
24 import java.util.Locale;
25
26 import javax.xml.registry.JAXRException;
27 import javax.xml.registry.LifeCycleManager;
28 import javax.xml.registry.infomodel.Association;
29 import javax.xml.registry.infomodel.Classification;
30 import javax.xml.registry.infomodel.ClassificationScheme;
31 import javax.xml.registry.infomodel.Concept;
32 import javax.xml.registry.infomodel.EmailAddress;
33 import javax.xml.registry.infomodel.ExternalIdentifier;
34 import javax.xml.registry.infomodel.ExternalLink;
35 import javax.xml.registry.infomodel.InternationalString;
36 import javax.xml.registry.infomodel.Organization;
37 import javax.xml.registry.infomodel.PostalAddress;
38 import javax.xml.registry.infomodel.RegistryObject;
39 import javax.xml.registry.infomodel.Service;
40 import javax.xml.registry.infomodel.ServiceBinding;
41 import javax.xml.registry.infomodel.SpecificationLink;
42 import javax.xml.registry.infomodel.TelephoneNumber;
43 import javax.xml.registry.infomodel.User;
44
45 import org.uddi.api_v3.*;
46 import org.apache.ws.scout.registry.infomodel.AssociationImpl;
47 import org.apache.ws.scout.registry.infomodel.ClassificationImpl;
48 import org.apache.ws.scout.registry.infomodel.ClassificationSchemeImpl;
49 import org.apache.ws.scout.registry.infomodel.ConceptImpl;
50 import org.apache.ws.scout.registry.infomodel.EmailAddressImpl;
51 import org.apache.ws.scout.registry.infomodel.ExternalIdentifierImpl;
52 import org.apache.ws.scout.registry.infomodel.ExternalLinkImpl;
53 import org.apache.ws.scout.registry.infomodel.InternationalStringImpl;
54 import org.apache.ws.scout.registry.infomodel.KeyImpl;
55 import org.apache.ws.scout.registry.infomodel.OrganizationImpl;
56 import org.apache.ws.scout.registry.infomodel.PersonNameImpl;
57 import org.apache.ws.scout.registry.infomodel.PostalAddressImpl;
58 import org.apache.ws.scout.registry.infomodel.ServiceBindingImpl;
59 import org.apache.ws.scout.registry.infomodel.ServiceImpl;
60 import org.apache.ws.scout.registry.infomodel.SpecificationLinkImpl;
61 import org.apache.ws.scout.registry.infomodel.TelephoneNumberImpl;
62 import org.apache.ws.scout.registry.infomodel.UserImpl;
63
64
65
66
67
68
69
70
71 public class ScoutUddiV3JaxrHelper
72 {
73 public static Association getAssociation(Collection orgs,
74 LifeCycleManager lcm)
75 throws JAXRException
76 {
77 Association asso = new AssociationImpl(lcm);
78 Object[] arr = orgs.toArray();
79 asso.setSourceObject((RegistryObject)arr[0]);
80 asso.setTargetObject((RegistryObject)arr[1]);
81 return asso;
82 }
83
84 public static Organization getOrganization(BusinessEntity businessEntity,
85 LifeCycleManager lifeCycleManager)
86 throws JAXRException
87 {
88 Organization org = new OrganizationImpl(lifeCycleManager);
89 List<Name> namesList = businessEntity.getName();
90 if ((namesList != null) && (namesList.size() > 0)) {
91 InternationalString is = null;
92 for (Name n : namesList) {
93 if (is == null) {
94 is = getIString(n.getLang(), n.getValue(), lifeCycleManager);
95 } else {
96 is.setValue(getLocale(n.getLang()), n.getValue());
97 }
98 }
99 org.setName(is);
100 }
101
102 List<Description> descriptionList = businessEntity.getDescription();
103 if ((descriptionList != null) && (descriptionList.size() > 0)) {
104 InternationalString is = null;
105 for (Description desc : descriptionList) {
106 if (is == null) {
107 is = getIString(desc.getLang(), desc.getValue(), lifeCycleManager);
108 } else {
109 is.setValue(getLocale(desc.getLang()), desc.getValue());
110 }
111 }
112 org.setDescription(is);
113 }
114 org.setKey(lifeCycleManager.createKey(businessEntity.getBusinessKey()));
115
116
117 BusinessServices services = businessEntity.getBusinessServices();
118 if(services != null)
119 {
120 List<BusinessService> bizServiceList = services.getBusinessService();
121 for (BusinessService businessService : bizServiceList) {
122 org.addService(getService(businessService, lifeCycleManager));
123 }
124 }
125
126
127
128
129
130
131
132
133
134
135
136 Contacts contacts = businessEntity.getContacts();
137 if(contacts != null)
138 {
139 List<Contact> contactList = contacts.getContact();
140 if (contactList!=null) {
141 boolean isFirst=true;
142 for (Contact contact : contactList) {
143 User user = new UserImpl(null);
144 List<PersonName> pname = contact.getPersonName();
145 if (pname != null && pname.size() > 0) {
146 String name = pname.get(0).getValue();
147 user.setPersonName(new PersonNameImpl(name));
148 }
149 if (isFirst) {
150 isFirst=false;
151 org.setPrimaryContact(user);
152 } else {
153 org.addUser(user);
154 }
155 }
156 }
157 }
158
159
160 DiscoveryURLs durls = businessEntity.getDiscoveryURLs();
161 if (durls != null)
162 {
163 List<DiscoveryURL> discoveryURL_List = durls.getDiscoveryURL();
164 for (DiscoveryURL discoveryURL : discoveryURL_List) {
165 ExternalLink link = new ExternalLinkImpl(lifeCycleManager);
166 link.setExternalURI(discoveryURL.getValue());
167 org.addExternalLink(link);
168 }
169 }
170
171 org.addExternalIdentifiers(getExternalIdentifiers(businessEntity.getIdentifierBag(), lifeCycleManager));
172 org.addClassifications(getClassifications(businessEntity.getCategoryBag(), lifeCycleManager));
173
174 return org;
175 }
176
177
178 public static Organization getOrganization(BusinessDetail bizdetail,
179 LifeCycleManager lifeCycleManager)
180 throws JAXRException
181 {
182 List<BusinessEntity> bizEntityList = bizdetail.getBusinessEntity();
183 Organization org = new OrganizationImpl(lifeCycleManager);
184 if (bizEntityList.size() != 1) {
185 throw new JAXRException("Unexpected count of organizations in BusinessDetail: " + bizEntityList.size());
186 }
187 BusinessEntity entity = bizEntityList.get(0);
188 List<Name> namesList = entity.getName();
189 if ((namesList != null) && (namesList.size() > 0)) {
190 InternationalString is = null;
191 for (Name n : namesList) {
192 if (is == null) {
193 is = getIString(n.getLang(), n.getValue(), lifeCycleManager);
194 } else {
195 is.setValue(getLocale(n.getLang()), n.getValue());
196 }
197 }
198 org.setName(is);
199 }
200
201 List<Description> descriptionList = entity.getDescription();
202 if ((descriptionList != null) && (descriptionList.size() > 0)) {
203 InternationalString is = null;
204 for (Description desc : descriptionList) {
205 if (is == null) {
206 is = getIString(desc.getLang(), desc.getValue(), lifeCycleManager);
207 } else {
208 is.setValue(getLocale(desc.getLang()), desc.getValue());
209 }
210 }
211 org.setDescription(is);
212 }
213 org.setKey(lifeCycleManager.createKey(entity.getBusinessKey()));
214
215
216 BusinessServices services = entity.getBusinessServices();
217 if (services != null) {
218 List<BusinessService> bizServiceList = services.getBusinessService();
219 for (BusinessService businessService : bizServiceList) {
220 org.addService(getService(businessService, lifeCycleManager));
221 }
222 }
223
224
225
226
227
228
229
230
231
232
233 Contacts contacts = entity.getContacts();
234 if (contacts != null) {
235 List<Contact> contactList = contacts.getContact();
236 boolean isFirst=true;
237 for (Contact contact : contactList) {
238 User user = new UserImpl(null);
239 List<PersonName> pnames = (List<PersonName>) contact.getPersonName();
240 String pname = null;
241 if (pnames != null && pnames.size() > 0) {
242 PersonName personname = pnames.get(0);
243 pname = personname.getValue();
244 }
245 user.setType(contact.getUseType());
246 user.setPersonName(new PersonNameImpl(pname));
247
248 List<Email> emailList = contact.getEmail();
249 ArrayList<EmailAddress> tempEmails = new ArrayList<EmailAddress>();
250 for (Email email : emailList) {
251 tempEmails.add(new EmailAddressImpl(email.getValue(), null));
252 }
253 user.setEmailAddresses(tempEmails);
254
255 List<Address> addressList = contact.getAddress();
256 ArrayList<PostalAddress> tempAddresses = new ArrayList<PostalAddress>();
257 for (Address address : addressList) {
258 ArrayList<AddressLine> addressLineList = new ArrayList<AddressLine>(address.getAddressLine());
259 AddressLine[] alines = new AddressLine[addressLineList.size()];
260 addressLineList.toArray(alines);
261
262 PostalAddress pa = getPostalAddress(alines);
263 tempAddresses.add(pa);
264 }
265 user.setPostalAddresses(tempAddresses);
266
267 List<Phone> phoneList = contact.getPhone();
268 ArrayList<TelephoneNumber> tempPhones = new ArrayList<TelephoneNumber>();
269 for (Phone phone : phoneList) {
270 TelephoneNumberImpl tni = new TelephoneNumberImpl();
271 tni.setType(phone.getUseType());
272 tni.setNumber(phone.getValue());
273 tempPhones.add(tni);
274 }
275 user.setTelephoneNumbers(tempPhones);
276 if (isFirst) {
277 isFirst=false;
278 org.setPrimaryContact(user);
279 } else {
280 org.addUser(user);
281 }
282 }
283 }
284
285 DiscoveryURLs durls = entity.getDiscoveryURLs();
286 if (durls != null)
287 {
288 List<DiscoveryURL> discoveryURL_List = durls.getDiscoveryURL();
289 for (DiscoveryURL discoveryURL : discoveryURL_List) {
290 ExternalLink link = new ExternalLinkImpl(lifeCycleManager);
291 link.setExternalURI(discoveryURL.getValue());
292 org.addExternalLink(link);
293 }
294 }
295
296 org.addExternalIdentifiers(getExternalIdentifiers(entity.getIdentifierBag(), lifeCycleManager));
297 org.addClassifications(getClassifications(entity.getCategoryBag(), lifeCycleManager));
298
299 return org;
300 }
301
302 private static PostalAddress getPostalAddress(AddressLine[] addressLineArr) throws JAXRException {
303 PostalAddress pa = new PostalAddressImpl();
304 HashMap<String, String> hm = new HashMap<String, String>();
305 for (AddressLine anAddressLineArr : addressLineArr) {
306 hm.put(anAddressLineArr.getKeyValue(), anAddressLineArr.getValue());
307 }
308
309 if (hm.containsKey("STREET_NUMBER")) {
310 pa.setStreetNumber(hm.get("STREET_NUMBER"));
311 }
312
313 if (hm.containsKey("STREET")) {
314 pa.setStreet(hm.get("STREET"));
315 }
316
317 if (hm.containsKey("CITY")) {
318 pa.setCity(hm.get("CITY"));
319 }
320
321 if (hm.containsKey("COUNTRY")) {
322 pa.setCountry(hm.get("COUNTRY"));
323 }
324
325 if (hm.containsKey("POSTALCODE")) {
326 pa.setPostalCode(hm.get("POSTALCODE"));
327 }
328
329 if (hm.containsKey("STATE")) {
330 pa.setStateOrProvince(hm.get("STATE"));
331 }
332
333 return pa;
334 }
335
336 private static InternationalString getIString(String lang, String str, LifeCycleManager lifeCycleManager)
337 throws JAXRException
338 {
339 if (str!=null) {
340 return lifeCycleManager.createInternationalString(getLocale(lang), str);
341 } else {
342 return null;
343 }
344 }
345
346 public static InternationalString getIString(String str, LifeCycleManager lifeCycleManager)
347 throws JAXRException
348 {
349 return lifeCycleManager.createInternationalString(str);
350 }
351
352 public static Service getService(BusinessService businessService, LifeCycleManager lifeCycleManager)
353 throws JAXRException
354 {
355 Service serve = new ServiceImpl(lifeCycleManager);
356
357 String keystr = businessService.getServiceKey();
358
359 if (keystr != null)
360 {
361 serve.setKey(lifeCycleManager.createKey(keystr));
362 }
363
364 List<Name> namesList = businessService.getName();
365 InternationalString is = null;
366 for (Name n : namesList) {
367 if (is == null) {
368 is = lifeCycleManager.createInternationalString(getLocale(n.getLang()), n.getValue());
369 } else {
370 is.setValue(getLocale(n.getLang()), n.getValue());
371 }
372 }
373 serve.setName(is);
374
375 List<Description> descriptionList = businessService.getDescription();
376 InternationalString dis = null;
377 for (Description desc : descriptionList) {
378 if (dis == null) {
379 dis = lifeCycleManager.createInternationalString(getLocale(desc.getLang()), desc.getValue());
380 } else {
381 dis.setValue(getLocale(desc.getLang()), desc.getValue());
382 }
383 }
384 serve.setDescription(dis);
385
386
387 BindingTemplates bts = businessService.getBindingTemplates();
388 if (bts != null) {
389 List<BindingTemplate> bindingTemplateList = bts.getBindingTemplate();
390 for (BindingTemplate bindingTemplate : bindingTemplateList) {
391 serve.addServiceBinding(getServiceBinding(bindingTemplate, lifeCycleManager));
392 }
393 }
394 serve.addClassifications(getClassifications(businessService.getCategoryBag(), lifeCycleManager));
395
396 return serve;
397 }
398
399 public static Service getService(ServiceInfo serviceInfo, LifeCycleManager lifeCycleManager)
400 throws JAXRException
401 {
402 Service service = new ServiceImpl(lifeCycleManager);
403
404 String keystr = serviceInfo.getServiceKey();
405
406 if (keystr != null)
407 {
408 service.setKey(lifeCycleManager.createKey(keystr));
409 }
410
411 List<Name> namesList = serviceInfo.getName();
412 InternationalString is = null;
413 for (Name n : namesList) {
414 if (is == null) {
415 is = lifeCycleManager.createInternationalString(getLocale(n.getLang()), n.getValue());
416 } else {
417 is.setValue(getLocale(n.getLang()), n.getValue());
418 }
419 }
420 service.setName(is);
421 return service;
422 }
423
424 public static ServiceBinding getServiceBinding(BindingTemplate businessTemplate, LifeCycleManager lifeCycleManager)
425 throws JAXRException
426 {
427 ServiceBinding serviceBinding = new ServiceBindingImpl(lifeCycleManager);
428
429 String keystr = businessTemplate.getServiceKey();
430 if (keystr != null)
431 {
432 Service svc = new ServiceImpl(lifeCycleManager);
433 svc.setKey(lifeCycleManager.createKey(keystr));
434 ((ServiceBindingImpl)serviceBinding).setService(svc);
435 }
436 String bindingKey = businessTemplate.getBindingKey();
437 if(bindingKey != null) serviceBinding.setKey(new KeyImpl(bindingKey));
438
439
440 AccessPoint access = businessTemplate.getAccessPoint();
441 if (access != null) serviceBinding.setAccessURI(access.getValue());
442
443
444 Description desc = null;
445 if (businessTemplate.getDescription().size()>0) desc = businessTemplate.getDescription().get(0);
446 if (desc!=null) {
447 serviceBinding.setDescription(new InternationalStringImpl(desc.getValue()));
448 }
449
450
451 TModelInstanceDetails details = businessTemplate.getTModelInstanceDetails();
452 if (details != null) {
453 List<TModelInstanceInfo> tmodelInstanceInfoList = details.getTModelInstanceInfo();
454
455 for (TModelInstanceInfo info: tmodelInstanceInfoList)
456 {
457 if (info!=null && info.getInstanceDetails()!=null) {
458 InstanceDetails idetails = info.getInstanceDetails();
459 Collection<ExternalLink> elinks = getExternalLinks(idetails.getOverviewDoc(),lifeCycleManager);
460 SpecificationLink slink = new SpecificationLinkImpl(lifeCycleManager);
461 slink.addExternalLinks(elinks);
462 serviceBinding.addSpecificationLink(slink);
463
464 ConceptImpl c = new ConceptImpl(lifeCycleManager);
465 c.setExternalLinks(elinks);
466 c.setKey(lifeCycleManager.createKey(info.getTModelKey()));
467 c.setName(lifeCycleManager.createInternationalString(idetails.getInstanceParms()));
468 c.setValue(idetails.getInstanceParms());
469
470 slink.setSpecificationObject(c);
471 }
472 }
473 }
474 HostingRedirector hr = businessTemplate.getHostingRedirector();
475 if(hr != null)
476 {
477 ServiceBinding sb = lifeCycleManager.createServiceBinding();
478 sb.setKey(new KeyImpl(hr.getBindingKey()));
479 serviceBinding.setTargetBinding(sb);
480 }
481 serviceBinding.addClassifications(getClassifications(businessTemplate.getCategoryBag(), lifeCycleManager));
482
483 return serviceBinding;
484 }
485
486 public static Concept getConcept(TModelDetail tModelDetail, LifeCycleManager lifeCycleManager)
487 throws JAXRException
488 {
489 Concept concept = new ConceptImpl(lifeCycleManager);
490 List<TModel> tmodelList = tModelDetail.getTModel();
491 for (TModel tmodel : tmodelList) {
492 concept.setKey(lifeCycleManager.createKey(tmodel.getTModelKey()));
493 concept.setName(lifeCycleManager.createInternationalString(getLocale(tmodel.getName().getLang()),
494 tmodel.getName().getValue()));
495
496 Description desc = getDescription(tmodel);
497 if( desc != null ) {
498 concept.setDescription(lifeCycleManager.createInternationalString(getLocale(desc.getLang()),
499 desc.getValue()));
500 }
501
502 concept.addExternalIdentifiers(getExternalIdentifiers(tmodel.getIdentifierBag(), lifeCycleManager));
503 concept.addClassifications(getClassifications(tmodel.getCategoryBag(), lifeCycleManager));
504 }
505 return concept;
506 }
507
508 public static Concept getConcept(TModel tmodel, LifeCycleManager lifeCycleManager)
509 throws JAXRException
510 {
511 Concept concept = new ConceptImpl(lifeCycleManager);
512 concept.setKey(lifeCycleManager.createKey(tmodel.getTModelKey()));
513 concept.setName(lifeCycleManager.createInternationalString(getLocale(tmodel.getName().getLang()),
514 tmodel.getName().getValue()));
515
516 Description desc = getDescription(tmodel);
517 if (desc != null) {
518 concept.setDescription(lifeCycleManager.createInternationalString(getLocale(desc.getLang()),
519 desc.getValue()));
520 }
521
522 concept.addExternalIdentifiers(getExternalIdentifiers(tmodel.getIdentifierBag(), lifeCycleManager));
523 concept.addClassifications(getClassifications(tmodel.getCategoryBag(), lifeCycleManager));
524
525 return concept;
526 }
527
528 public static Concept getConcept(TModelInfo tModelInfo, LifeCycleManager lifeCycleManager)
529 throws JAXRException
530 {
531 Concept concept = new ConceptImpl(lifeCycleManager);
532 concept.setKey(lifeCycleManager.createKey(tModelInfo.getTModelKey()));
533 concept.setName(lifeCycleManager.createInternationalString(getLocale(tModelInfo.getName().getLang()),
534 tModelInfo.getName().getValue()));
535
536 return concept;
537 }
538
539 private static Description getDescription( TModel tmodel )
540 {
541 Description desc = null;
542 if (tmodel.getDescription().size()>0) desc=tmodel.getDescription().get(0);
543 return desc;
544 }
545
546
547
548
549
550
551
552
553 public static Collection getClassifications(CategoryBag categoryBag, LifeCycleManager lifeCycleManager)
554 throws JAXRException {
555 Collection<Classification> classifications = null;
556 if (categoryBag != null) {
557 classifications = new ArrayList<Classification>();
558 List<KeyedReference> keyedReferenceList = categoryBag.getKeyedReference();
559 for (KeyedReference keyedReference : keyedReferenceList) {
560 Classification classification = new ClassificationImpl(lifeCycleManager);
561 classification.setValue(keyedReference.getKeyValue());
562 classification.setName(new InternationalStringImpl(keyedReference.getKeyName()));
563 String tmodelKey = keyedReference.getTModelKey();
564 if (tmodelKey != null) {
565 ClassificationScheme scheme = new ClassificationSchemeImpl(lifeCycleManager);
566 scheme.setKey(new KeyImpl(tmodelKey));
567 classification.setClassificationScheme(scheme);
568 }
569 classifications.add(classification);
570 }
571 }
572 return classifications;
573 }
574
575 public static Collection<ExternalLink> getExternalLinks(List<OverviewDoc> overviewDocs, LifeCycleManager lifeCycleManager)
576 throws JAXRException
577 {
578 ArrayList<ExternalLink> alist = new ArrayList<ExternalLink>();
579 if((overviewDocs != null) && (overviewDocs.size() != 0))
580 {
581 Iterator docIter = overviewDocs.iterator();
582 while (docIter.hasNext()) {
583 OverviewDoc overviewDoc = (OverviewDoc) docIter.next();
584 String descStr = "";
585 Description desc = null;
586 if (overviewDoc.getDescription().size()>0) desc = overviewDoc.getDescription().get(0);
587 if (desc !=null) descStr = desc.getValue();
588 alist.add(lifeCycleManager.createExternalLink(overviewDoc.getOverviewURL().getValue().toString(),descStr));
589
590 }
591 }
592 return alist;
593 }
594
595
596
597
598
599
600
601
602
603 public static Collection getExternalIdentifiers(IdentifierBag identifierBag, LifeCycleManager lifeCycleManager)
604 throws JAXRException {
605 Collection<ExternalIdentifier> extidentifiers = null;
606 if (identifierBag != null) {
607 extidentifiers = new ArrayList<ExternalIdentifier>();
608
609 List<KeyedReference> keyedReferenceList = identifierBag.getKeyedReference();
610 for (KeyedReference keyedReference : keyedReferenceList) {
611 ExternalIdentifier extId = new ExternalIdentifierImpl(lifeCycleManager);
612 extId.setValue(keyedReference.getKeyValue());
613 extId.setName(new InternationalStringImpl(keyedReference.getKeyName()));
614
615 String tmodelKey = keyedReference.getTModelKey();
616 if (tmodelKey != null) {
617 ClassificationScheme scheme = new ClassificationSchemeImpl(lifeCycleManager);
618 scheme.setKey(new KeyImpl(tmodelKey));
619 extId.setIdentificationScheme(scheme);
620 }
621 extidentifiers.add(extId);
622 }
623 }
624 return extidentifiers;
625 }
626
627 private static Locale getLocale(String lang) {
628 if (lang == null || lang.trim().length() == 0) {
629 return Locale.getDefault();
630 } else if (lang.equalsIgnoreCase(Locale.getDefault().getLanguage())) {
631 return Locale.getDefault();
632 } else {
633 return new Locale(lang);
634 }
635 }
636
637 }