001: /**
002: *
003: * Copyright 2004 The Apache Software Foundation
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.ws.scout.util;
017:
018: import java.util.Collection;
019: import java.util.Iterator;
020: import java.util.StringTokenizer;
021:
022: import javax.xml.registry.JAXRException;
023: import javax.xml.registry.infomodel.Association;
024: import javax.xml.registry.infomodel.Classification;
025: import javax.xml.registry.infomodel.ClassificationScheme;
026: import javax.xml.registry.infomodel.Concept;
027: import javax.xml.registry.infomodel.EmailAddress;
028: import javax.xml.registry.infomodel.ExternalIdentifier;
029: import javax.xml.registry.infomodel.ExternalLink;
030: import javax.xml.registry.infomodel.InternationalString;
031: import javax.xml.registry.infomodel.Key;
032: import javax.xml.registry.infomodel.LocalizedString;
033: import javax.xml.registry.infomodel.Organization;
034: import javax.xml.registry.infomodel.PostalAddress;
035: import javax.xml.registry.infomodel.RegistryObject;
036: import javax.xml.registry.infomodel.Service;
037: import javax.xml.registry.infomodel.ServiceBinding;
038: import javax.xml.registry.infomodel.Slot;
039: import javax.xml.registry.infomodel.SpecificationLink;
040: import javax.xml.registry.infomodel.TelephoneNumber;
041: import javax.xml.registry.infomodel.User;
042:
043: import org.apache.commons.logging.Log;
044: import org.apache.commons.logging.LogFactory;
045: import org.apache.ws.scout.registry.infomodel.InternationalStringImpl;
046: import org.apache.ws.scout.uddi.AccessPoint;
047: import org.apache.ws.scout.uddi.Address;
048: import org.apache.ws.scout.uddi.AddressLine;
049: import org.apache.ws.scout.uddi.BindingTemplate;
050: import org.apache.ws.scout.uddi.BindingTemplates;
051: import org.apache.ws.scout.uddi.BusinessEntity;
052: import org.apache.ws.scout.uddi.BusinessService;
053: import org.apache.ws.scout.uddi.BusinessServices;
054: import org.apache.ws.scout.uddi.CategoryBag;
055: import org.apache.ws.scout.uddi.Contact;
056: import org.apache.ws.scout.uddi.Contacts;
057: import org.apache.ws.scout.uddi.Description;
058: import org.apache.ws.scout.uddi.DiscoveryURL;
059: import org.apache.ws.scout.uddi.DiscoveryURLs;
060: import org.apache.ws.scout.uddi.Email;
061: import org.apache.ws.scout.uddi.HostingRedirector;
062: import org.apache.ws.scout.uddi.IdentifierBag;
063: import org.apache.ws.scout.uddi.InstanceDetails;
064: import org.apache.ws.scout.uddi.KeyedReference;
065: import org.apache.ws.scout.uddi.Name;
066: import org.apache.ws.scout.uddi.OverviewDoc;
067: import org.apache.ws.scout.uddi.Phone;
068: import org.apache.ws.scout.uddi.PublisherAssertion;
069: import org.apache.ws.scout.uddi.TModel;
070: import org.apache.ws.scout.uddi.TModelInstanceDetails;
071: import org.apache.ws.scout.uddi.TModelInstanceInfo;
072: import org.apache.ws.scout.uddi.URLType;
073: import org.apache.xmlbeans.XmlObject;
074:
075: /**
076: * Helper class that does Jaxr->UDDI Mapping
077: *
078: * @author <a href="mailto:anil@apache.org">Anil Saldhana</a>
079: * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
080: * @author <a href="mailto:kstam@apache.org">Kurt T Stam</a>
081: */
082: public class ScoutJaxrUddiHelper {
083: private static final String UDDI_ORG_TYPES = "uuid:C1ACF26D-9672-4404-9D70-39B756E62AB4";
084: private static Log log = LogFactory
085: .getLog(ScoutJaxrUddiHelper.class);
086:
087: /**
088: * Get UDDI Address given JAXR Postal Address
089: */
090: public static Address getAddress(PostalAddress post)
091: throws JAXRException {
092: Address address = Address.Factory.newInstance();
093:
094: AddressLine[] addarr = new AddressLine[6];
095:
096: String stnum = post.getStreetNumber();
097: String st = post.getStreet();
098: String city = post.getCity();
099: String country = post.getCountry();
100: String code = post.getPostalCode();
101: String state = post.getStateOrProvince();
102:
103: AddressLine stnumAL = AddressLine.Factory.newInstance();
104: stnumAL.setKeyName("STREET_NUMBER");
105: if (stnum != null) {
106: stnumAL.setKeyValue(stnum);
107: }
108:
109: AddressLine stAL = AddressLine.Factory.newInstance();
110: stAL.setKeyName("STREET");
111: if (st != null) {
112: stAL.setKeyValue(st);
113: }
114:
115: AddressLine cityAL = AddressLine.Factory.newInstance();
116: cityAL.setKeyName("CITY");
117: if (city != null) {
118: cityAL.setKeyValue(city);
119: }
120:
121: AddressLine countryAL = AddressLine.Factory.newInstance();
122: countryAL.setKeyName("COUNTRY");
123: if (country != null) {
124: countryAL.setKeyValue(country);
125: }
126:
127: AddressLine codeAL = AddressLine.Factory.newInstance();
128: codeAL.setKeyName("POSTALCODE");
129: if (code != null) {
130: codeAL.setKeyValue(code);
131: }
132:
133: AddressLine stateAL = AddressLine.Factory.newInstance();
134: stateAL.setKeyName("STATE");
135: if (state != null) {
136: stateAL.setKeyValue(state);
137: }
138:
139: // Add the AddressLine to vector
140: addarr[0] = stnumAL;
141: addarr[1] = stAL;
142: addarr[2] = cityAL;
143: addarr[3] = countryAL;
144: addarr[4] = codeAL;
145: addarr[5] = stateAL;
146:
147: address.setAddressLineArray(addarr);
148:
149: return address;
150: }
151:
152: public static BindingTemplate getBindingTemplateFromJAXRSB(
153: ServiceBinding serve) throws JAXRException {
154: BindingTemplate bt = BindingTemplate.Factory.newInstance();
155: if (serve.getKey() != null && serve.getKey().getId() != null)
156: bt.setBindingKey(serve.getKey().getId());
157: try {
158: // Set Access URI
159: String accessuri = serve.getAccessURI();
160: if (accessuri != null) {
161: AccessPoint ap = AccessPoint.Factory.newInstance();
162: ap.setURLType(getURLType(accessuri));
163: ap.setStringValue(accessuri);
164: bt.setAccessPoint(ap);
165: }
166: ServiceBinding sb = serve.getTargetBinding();
167: if (sb != null) {
168: HostingRedirector red = HostingRedirector.Factory
169: .newInstance();
170: Key key = sb.getKey();
171: if (key != null && key.getId() != null) {
172: red.setBindingKey(key.getId());
173: } else {
174: red.setBindingKey("");
175: }
176: bt.setHostingRedirector(red);
177: }
178: // TODO:Need to look further at the mapping b/w BindingTemplate and
179: // Jaxr ServiceBinding
180:
181: // Get Service information
182: Service svc = serve.getService();
183: if (svc != null && svc.getKey() != null
184: && svc.getKey().getId() != null) {
185: bt.setServiceKey(svc.getKey().getId());
186: }
187:
188: InternationalString idesc = ((RegistryObject) serve)
189: .getDescription();
190:
191: if (idesc != null) {
192: for (LocalizedString locName : idesc
193: .getLocalizedStrings()) {
194: Description desc = bt.addNewDescription();
195: desc.setStringValue(locName.getValue());
196: desc.setLang(locName.getLocale().getLanguage());
197: }
198: }
199:
200: // SpecificationLink
201: Collection slcol = serve.getSpecificationLinks();
202: TModelInstanceDetails tid = TModelInstanceDetails.Factory
203: .newInstance();
204: if (slcol != null && !slcol.isEmpty()) {
205: Iterator iter = slcol.iterator();
206: while (iter.hasNext()) {
207: SpecificationLink slink = (SpecificationLink) iter
208: .next();
209:
210: TModelInstanceInfo emptyTInfo = tid
211: .addNewTModelInstanceInfo();
212:
213: RegistryObject specificationObject = slink
214: .getSpecificationObject();
215: if (specificationObject.getKey() != null
216: && specificationObject.getKey().getId() != null) {
217: emptyTInfo.setTModelKey(specificationObject
218: .getKey().getId());
219: if (specificationObject.getDescription() != null) {
220: for (LocalizedString locDesc : specificationObject
221: .getDescription()
222: .getLocalizedStrings()) {
223: Description description = emptyTInfo
224: .addNewDescription();
225: description.setStringValue(locDesc
226: .getValue());
227: description.setLang(locDesc.getLocale()
228: .getLanguage());
229: }
230: }
231: Collection<ExternalLink> externalLinks = slink
232: .getExternalLinks();
233: if (externalLinks != null
234: && externalLinks.size() > 0) {
235: for (ExternalLink link : externalLinks) {
236: InstanceDetails ids = emptyTInfo
237: .addNewInstanceDetails();
238: if (link.getDescription() != null) {
239: Description description = ids
240: .addNewDescription();
241: description.setStringValue(link
242: .getDescription()
243: .getValue());
244: }
245: if (link.getExternalURI() != null) {
246: OverviewDoc overviewDoc = ids
247: .addNewOverviewDoc();
248: overviewDoc.setOverviewURL(link
249: .getExternalURI());
250: }
251: }
252: }
253: }
254: }
255: bt.setTModelInstanceDetails(tid);
256: }
257: log.debug("BindingTemplate=" + bt.toString());
258: } catch (Exception ud) {
259: throw new JAXRException("Apache JAXR Impl:", ud);
260: }
261: return bt;
262: }
263:
264: public static PublisherAssertion getPubAssertionFromJAXRAssociation(
265: Association assc) throws JAXRException {
266: PublisherAssertion pa = PublisherAssertion.Factory
267: .newInstance();
268: try {
269: if (assc.getSourceObject().getKey() != null
270: && assc.getSourceObject().getKey().getId() != null) {
271: pa.setFromKey(assc.getSourceObject().getKey().getId());
272: }
273:
274: if (assc.getTargetObject().getKey() != null
275: && assc.getTargetObject().getKey().getId() != null) {
276: pa.setToKey(assc.getTargetObject().getKey().getId());
277: }
278: Concept c = assc.getAssociationType();
279: String v = c.getValue();
280: KeyedReference kr = KeyedReference.Factory.newInstance();
281: Key key = c.getKey();
282: if (key == null) {
283: // TODO:Need to check this. If the concept is a predefined
284: // enumeration, the key can be the parent classification scheme
285: key = c.getClassificationScheme().getKey();
286: }
287: if (key == null || key.getId() == null) {
288: // The parent classification scheme may not always contain the
289: // key. It is okay if it doesn't, since the UDDI v2 spec allows
290: // TModelKey to be absent.
291:
292: // TODO: This setting to "" should not be needed at all.
293: // However, a bug in jUDDI needs it to be there. See:
294: // http://issues.apache.org/jira/browse/JUDDI-78
295: //kr.setTModelKey("");
296: } else {
297: kr.setTModelKey(key.getId());
298: }
299: kr.setKeyName("Concept");
300:
301: if (v != null) {
302: kr.setKeyValue(v);
303: }
304:
305: pa.setKeyedReference(kr);
306: } catch (Exception ud) {
307: throw new JAXRException("Apache JAXR Impl:", ud);
308: }
309: return pa;
310: }
311:
312: public static PublisherAssertion getPubAssertionFromJAXRAssociationKey(
313: String key) throws JAXRException {
314: PublisherAssertion pa = PublisherAssertion.Factory
315: .newInstance();
316: try {
317: StringTokenizer token = new StringTokenizer(key, ":");
318: if (token.hasMoreTokens()) {
319: pa.setFromKey(getToken(token.nextToken()));
320: pa.setToKey(getToken(token.nextToken()));
321: KeyedReference kr = KeyedReference.Factory
322: .newInstance();
323: // Sometimes the Key is UUID:something
324: String str = getToken(token.nextToken());
325: if ("UUID".equals(str))
326: str += ":" + getToken(token.nextToken());
327: kr.setTModelKey(str);
328: kr.setKeyName(getToken(token.nextToken()));
329: kr.setKeyValue(getToken(token.nextToken()));
330: pa.setKeyedReference(kr);
331: }
332:
333: } catch (Exception ud) {
334: throw new JAXRException("Apache JAXR Impl:", ud);
335: }
336: return pa;
337: }
338:
339: public static BusinessService getBusinessServiceFromJAXRService(
340: Service serve) throws JAXRException {
341: BusinessService bs = BusinessService.Factory.newInstance();
342: try {
343: InternationalString iname = ((RegistryObject) serve)
344: .getName();
345:
346: for (LocalizedString locName : iname.getLocalizedStrings()) {
347: Name name = bs.addNewName();
348: name.setStringValue(locName.getValue());
349: name.setLang(locName.getLocale().getLanguage());
350: }
351:
352: InternationalString idesc = ((RegistryObject) serve)
353: .getDescription();
354:
355: if (idesc != null) {
356: for (LocalizedString locName : idesc
357: .getLocalizedStrings()) {
358: Description desc = bs.addNewDescription();
359: desc.setStringValue(locName.getValue());
360: desc.setLang(locName.getLocale().getLanguage());
361: }
362: }
363:
364: Organization o = serve.getProvidingOrganization();
365:
366: /*
367: * there may not always be a key...
368: */
369: if (o != null) {
370: Key k = o.getKey();
371:
372: if (k != null && k.getId() != null) {
373: bs.setBusinessKey(k.getId());
374: }
375:
376: } else {
377: /*
378: * gmj - I *think* this is the right thing to do
379: */
380: throw new JAXRException(
381: "Service has no associated organization");
382: }
383:
384: if (serve.getKey() != null
385: && serve.getKey().getId() != null) {
386: bs.setServiceKey(serve.getKey().getId());
387: } else {
388: bs.setServiceKey("");
389: }
390:
391: CategoryBag catBag = getCategoryBagFromClassifications(serve
392: .getClassifications());
393: if (catBag != null) {
394: bs.setCategoryBag(catBag);
395: }
396:
397: //Add the ServiceBinding information
398: BindingTemplates bt = getBindingTemplates(serve
399: .getServiceBindings());
400: if (bt != null) {
401: bs.setBindingTemplates(bt);
402: }
403:
404: log.debug("BusinessService=" + bs.toString());
405: } catch (Exception ud) {
406: throw new JAXRException("Apache JAXR Impl:", ud);
407: }
408: return bs;
409: }
410:
411: public static TModel getTModelFromJAXRClassificationScheme(
412: ClassificationScheme scheme) throws JAXRException {
413: TModel tm = TModel.Factory.newInstance();
414: try {
415: /*
416: * a fresh scheme might not have a key
417: */
418:
419: Key k = scheme.getKey();
420:
421: if (k != null && k.getId() != null) {
422: tm.setTModelKey(k.getId());
423:
424: }
425:
426: /*
427: * There's no reason to believe these are here either
428: */
429:
430: Slot s = scheme.getSlot("authorizedName");
431:
432: if (s != null && s.getName() != null) {
433: tm.setAuthorizedName(s.getName());
434: }
435:
436: s = scheme.getSlot("operator");
437:
438: if (s != null && s.getName() != null) {
439: tm.setOperator(s.getName());
440: }
441:
442: InternationalString iname = ((RegistryObject) scheme)
443: .getName();
444:
445: for (LocalizedString locName : iname.getLocalizedStrings()) {
446: Name name = tm.addNewName();
447: name.setStringValue(locName.getValue());
448: name.setLang(locName.getLocale().getLanguage());
449: }
450:
451: InternationalString idesc = ((RegistryObject) scheme)
452: .getDescription();
453:
454: if (idesc != null) {
455: for (LocalizedString locName : idesc
456: .getLocalizedStrings()) {
457: Description desc = tm.addNewDescription();
458: desc.setStringValue(locName.getValue());
459: desc.setLang(locName.getLocale().getLanguage());
460: }
461: }
462:
463: IdentifierBag idBag = getIdentifierBagFromExternalIdentifiers(scheme
464: .getExternalIdentifiers());
465: if (idBag != null) {
466: tm.setIdentifierBag(idBag);
467: }
468: CategoryBag catBag = getCategoryBagFromClassifications(scheme
469: .getClassifications());
470: if (catBag != null) {
471: tm.setCategoryBag(catBag);
472: }
473:
474: // ToDO: overviewDoc
475: } catch (Exception ud) {
476: throw new JAXRException("Apache JAXR Impl:", ud);
477: }
478: return tm;
479: }
480:
481: public static TModel getTModelFromJAXRConcept(Concept scheme)
482: throws JAXRException {
483: TModel tm = TModel.Factory.newInstance();
484: if (scheme == null)
485: return null;
486: try {
487: Key key = scheme.getKey();
488: if (key != null && key.getId() != null)
489: tm.setTModelKey(key.getId());
490: Slot sl1 = scheme.getSlot("authorizedName");
491: if (sl1 != null && sl1.getName() != null)
492: tm.setAuthorizedName(sl1.getName());
493:
494: Slot sl2 = scheme.getSlot("operator");
495: if (sl2 != null && sl2.getName() != null)
496: tm.setOperator(sl2.getName());
497:
498: InternationalString iname = ((RegistryObject) scheme)
499: .getName();
500:
501: for (LocalizedString locName : iname.getLocalizedStrings()) {
502: Name name = tm.addNewName();
503: name.setStringValue(locName.getValue());
504: name.setLang(locName.getLocale().getLanguage());
505: }
506:
507: InternationalString idesc = ((RegistryObject) scheme)
508: .getDescription();
509:
510: if (idesc != null) {
511: for (LocalizedString locName : idesc
512: .getLocalizedStrings()) {
513: Description desc = tm.addNewDescription();
514: desc.setStringValue(locName.getValue());
515: desc.setLang(locName.getLocale().getLanguage());
516: }
517: }
518: // External Links
519: Collection externalLinks = scheme.getExternalLinks();
520: if (externalLinks != null && externalLinks.size() > 0) {
521: tm
522: .setOverviewDoc(getOverviewDocFromExternalLink((ExternalLink) externalLinks
523: .iterator().next()));
524: }
525:
526: IdentifierBag idBag = getIdentifierBagFromExternalIdentifiers(scheme
527: .getExternalIdentifiers());
528: if (idBag != null) {
529: tm.setIdentifierBag(idBag);
530: }
531: CategoryBag catBag = getCategoryBagFromClassifications(scheme
532: .getClassifications());
533: if (catBag != null) {
534: tm.setCategoryBag(catBag);
535: }
536:
537: } catch (Exception ud) {
538: throw new JAXRException("Apache JAXR Impl:", ud);
539: }
540: return tm;
541: }
542:
543: public static BusinessEntity getBusinessEntityFromJAXROrg(
544: Organization org) throws JAXRException {
545: BusinessEntity biz = BusinessEntity.Factory.newInstance();
546: BusinessServices bss = BusinessServices.Factory.newInstance();
547: BusinessService[] barr = new BusinessService[0];
548:
549: try {
550: // It may just be an update
551: Key key = org.getKey();
552: if (key != null && key.getId() != null) {
553: biz.setBusinessKey(key.getId());
554: } else {
555: biz.setBusinessKey("");
556: }
557: // Lets get the Organization attributes at the top level
558:
559: InternationalString iname = org.getName();
560:
561: if (iname != null) {
562: for (LocalizedString locName : iname
563: .getLocalizedStrings()) {
564: Name name = biz.addNewName();
565: name.setStringValue(locName.getValue());
566: name.setLang(locName.getLocale().getLanguage());
567: }
568: }
569:
570: InternationalString idesc = org.getDescription();
571:
572: if (idesc != null) {
573: for (LocalizedString locName : idesc
574: .getLocalizedStrings()) {
575: Description desc = biz.addNewDescription();
576: desc.setStringValue(locName.getValue());
577: desc.setLang(locName.getLocale().getLanguage());
578: }
579: }
580:
581: if (org.getPrimaryContact() != null
582: && org.getPrimaryContact().getPersonName() != null
583: && org.getPrimaryContact().getPersonName()
584: .getFullName() != null) {
585:
586: biz.setAuthorizedName(org.getPrimaryContact()
587: .getPersonName().getFullName());
588: }
589:
590: Collection s = org.getServices();
591: log.debug("?Org has services=" + s.isEmpty());
592:
593: barr = new BusinessService[s.size()];
594:
595: Iterator iter = s.iterator();
596: int barrPos = 0;
597: while (iter.hasNext()) {
598: BusinessService bs = ScoutJaxrUddiHelper
599: .getBusinessServiceFromJAXRService((Service) iter
600: .next());
601: barr[barrPos] = bs;
602: barrPos++;
603: }
604:
605: /*
606: * map users : JAXR has concept of 'primary contact', which is a
607: * special designation for one of the users, and D6.1 seems to say
608: * that the first UDDI user is the primary contact
609: */
610:
611: Contacts cts = Contacts.Factory.newInstance();
612: Contact[] carr = new Contact[0];
613:
614: User primaryContact = org.getPrimaryContact();
615: Collection users = org.getUsers();
616:
617: // Expand array to necessary size only (xmlbeans does not like
618: // null items in cases like this)
619:
620: int carrSize = 0;
621:
622: if (primaryContact != null) {
623: carrSize += 1;
624: }
625:
626: // TODO: Clean this up and make it more efficient
627: Iterator it = users.iterator();
628: while (it.hasNext()) {
629: User u = (User) it.next();
630: if (u != primaryContact) {
631: carrSize++;
632: }
633: }
634:
635: carr = new Contact[carrSize];
636:
637: /*
638: * first do primary, and then filter that out in the loop
639: */
640: if (primaryContact != null) {
641: Contact ct = getContactFromJAXRUser(primaryContact);
642: carr[0] = ct;
643: }
644:
645: it = users.iterator();
646: int carrPos = 1;
647: while (it.hasNext()) {
648: User u = (User) it.next();
649:
650: if (u != primaryContact) {
651: Contact ct = getContactFromJAXRUser(u);
652: carr[carrPos] = ct;
653: carrPos++;
654: }
655: }
656:
657: bss.setBusinessServiceArray(barr);
658: if (carr.length > 0) {
659: cts.setContactArray(carr);
660: biz.setContacts(cts);
661: }
662: biz.setBusinessServices(bss);
663:
664: // External Links
665: Iterator exiter = org.getExternalLinks().iterator();
666: DiscoveryURLs emptyDUs = null;
667: boolean first = true;
668: while (exiter.hasNext()) {
669: ExternalLink link = (ExternalLink) exiter.next();
670: /** Note: jUDDI adds its own discoverURL as the businessEntity* */
671: if (first) {
672: emptyDUs = biz.addNewDiscoveryURLs();
673: first = false;
674: }
675: DiscoveryURL emptyDU = emptyDUs.addNewDiscoveryURL();
676: emptyDU.setUseType("businessEntityExt");
677:
678: if (link.getExternalURI() != null) {
679: emptyDU.setStringValue(link.getExternalURI());
680: }
681: }
682:
683: IdentifierBag idBag = getIdentifierBagFromExternalIdentifiers(org
684: .getExternalIdentifiers());
685: if (idBag != null) {
686: biz.setIdentifierBag(idBag);
687: }
688: CategoryBag catBag = getCategoryBagFromClassifications(org
689: .getClassifications());
690: if (catBag != null) {
691: biz.setCategoryBag(catBag);
692: }
693:
694: } catch (Exception ud) {
695: throw new JAXRException("Apache JAXR Impl:", ud);
696: }
697: return biz;
698: }
699:
700: /**
701: *
702: * Convert JAXR User Object to UDDI Contact
703: */
704: public static Contact getContactFromJAXRUser(User user)
705: throws JAXRException {
706: Contact ct = Contact.Factory.newInstance();
707:
708: if (user == null) {
709: return null;
710: }
711:
712: Address[] addarr = new Address[0];
713: Phone[] phonearr = new Phone[0];
714: Email[] emailarr = new Email[0];
715: try {
716:
717: if (user.getPersonName() != null
718: && user.getPersonName().getFullName() != null) {
719: ct.setPersonName(user.getPersonName().getFullName());
720: }
721:
722: if (user.getType() != null) {
723: ct.setUseType(user.getType());
724: }
725: // Postal Address
726: Collection postc = user.getPostalAddresses();
727:
728: addarr = new Address[postc.size()];
729:
730: Iterator iterator = postc.iterator();
731: int addarrPos = 0;
732: while (iterator.hasNext()) {
733: PostalAddress post = (PostalAddress) iterator.next();
734: addarr[addarrPos] = ScoutJaxrUddiHelper
735: .getAddress(post);
736: addarrPos++;
737: }
738: // Phone Numbers
739: Collection ph = user.getTelephoneNumbers(null);
740:
741: phonearr = new Phone[ph.size()];
742:
743: Iterator it = ph.iterator();
744: int phonearrPos = 0;
745: while (it.hasNext()) {
746: TelephoneNumber t = (TelephoneNumber) it.next();
747: Phone phone = Phone.Factory.newInstance();
748: String str = t.getNumber();
749: log.debug("Telephone=" + str);
750:
751: // FIXME: If phone number is null, should the phone
752: // not be set at all, or set to empty string?
753: if (str != null) {
754: phone.setStringValue(str);
755: } else {
756: phone.setStringValue("");
757: }
758:
759: phonearr[phonearrPos] = phone;
760: phonearrPos++;
761: }
762:
763: // Email Addresses
764: Collection ec = user.getEmailAddresses();
765:
766: emailarr = new Email[ec.size()];
767:
768: Iterator iter = ec.iterator();
769: int emailarrPos = 0;
770: while (iter.hasNext()) {
771: EmailAddress ea = (EmailAddress) iter.next();
772: Email email = Email.Factory.newInstance();
773:
774: if (ea.getAddress() != null) {
775: email.setStringValue(ea.getAddress());
776: }
777: // email.setText( ea.getAddress() );
778:
779: if (ea.getType() != null) {
780: email.setUseType(ea.getType());
781: }
782:
783: emailarr[emailarrPos] = email;
784: emailarrPos++;
785: }
786: ct.setAddressArray(addarr);
787: ct.setPhoneArray(phonearr);
788: ct.setEmailArray(emailarr);
789: } catch (Exception ud) {
790: throw new JAXRException("Apache JAXR Impl:", ud);
791: }
792: return ct;
793: }
794:
795: private static String getToken(String tokenstr) {
796: // Token can have the value NULL which need to be converted into null
797: if (tokenstr.equals("NULL"))
798: tokenstr = "";
799: return tokenstr;
800: }
801:
802: private static URLType.Enum getURLType(String accessuri) {
803: String acc = accessuri.toLowerCase();
804: URLType.Enum uri = URLType.OTHER;
805: if (acc.startsWith("http:"))
806: uri = URLType.HTTP;
807: else if (acc.startsWith("https:"))
808: uri = URLType.HTTPS;
809: else if (acc.startsWith("ftp:"))
810: uri = URLType.FTP;
811: else if (acc.startsWith("phone:"))
812: uri = URLType.PHONE;// TODO:Handle this better
813:
814: return uri;
815: }
816:
817: /**
818: * According to JAXR Javadoc, there are two types of classification, internal and external and they use the Classification, Concept,
819: * and ClassificationScheme objects. It seems the only difference between internal and external (as related to UDDI) is that the
820: * name/value pair of the categorization is held in the Concept for internal classifications and the Classification for external (bypassing
821: * the Concept entirely).
822: *
823: * The translation to UDDI is simple. Relevant objects have a category bag which contains a bunch of KeyedReferences (name/value pairs).
824: * These KeyedReferences optionally refer to a tModel that identifies the type of category (translates to the ClassificationScheme key). If
825: * this is set and the tModel doesn't exist in the UDDI registry, then an invalid key error will occur when trying to save the object.
826: *
827: * @param regObj
828: * @param destinationObj
829: * @throws JAXRException
830: */
831: public static CategoryBag getCategoryBagFromClassifications(
832: Collection classifications) throws JAXRException {
833: try {
834: if (classifications == null || classifications.size() == 0)
835: return null;
836:
837: // Classifications
838: CategoryBag cbag = (CategoryBag) (XmlObject.Factory
839: .newInstance()).changeType(CategoryBag.type);
840: Iterator classiter = classifications.iterator();
841: while (classiter.hasNext()) {
842: Classification classification = (Classification) classiter
843: .next();
844: if (classification != null) {
845: KeyedReference keyr = cbag.addNewKeyedReference();
846:
847: InternationalStringImpl iname = null;
848: String value = null;
849: ClassificationScheme scheme = classification
850: .getClassificationScheme();
851: if (scheme == null
852: || (classification.isExternal() && classification
853: .getConcept() == null)) {
854: /*
855: * JAXR 1.0 Specification: Section D6.4.4
856: * Specification related tModels mapped from Concept may be automatically
857: * categorized by the well-known uddi-org:types taxonomy in UDDI (with
858: * tModelKey uuid:C1ACF26D-9672-4404-9D70-39B756E62AB4) as follows:
859: * The keyed reference is assigned a taxonomy value of specification.
860: */
861: keyr.setTModelKey(UDDI_ORG_TYPES);
862: keyr.setKeyValue("specification");
863: } else {
864: if (classification.isExternal()) {
865: iname = (InternationalStringImpl) ((RegistryObject) classification)
866: .getName();
867: value = classification.getValue();
868: } else {
869: Concept concept = classification
870: .getConcept();
871: if (concept != null) {
872: iname = (InternationalStringImpl) ((RegistryObject) concept)
873: .getName();
874: value = concept.getValue();
875: scheme = concept
876: .getClassificationScheme();
877: }
878: }
879:
880: String name = iname.getValue();
881: if (name != null)
882: keyr.setKeyName(name);
883:
884: if (value != null)
885: keyr.setKeyValue(value);
886:
887: if (scheme != null) {
888: Key key = scheme.getKey();
889: if (key != null && key.getId() != null)
890: keyr.setTModelKey(key.getId());
891: }
892: }
893: }
894: }
895: return cbag;
896: } catch (Exception ud) {
897: throw new JAXRException("Apache JAXR Impl:", ud);
898: }
899: }
900:
901: /**
902: * Adds the objects identifiers from JAXR's external identifier collection
903: *
904: * @param identifiers
905: * @param ibag
906: * @throws JAXRException
907: */
908: public static IdentifierBag getIdentifierBagFromExternalIdentifiers(
909: Collection identifiers) throws JAXRException {
910: try {
911: if (identifiers == null || identifiers.size() == 0)
912: return null;
913:
914: // Identifiers
915: IdentifierBag ibag = (IdentifierBag) (XmlObject.Factory
916: .newInstance()).changeType(IdentifierBag.type);
917: Iterator iditer = identifiers.iterator();
918: while (iditer.hasNext()) {
919: ExternalIdentifier extid = (ExternalIdentifier) iditer
920: .next();
921: if (extid != null) {
922: KeyedReference keyr = ibag.addNewKeyedReference();
923:
924: InternationalStringImpl iname = (InternationalStringImpl) ((RegistryObject) extid)
925: .getName();
926: String value = extid.getValue();
927: ClassificationScheme scheme = extid
928: .getIdentificationScheme();
929:
930: String name = iname.getValue();
931: if (name != null)
932: keyr.setKeyName(name);
933:
934: if (value != null)
935: keyr.setKeyValue(value);
936:
937: if (scheme != null) {
938: Key key = scheme.getKey();
939: if (key != null && key.getId() != null)
940: keyr.setTModelKey(key.getId());
941: }
942: }
943: }
944: return ibag;
945: } catch (Exception ud) {
946: throw new JAXRException("Apache JAXR Impl:", ud);
947: }
948: }
949:
950: private static OverviewDoc getOverviewDocFromExternalLink(
951: ExternalLink link) throws JAXRException {
952: OverviewDoc od = (OverviewDoc) (XmlObject.Factory.newInstance())
953: .changeType(OverviewDoc.type);
954: String url = link.getExternalURI();
955: if (url != null)
956: od.setOverviewURL(url);
957: InternationalString extDesc = link.getDescription();
958: if (extDesc != null) {
959: Description description = od.addNewDescription();
960: description.setStringValue(extDesc.getValue());
961: }
962: return od;
963: }
964:
965: private static BindingTemplates getBindingTemplates(
966: Collection serviceBindings) throws JAXRException {
967: BindingTemplates bt = null;
968: if (serviceBindings != null && serviceBindings.size() > 0) {
969: bt = BindingTemplates.Factory.newInstance();
970: Iterator iter = serviceBindings.iterator();
971: int currLoc = 0;
972: BindingTemplate[] bindingTemplateArray = new BindingTemplate[serviceBindings
973: .size()];
974: while (iter.hasNext()) {
975: ServiceBinding sb = (ServiceBinding) iter.next();
976: bindingTemplateArray[currLoc] = getBindingTemplateFromJAXRSB(sb);
977: currLoc++;
978: }
979: if (bindingTemplateArray != null) {
980: bt.setBindingTemplateArray(bindingTemplateArray);
981: }
982: }
983: return bt;
984: }
985: }
|