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