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