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