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.Arrays;
20 import java.util.Collection;
21 import java.util.Iterator;
22 import java.util.List;
23 import java.util.StringTokenizer;
24
25 import javax.xml.registry.JAXRException;
26 import javax.xml.registry.infomodel.Association;
27 import javax.xml.registry.infomodel.Classification;
28 import javax.xml.registry.infomodel.ClassificationScheme;
29 import javax.xml.registry.infomodel.Concept;
30 import javax.xml.registry.infomodel.EmailAddress;
31 import javax.xml.registry.infomodel.ExternalIdentifier;
32 import javax.xml.registry.infomodel.ExternalLink;
33 import javax.xml.registry.infomodel.InternationalString;
34 import javax.xml.registry.infomodel.Key;
35 import javax.xml.registry.infomodel.LocalizedString;
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.Slot;
42 import javax.xml.registry.infomodel.SpecificationLink;
43 import javax.xml.registry.infomodel.TelephoneNumber;
44 import javax.xml.registry.infomodel.User;
45
46 import org.apache.commons.logging.Log;
47 import org.apache.commons.logging.LogFactory;
48 import org.apache.ws.scout.model.uddi.v2.AccessPoint;
49 import org.apache.ws.scout.model.uddi.v2.Address;
50 import org.apache.ws.scout.model.uddi.v2.AddressLine;
51 import org.apache.ws.scout.model.uddi.v2.BindingTemplate;
52 import org.apache.ws.scout.model.uddi.v2.BindingTemplates;
53 import org.apache.ws.scout.model.uddi.v2.BusinessEntity;
54 import org.apache.ws.scout.model.uddi.v2.BusinessService;
55 import org.apache.ws.scout.model.uddi.v2.BusinessServices;
56 import org.apache.ws.scout.model.uddi.v2.CategoryBag;
57 import org.apache.ws.scout.model.uddi.v2.Contact;
58 import org.apache.ws.scout.model.uddi.v2.Contacts;
59 import org.apache.ws.scout.model.uddi.v2.Description;
60 import org.apache.ws.scout.model.uddi.v2.DiscoveryURL;
61 import org.apache.ws.scout.model.uddi.v2.DiscoveryURLs;
62 import org.apache.ws.scout.model.uddi.v2.Email;
63 import org.apache.ws.scout.model.uddi.v2.HostingRedirector;
64 import org.apache.ws.scout.model.uddi.v2.IdentifierBag;
65 import org.apache.ws.scout.model.uddi.v2.InstanceDetails;
66 import org.apache.ws.scout.model.uddi.v2.KeyedReference;
67 import org.apache.ws.scout.model.uddi.v2.Name;
68 import org.apache.ws.scout.model.uddi.v2.ObjectFactory;
69 import org.apache.ws.scout.model.uddi.v2.OverviewDoc;
70 import org.apache.ws.scout.model.uddi.v2.Phone;
71 import org.apache.ws.scout.model.uddi.v2.PublisherAssertion;
72 import org.apache.ws.scout.model.uddi.v2.TModel;
73 import org.apache.ws.scout.model.uddi.v2.TModelBag;
74 import org.apache.ws.scout.model.uddi.v2.TModelInstanceDetails;
75 import org.apache.ws.scout.model.uddi.v2.TModelInstanceInfo;
76 import org.apache.ws.scout.model.uddi.v2.URLType;
77 import org.apache.ws.scout.registry.infomodel.InternationalStringImpl;
78
79
80
81
82
83
84
85
86
87 public class ScoutJaxrUddiHelper
88 {
89 private static final String UDDI_ORG_TYPES = "uuid:C1ACF26D-9672-4404-9D70-39B756E62AB4";
90 private static Log log = LogFactory.getLog(ScoutJaxrUddiHelper.class);
91 private static ObjectFactory objectFactory = new ObjectFactory();
92
93
94
95
96 public static Address getAddress(PostalAddress postalAddress) throws JAXRException {
97 Address address = objectFactory.createAddress();
98
99 AddressLine[] addarr = new AddressLine[6];
100
101 String stnum = postalAddress.getStreetNumber();
102 String st = postalAddress.getStreet();
103 String city = postalAddress.getCity();
104 String country = postalAddress.getCountry();
105 String code = postalAddress.getPostalCode();
106 String state = postalAddress.getStateOrProvince();
107
108 AddressLine stnumAL = objectFactory.createAddressLine();
109 stnumAL.setKeyName("STREET_NUMBER");
110 if (stnum != null) {
111 stnumAL.setKeyValue(stnum);
112 }
113
114 AddressLine stAL = objectFactory.createAddressLine();
115 stAL.setKeyName("STREET");
116 if (st != null) {
117 stAL.setKeyValue(st);
118 }
119
120 AddressLine cityAL = objectFactory.createAddressLine();
121 cityAL.setKeyName("CITY");
122 if (city != null) {
123 cityAL.setKeyValue(city);
124 }
125
126 AddressLine countryAL = objectFactory.createAddressLine();
127 countryAL.setKeyName("COUNTRY");
128 if (country != null) {
129 countryAL.setKeyValue(country);
130 }
131
132 AddressLine codeAL = objectFactory.createAddressLine();
133 codeAL.setKeyName("POSTALCODE");
134 if (code != null) {
135 codeAL.setKeyValue(code);
136 }
137
138 AddressLine stateAL = objectFactory.createAddressLine();
139 stateAL.setKeyName("STATE");
140 if (state != null) {
141 stateAL.setKeyValue(state);
142 }
143
144
145 addarr[0] = stnumAL;
146 addarr[1] = stAL;
147 addarr[2] = cityAL;
148 addarr[3] = countryAL;
149 addarr[4] = codeAL;
150 addarr[5] = stateAL;
151
152 address.getAddressLine().addAll(Arrays.asList(addarr));
153
154 return address;
155 }
156
157 public static BindingTemplate getBindingTemplateFromJAXRSB(
158 ServiceBinding serviceBinding) throws JAXRException {
159 BindingTemplate bt = objectFactory.createBindingTemplate();
160 if (serviceBinding.getKey() != null && serviceBinding.getKey().getId() != null) {
161 bt.setBindingKey(serviceBinding.getKey().getId());
162 } else {
163 bt.setBindingKey("");
164 }
165
166 try {
167
168 String accessuri = serviceBinding.getAccessURI();
169 if (accessuri != null) {
170 AccessPoint accessPoint = objectFactory.createAccessPoint();
171 accessPoint.setURLType(getURLType(accessuri));
172 accessPoint.setValue(accessuri);
173 bt.setAccessPoint(accessPoint);
174 }
175 ServiceBinding sb = serviceBinding.getTargetBinding();
176 if (sb != null) {
177 HostingRedirector red = objectFactory.createHostingRedirector();
178 Key key = sb.getKey();
179 if (key != null && key.getId() != null) {
180 red.setBindingKey(key.getId());
181 } else {
182 red.setBindingKey("");
183 }
184 bt.setHostingRedirector(red);
185 } else {
186 if (bt.getAccessPoint() == null) {
187 bt.setAccessPoint(objectFactory.createAccessPoint());
188 }
189 }
190
191
192
193
194 Service svc = serviceBinding.getService();
195 if (svc != null && svc.getKey() != null && svc.getKey().getId() != null) {
196 bt.setServiceKey(svc.getKey().getId());
197 }
198
199 InternationalString idesc = serviceBinding.getDescription();
200
201 addDescriptions(bt.getDescription(), idesc);
202
203
204 Collection<SpecificationLink> slcol = serviceBinding.getSpecificationLinks();
205 TModelInstanceDetails tid = objectFactory.createTModelInstanceDetails();
206 if (slcol != null && !slcol.isEmpty()) {
207 Iterator<SpecificationLink> iter = slcol.iterator();
208 while (iter.hasNext()) {
209 SpecificationLink slink = (SpecificationLink) iter.next();
210
211 TModelInstanceInfo emptyTInfo = objectFactory.createTModelInstanceInfo();
212 tid.getTModelInstanceInfo().add(emptyTInfo);
213
214 RegistryObject specificationObject = slink.getSpecificationObject();
215 if (specificationObject.getKey() != null && specificationObject.getKey().getId() != null) {
216 emptyTInfo.setTModelKey(specificationObject.getKey().getId());
217 if (specificationObject.getDescription()!=null) {
218 for (Object o : specificationObject.getDescription().getLocalizedStrings()) {
219 LocalizedString locDesc = (LocalizedString) o;
220 Description description = objectFactory.createDescription();
221 emptyTInfo.getDescription().add(description);
222 description.setValue(locDesc.getValue());
223 description.setLang(locDesc.getLocale().getLanguage());
224 }
225 }
226 Collection<ExternalLink> externalLinks = slink.getExternalLinks();
227 if (externalLinks!=null && externalLinks.size()>0) {
228 for (ExternalLink link : externalLinks) {
229 InstanceDetails ids = objectFactory.createInstanceDetails();
230 emptyTInfo.setInstanceDetails(ids);
231 if (link.getDescription()!=null) {
232 Description description = objectFactory.createDescription();
233 ids.getDescription().add(description);
234 description.setValue(link.getDescription().getValue());
235 }
236 if (link.getExternalURI()!=null) {
237 OverviewDoc overviewDoc = objectFactory.createOverviewDoc();
238 ids.setOverviewDoc(overviewDoc);
239 overviewDoc.setOverviewURL(link.getExternalURI());
240 }
241 }
242 }
243 }
244 }
245 }
246 bt.setTModelInstanceDetails(tid);
247 log.debug("BindingTemplate=" + bt.toString());
248 } catch (Exception ud) {
249 throw new JAXRException("Apache JAXR Impl:", ud);
250 }
251 return bt;
252 }
253
254 public static PublisherAssertion getPubAssertionFromJAXRAssociation(
255 Association association) throws JAXRException {
256 PublisherAssertion pa = objectFactory.createPublisherAssertion();
257 try {
258 if (association.getSourceObject().getKey() != null &&
259 association.getSourceObject().getKey().getId() != null) {
260 pa.setFromKey(association.getSourceObject().getKey().getId());
261 }
262
263 if (association.getTargetObject().getKey() != null &&
264 association.getTargetObject().getKey().getId() != null) {
265 pa.setToKey(association.getTargetObject().getKey().getId());
266 }
267 Concept c = association.getAssociationType();
268 String v = c.getValue();
269 KeyedReference kr = objectFactory.createKeyedReference();
270 Key key = c.getKey();
271 if (key == null) {
272
273
274 key = c.getClassificationScheme().getKey();
275 }
276 if (key != null && key.getId() != null) {
277 kr.setTModelKey(key.getId());
278 }
279 kr.setKeyName("Concept");
280
281 if (v != null) {
282 kr.setKeyValue(v);
283 }
284
285 pa.setKeyedReference(kr);
286 } catch (Exception ud) {
287 throw new JAXRException("Apache JAXR Impl:", ud);
288 }
289 return pa;
290 }
291
292 public static PublisherAssertion getPubAssertionFromJAXRAssociationKey(
293 String key) throws JAXRException {
294 PublisherAssertion pa = objectFactory.createPublisherAssertion();
295 try {
296 StringTokenizer token = new StringTokenizer(key, "|");
297 if (token.hasMoreTokens()) {
298 pa.setFromKey(getToken(token.nextToken()));
299 pa.setToKey(getToken(token.nextToken()));
300 KeyedReference kr = objectFactory.createKeyedReference();
301
302 String str = getToken(token.nextToken());
303 if ("UUID".equals(str))
304 str += ":" + getToken(token.nextToken());
305 kr.setTModelKey(str);
306 kr.setKeyName(getToken(token.nextToken()));
307 kr.setKeyValue(getToken(token.nextToken()));
308 pa.setKeyedReference(kr);
309 }
310
311 } catch (Exception ud) {
312 throw new JAXRException("Apache JAXR Impl:", ud);
313 }
314 return pa;
315 }
316
317 public static BusinessService getBusinessServiceFromJAXRService(
318 Service service) throws JAXRException {
319 BusinessService bs = objectFactory.createBusinessService();
320 try {
321 InternationalString iname = service.getName();
322
323 addNames(bs.getName(), iname);
324
325 InternationalString idesc = service.getDescription();
326
327 addDescriptions(bs.getDescription(), idesc);
328
329 Organization o = service.getProvidingOrganization();
330
331
332
333
334 if (o != null) {
335 Key k = o.getKey();
336
337 if (k != null && k.getId() != null) {
338 bs.setBusinessKey(k.getId());
339 }
340
341 } else {
342
343
344
345 throw new JAXRException(
346 "Service has no associated organization");
347 }
348
349 if (service.getKey() != null && service.getKey().getId() != null) {
350 bs.setServiceKey(service.getKey().getId());
351 } else {
352 bs.setServiceKey("");
353 }
354
355 CategoryBag catBag = getCategoryBagFromClassifications(service.getClassifications());
356 if (catBag!=null) {
357 bs.setCategoryBag(catBag);
358 }
359
360
361 BindingTemplates bt = getBindingTemplates(service.getServiceBindings());
362 if (bt != null) {
363 bs.setBindingTemplates(bt);
364 }
365
366 log.debug("BusinessService=" + bs.toString());
367 } catch (Exception ud) {
368 throw new JAXRException("Apache JAXR Impl:", ud);
369 }
370 return bs;
371 }
372
373 public static TModel getTModelFromJAXRClassificationScheme(
374 ClassificationScheme classificationScheme) throws JAXRException {
375 TModel tm = objectFactory.createTModel();
376 try {
377
378
379
380
381 Key k = classificationScheme.getKey();
382
383 if (k != null && k.getId() != null) {
384 tm.setTModelKey(k.getId());
385 } else {
386 tm.setTModelKey("");
387 }
388
389
390
391
392
393 Slot s = classificationScheme.getSlot("authorizedName");
394
395 if (s != null && s.getName() != null) {
396 tm.setAuthorizedName(s.getName());
397 }
398
399 s = classificationScheme.getSlot("operator");
400
401 if (s != null && s.getName() != null) {
402 tm.setOperator(s.getName());
403 }
404
405 InternationalString iname = classificationScheme.getName();
406
407 tm.setName(getFirstName(iname));
408
409 InternationalString idesc = classificationScheme.getDescription();
410
411 addDescriptions(tm.getDescription(), idesc);
412
413 IdentifierBag idBag = getIdentifierBagFromExternalIdentifiers(classificationScheme.getExternalIdentifiers());
414 if (idBag!=null) {
415 tm.setIdentifierBag(idBag);
416 }
417 CategoryBag catBag = getCategoryBagFromClassifications(classificationScheme.getClassifications());
418 if (catBag!=null) {
419 tm.setCategoryBag(catBag);
420 }
421
422
423 } catch (Exception ud) {
424 throw new JAXRException("Apache JAXR Impl:", ud);
425 }
426 return tm;
427 }
428
429 public static TModel getTModelFromJAXRConcept(Concept concept)
430 throws JAXRException {
431 TModel tm = objectFactory.createTModel();
432 if (concept == null)
433 return null;
434 try {
435 Key key = concept.getKey();
436 if (key != null && key.getId() != null)
437 tm.setTModelKey(key.getId());
438 Slot sl1 = concept.getSlot("authorizedName");
439 if (sl1 != null && sl1.getName() != null)
440 tm.setAuthorizedName(sl1.getName());
441
442 Slot sl2 = concept.getSlot("operator");
443 if (sl2 != null && sl2.getName() != null)
444 tm.setOperator(sl2.getName());
445
446 InternationalString iname = concept.getName();
447
448 tm.setName(getFirstName(iname));
449
450 InternationalString idesc = concept.getDescription();
451
452 addDescriptions(tm.getDescription(), idesc);
453
454
455 Collection<ExternalLink> externalLinks = concept.getExternalLinks();
456 if(externalLinks != null && externalLinks.size() > 0)
457 {
458 tm.setOverviewDoc(getOverviewDocFromExternalLink((ExternalLink)externalLinks.iterator().next()));
459 }
460
461 IdentifierBag idBag = getIdentifierBagFromExternalIdentifiers(concept.getExternalIdentifiers());
462 if (idBag!=null) {
463 tm.setIdentifierBag(idBag);
464 }
465 CategoryBag catBag = getCategoryBagFromClassifications(concept.getClassifications());
466 if (catBag!=null) {
467 tm.setCategoryBag(catBag);
468 }
469
470 } catch (Exception ud) {
471 throw new JAXRException("Apache JAXR Impl:", ud);
472 }
473 return tm;
474 }
475
476 private static void addDescriptions(List<Description> descripions, InternationalString idesc) throws JAXRException {
477 if (idesc != null) {
478 for (Object o : idesc.getLocalizedStrings()) {
479 LocalizedString locName = (LocalizedString) o;
480 Description desc = objectFactory.createDescription();
481 descripions.add(desc);
482 desc.setValue(locName.getValue());
483 desc.setLang(locName.getLocale().getLanguage());
484 }
485 }
486 }
487
488 private static Name getFirstName(InternationalString iname) throws JAXRException {
489 for (Object o : iname.getLocalizedStrings()) {
490 LocalizedString locName = (LocalizedString) o;
491 Name name = objectFactory.createName();
492 name.setValue(locName.getValue());
493 name.setLang(locName.getLocale().getLanguage());
494 return name;
495 }
496 return null;
497 }
498 private static void addNames(List<Name> names, InternationalString iname) throws JAXRException {
499 for (Object o : iname.getLocalizedStrings()) {
500 LocalizedString locName = (LocalizedString) o;
501 Name name = objectFactory.createName();
502 name.setValue(locName.getValue());
503 name.setLang(locName.getLocale().getLanguage());
504 names.add(name);
505 }
506 }
507
508 public static BusinessEntity getBusinessEntityFromJAXROrg(Organization organization)
509 throws JAXRException {
510 BusinessEntity biz = objectFactory.createBusinessEntity();
511 BusinessServices bss = objectFactory.createBusinessServices();
512 BusinessService[] barr = new BusinessService[0];
513
514 try {
515
516 Key key = organization.getKey();
517 if (key != null && key.getId() != null) {
518 biz.setBusinessKey(key.getId());
519 } else {
520 biz.setBusinessKey("");
521 }
522
523
524 InternationalString iname = organization.getName();
525
526 if (iname != null) {
527 addNames(biz.getName(), iname);
528 }
529
530 InternationalString idesc = organization.getDescription();
531
532 addDescriptions(biz.getDescription(), idesc);
533
534 if (organization.getPrimaryContact() != null &&
535 organization.getPrimaryContact().getPersonName()!= null &&
536 organization.getPrimaryContact().getPersonName().getFullName() != null) {
537
538 biz.setAuthorizedName(organization.getPrimaryContact().getPersonName()
539 .getFullName());
540 }
541
542 Collection<Service> s = organization.getServices();
543 log.debug("?Org has services=" + s.isEmpty());
544
545 barr = new BusinessService[s.size()];
546
547 Iterator<Service> iter = s.iterator();
548 int barrPos = 0;
549 while (iter.hasNext()) {
550 BusinessService bs = ScoutJaxrUddiHelper
551 .getBusinessServiceFromJAXRService((Service) iter
552 .next());
553 barr[barrPos] = bs;
554 barrPos++;
555 }
556
557
558
559
560
561
562
563 Contacts cts = objectFactory.createContacts();
564 Contact[] carr = new Contact[0];
565
566 User primaryContact = organization.getPrimaryContact();
567 Collection<User> users = organization.getUsers();
568
569
570
571
572 int carrSize = 0;
573
574 if (primaryContact != null) {
575 carrSize += 1;
576 }
577
578
579 Iterator<User> it = users.iterator();
580 while (it.hasNext()) {
581 User u = (User) it.next();
582 if (u != primaryContact) {
583 carrSize++;
584 }
585 }
586
587 carr = new Contact[carrSize];
588
589
590
591
592 if (primaryContact != null) {
593 Contact ct = getContactFromJAXRUser(primaryContact);
594 carr[0] = ct;
595 }
596
597 it = users.iterator();
598 int carrPos = 1;
599 while (it.hasNext()) {
600 User u = (User) it.next();
601
602 if (u != primaryContact) {
603 Contact ct = getContactFromJAXRUser(u);
604 carr[carrPos] = ct;
605 carrPos++;
606 }
607 }
608
609 bss.getBusinessService().addAll(Arrays.asList(barr));
610 if (carr.length>0) {
611 cts.getContact().addAll(Arrays.asList(carr));
612 biz.setContacts(cts);
613 }
614 biz.setBusinessServices(bss);
615
616
617 Iterator<ExternalLink> exiter = organization.getExternalLinks().iterator();
618 DiscoveryURLs emptyDUs = null;
619 boolean first = true;
620 while (exiter.hasNext()) {
621 ExternalLink link = (ExternalLink) exiter.next();
622
623 if (first) {
624 emptyDUs = objectFactory.createDiscoveryURLs();
625 biz.setDiscoveryURLs(emptyDUs);
626 first = false;
627 }
628 DiscoveryURL emptyDU = objectFactory.createDiscoveryURL();
629 emptyDUs.getDiscoveryURL().add(emptyDU);
630 emptyDU.setUseType("businessEntityExt");
631
632 if (link.getExternalURI() != null) {
633 emptyDU.setValue(link.getExternalURI());
634 }
635 }
636
637 IdentifierBag idBag = getIdentifierBagFromExternalIdentifiers(organization.getExternalIdentifiers());
638 if (idBag!=null) {
639 biz.setIdentifierBag(idBag);
640 }
641 CategoryBag catBag = getCategoryBagFromClassifications(organization.getClassifications());
642 if (catBag!=null) {
643 biz.setCategoryBag(catBag);
644 }
645
646 } catch (Exception ud) {
647 throw new JAXRException("Apache JAXR Impl:", ud);
648 }
649 return biz;
650 }
651
652
653
654
655
656 public static Contact getContactFromJAXRUser(User user)
657 throws JAXRException {
658 Contact ct = objectFactory.createContact();
659 if (user == null) {
660 return null;
661 }
662
663 Address[] addarr = new Address[0];
664 Phone[] phonearr = new Phone[0];
665 Email[] emailarr = new Email[0];
666 try {
667
668 if (user.getPersonName() != null && user.getPersonName().getFullName() != null) {
669 ct.setPersonName(user.getPersonName().getFullName());
670 }
671
672 if (user.getType() != null) {
673 ct.setUseType(user.getType());
674 }
675
676 Collection<PostalAddress> postc = user.getPostalAddresses();
677
678 addarr = new Address[postc.size()];
679
680 Iterator<PostalAddress> iterator = postc.iterator();
681 int addarrPos = 0;
682 while (iterator.hasNext()) {
683 PostalAddress post = (PostalAddress) iterator.next();
684 addarr[addarrPos] = ScoutJaxrUddiHelper.getAddress(post);
685 addarrPos++;
686 }
687
688 Collection ph = user.getTelephoneNumbers(null);
689
690 phonearr = new Phone[ph.size()];
691
692 Iterator it = ph.iterator();
693 int phonearrPos = 0;
694 while (it.hasNext()) {
695 TelephoneNumber t = (TelephoneNumber) it.next();
696 Phone phone = objectFactory.createPhone();
697 String str = t.getNumber();
698 log.debug("Telephone=" + str);
699
700
701
702 if (str != null) {
703 phone.setValue(str);
704 } else {
705 phone.setValue("");
706 }
707
708 phonearr[phonearrPos] = phone;
709 phonearrPos++;
710 }
711
712
713 Collection ec = user.getEmailAddresses();
714
715 emailarr = new Email[ec.size()];
716
717 Iterator iter = ec.iterator();
718 int emailarrPos = 0;
719 while (iter.hasNext()) {
720 EmailAddress ea = (EmailAddress) iter.next();
721 Email email = objectFactory.createEmail();
722
723 if (ea.getAddress() != null) {
724 email.setValue(ea.getAddress());
725 }
726
727
728 if (ea.getType() != null) {
729 email.setUseType(ea.getType());
730 }
731
732 emailarr[emailarrPos] = email;
733 emailarrPos++;
734 }
735 ct.getAddress().addAll(Arrays.asList(addarr));
736 ct.getPhone().addAll(Arrays.asList(phonearr));
737 ct.getEmail().addAll(Arrays.asList(emailarr));
738 } catch (Exception ud) {
739 throw new JAXRException("Apache JAXR Impl:", ud);
740 }
741 return ct;
742 }
743
744 private static String getToken(String tokenstr) {
745
746 if (tokenstr.equals("NULL"))
747 tokenstr = "";
748 return tokenstr;
749 }
750
751 private static URLType getURLType(String accessuri) {
752 String acc = accessuri.toLowerCase();
753 URLType uri = URLType.OTHER;
754 if (acc.startsWith("http:"))
755 uri = URLType.HTTP;
756 else if (acc.startsWith("https:"))
757 uri = URLType.HTTPS;
758 else if (acc.startsWith("ftp:"))
759 uri = URLType.FTP;
760 else if (acc.startsWith("phone:"))
761 uri = URLType.PHONE;
762
763 return uri;
764 }
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779 public static CategoryBag getCategoryBagFromClassifications(Collection classifications) throws JAXRException {
780 try {
781 if (classifications == null || classifications.size()==0)
782 return null;
783
784
785 CategoryBag cbag = objectFactory.createCategoryBag();
786 Iterator classiter = classifications.iterator();
787 while (classiter.hasNext()) {
788 Classification classification = (Classification) classiter.next();
789 if (classification != null ) {
790 KeyedReference keyr = objectFactory.createKeyedReference();
791 cbag.getKeyedReference().add(keyr);
792
793 InternationalStringImpl iname = null;
794 String value = null;
795 ClassificationScheme scheme = classification.getClassificationScheme();
796 if (scheme==null || (classification.isExternal() && classification.getConcept()==null)) {
797
798
799
800
801
802
803
804 keyr.setTModelKey(UDDI_ORG_TYPES);
805 keyr.setKeyValue("specification");
806 } else {
807 if (classification.isExternal()) {
808 iname = (InternationalStringImpl) ((RegistryObject) classification).getName();
809 value = classification.getValue();
810 } else {
811 Concept concept = classification.getConcept();
812 if (concept != null) {
813 iname = (InternationalStringImpl) ((RegistryObject) concept).getName();
814 value = concept.getValue();
815 scheme = concept.getClassificationScheme();
816 }
817 }
818
819 String name = iname.getValue();
820 if (name != null)
821 keyr.setKeyName(name);
822
823 if (value != null)
824 keyr.setKeyValue(value);
825
826 if (scheme != null) {
827 Key key = scheme.getKey();
828 if (key != null && key.getId() != null)
829 keyr.setTModelKey(key.getId());
830 }
831 }
832 }
833 }
834 return cbag;
835 } catch (Exception ud) {
836 throw new JAXRException("Apache JAXR Impl:", ud);
837 }
838 }
839
840 public static TModelBag getTModelBagFromSpecifications(Collection specifications) throws JAXRException {
841 try {
842 if (specifications == null || specifications.size()==0)
843 return null;
844
845
846 TModelBag tbag = objectFactory.createTModelBag();
847 Iterator speciter = specifications.iterator();
848 while (speciter.hasNext()) {
849 RegistryObject registryobject = (RegistryObject) speciter.next();
850 if (registryobject instanceof SpecificationLink) {
851 SpecificationLink specificationlink = (SpecificationLink) registryobject;
852 if (specificationlink.getSpecificationObject() != null) {
853 RegistryObject ro = specificationlink.getSpecificationObject();
854 if (ro.getKey() != null) {
855 Key key = ro.getKey();
856 tbag.getTModelKey().add(key.toString());
857 }
858 }
859 } else {
860 log.info("ebXML case - the RegistryObject is an ExtrinsicObject, Not implemented");
861 }
862 }
863 return tbag;
864 } catch (Exception ud) {
865 throw new JAXRException("Apache JAXR Impl:", ud);
866 }
867 }
868
869
870
871
872
873
874
875
876 public static IdentifierBag getIdentifierBagFromExternalIdentifiers(Collection identifiers) throws JAXRException {
877 try {
878 if (identifiers == null || identifiers.size()==0)
879 return null;
880
881
882 IdentifierBag ibag = objectFactory.createIdentifierBag();
883 Iterator iditer = identifiers.iterator();
884 while (iditer.hasNext()) {
885 ExternalIdentifier extid = (ExternalIdentifier) iditer.next();
886 if (extid != null ) {
887 KeyedReference keyr = objectFactory.createKeyedReference();
888 ibag.getKeyedReference().add(keyr);
889
890 InternationalStringImpl iname = (InternationalStringImpl) ((RegistryObject) extid).getName();
891 String value = extid.getValue();
892 ClassificationScheme scheme = extid.getIdentificationScheme();
893
894 String name = iname.getValue();
895 if (name != null)
896 keyr.setKeyName(name);
897
898 if (value != null)
899 keyr.setKeyValue(value);
900
901 if (scheme != null) {
902 Key key = scheme.getKey();
903 if (key != null && key.getId() != null)
904 keyr.setTModelKey(key.getId());
905 }
906 }
907 }
908 return ibag;
909 } catch (Exception ud) {
910 throw new JAXRException("Apache JAXR Impl:", ud);
911 }
912 }
913
914 private static OverviewDoc getOverviewDocFromExternalLink(ExternalLink link)
915 throws JAXRException
916 {
917 OverviewDoc od = objectFactory.createOverviewDoc();
918 String url = link.getExternalURI();
919 if(url != null)
920 od.setOverviewURL(url);
921 InternationalString extDesc = link.getDescription();
922 if(extDesc != null) {
923 Description description = objectFactory.createDescription();
924 od.getDescription().add(description);
925 description.setValue(extDesc.getValue());
926 }
927 return od;
928 }
929
930 private static BindingTemplates getBindingTemplates(Collection serviceBindings)
931 throws JAXRException {
932 BindingTemplates bt = null;
933 if(serviceBindings != null && serviceBindings.size() > 0) {
934 bt = objectFactory.createBindingTemplates();
935 Iterator iter = serviceBindings.iterator();
936 int currLoc = 0;
937 BindingTemplate[] bindingTemplateArray = new BindingTemplate[serviceBindings.size()];
938 while(iter.hasNext()) {
939 ServiceBinding sb = (ServiceBinding)iter.next();
940 bindingTemplateArray[currLoc] = getBindingTemplateFromJAXRSB(sb);
941 currLoc++;
942 }
943 if (bindingTemplateArray != null) {
944 bt.getBindingTemplate().addAll(Arrays.asList(bindingTemplateArray));
945 }
946 }
947 return bt;
948 }
949 }