Coverage Report - org.apache.ws.scout.registry.BusinessQueryManagerV3Impl
 
Classes in this File Line Coverage Branch Coverage Complexity
BusinessQueryManagerV3Impl
20%
89/450
11%
17/156
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.registry;
 18  
 
 19  
 import java.net.PasswordAuthentication;
 20  
 import java.util.ArrayList;
 21  
 import java.util.Collection;
 22  
 import java.util.Iterator;
 23  
 import java.util.LinkedHashSet;
 24  
 import java.util.List;
 25  
 import java.util.Set;
 26  
 
 27  
 import javax.xml.registry.BulkResponse;
 28  
 import javax.xml.registry.BusinessLifeCycleManager;
 29  
 import javax.xml.registry.BusinessQueryManager;
 30  
 import javax.xml.registry.InvalidRequestException;
 31  
 import javax.xml.registry.JAXRException;
 32  
 import javax.xml.registry.LifeCycleManager;
 33  
 import javax.xml.registry.RegistryService;
 34  
 import javax.xml.registry.UnsupportedCapabilityException;
 35  
 import javax.xml.registry.infomodel.Association;
 36  
 import javax.xml.registry.infomodel.ClassificationScheme;
 37  
 import javax.xml.registry.infomodel.Concept;
 38  
 import javax.xml.registry.infomodel.Key;
 39  
 import javax.xml.registry.infomodel.LocalizedString;
 40  
 import javax.xml.registry.infomodel.Organization;
 41  
 import javax.xml.registry.infomodel.RegistryObject;
 42  
 import javax.xml.registry.infomodel.Service;
 43  
 import javax.xml.registry.infomodel.ServiceBinding;
 44  
 
 45  
 import org.apache.commons.logging.Log;
 46  
 import org.apache.commons.logging.LogFactory;
 47  
 
 48  
 import org.uddi.api_v3.*;
 49  
 import org.apache.ws.scout.registry.infomodel.AssociationImpl;
 50  
 import org.apache.ws.scout.registry.infomodel.ClassificationSchemeImpl;
 51  
 import org.apache.ws.scout.registry.infomodel.ConceptImpl;
 52  
 import org.apache.ws.scout.registry.infomodel.InternationalStringImpl;
 53  
 import org.apache.ws.scout.registry.infomodel.KeyImpl;
 54  
 import org.apache.ws.scout.registry.infomodel.ServiceBindingImpl;
 55  
 import org.apache.ws.scout.registry.infomodel.ServiceImpl;
 56  
 import org.apache.ws.scout.util.EnumerationHelper;
 57  
 import org.apache.ws.scout.util.ScoutJaxrUddiV3Helper;
 58  
 import org.apache.ws.scout.util.ScoutUddiV3JaxrHelper;
 59  
 
 60  
 /**
 61  
  * Implements the JAXR BusinessQueryManager Interface
 62  
  * For futher details, look into the JAXR API Javadoc.
 63  
  *
 64  
  * @author <a href="mailto:tcunning@apache.org">Tom Cunningham</a>
 65  
  * @author <a href="mailto:anil@apache.org">Anil Saldhana</a>
 66  
  * @author <a href="mailto:jboynes@apache.org">Jeremy Boynes</a>
 67  
  * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
 68  
  */
 69  
 public class BusinessQueryManagerV3Impl implements BusinessQueryManager
 70  
 {
 71  
     private final RegistryServiceImpl registryService;
 72  180
     private Log log = LogFactory.getLog(this.getClass());
 73  
 
 74  6
     private static ObjectFactory objectFactory = new ObjectFactory();
 75  
 
 76  
     public BusinessQueryManagerV3Impl(RegistryServiceImpl registry)
 77  180
     {
 78  180
         this.registryService = registry;
 79  180
     }
 80  
 
 81  
     public RegistryService getRegistryService()
 82  
     {
 83  0
         return registryService;
 84  
     }
 85  
 
 86  
     /**
 87  
      * Finds organizations in the registry that match the specified parameters
 88  
      *
 89  
      * @param findQualifiers
 90  
      * @param namePatterns
 91  
      * @param classifications
 92  
      * @param specifications
 93  
      * @param externalIdentifiers
 94  
      * @param externalLinks
 95  
      * @return BulkResponse
 96  
      * @throws JAXRException
 97  
      */
 98  
     public BulkResponse findOrganizations(Collection findQualifiers,
 99  
                                           Collection namePatterns,
 100  
                                           Collection classifications,
 101  
                                           Collection specifications,
 102  
                                           Collection externalIdentifiers,
 103  
                                           Collection externalLinks) throws JAXRException
 104  
     {
 105  0
         IRegistryV3 registry = (IRegistryV3) registryService.getRegistry();
 106  
         try
 107  
         {
 108  0
             FindQualifiers juddiFindQualifiers = mapFindQualifiers(findQualifiers);
 109  0
             Name[] nameArray = mapNamePatterns(namePatterns);
 110  0
             BusinessList result = registry.findBusiness(nameArray,
 111  
                     null, 
 112  
                     ScoutJaxrUddiV3Helper.getIdentifierBagFromExternalIdentifiers(externalIdentifiers), 
 113  
                     ScoutJaxrUddiV3Helper.getCategoryBagFromClassifications(classifications), 
 114  
                     ScoutJaxrUddiV3Helper.getTModelBagFromSpecifications(specifications),
 115  
                     juddiFindQualifiers,
 116  
                     registryService.getMaxRows());
 117  
             
 118  0
             BusinessInfo[] bizInfoArr =null;
 119  0
             BusinessInfos bizInfos = result.getBusinessInfos();
 120  0
             LinkedHashSet<Organization> orgs = new LinkedHashSet<Organization>();
 121  0
             if(bizInfos != null)
 122  
             {
 123  0
                     List<BusinessInfo> bizInfoList = bizInfos.getBusinessInfo();
 124  0
                     for (BusinessInfo businessInfo : bizInfoList) {
 125  
                     //Now get the details on the individual biz
 126  0
                     BusinessDetail detail = registry.getBusinessDetail(businessInfo.getBusinessKey());
 127  0
                     BusinessLifeCycleManagerV3Impl blcm = (BusinessLifeCycleManagerV3Impl)registryService.getLifeCycleManagerImpl();
 128  0
                     orgs.add(blcm.createOrganization(detail));
 129  0
                                 }
 130  0
                     bizInfoArr = new BusinessInfo[bizInfoList.size()];
 131  0
                     bizInfoList.toArray(bizInfoArr);
 132  
             }
 133  0
             return new BulkResponseImpl(orgs);
 134  0
         } catch (RegistryV3Exception e)
 135  
         {
 136  0
             throw new JAXRException(e);
 137  
         }
 138  
     }
 139  
 
 140  
     public BulkResponse findAssociations(Collection findQualifiers,
 141  
                                          String sourceObjectId,
 142  
                                          String targetObjectId,
 143  
                                          Collection associationTypes) throws JAXRException
 144  
     {
 145  
         //TODO: Currently we just return all the Association objects owned by the caller
 146  0
         IRegistryV3 registry = (IRegistryV3) registryService.getRegistry();
 147  
         try
 148  
         {
 149  0
             ConnectionImpl con = ((RegistryServiceImpl)getRegistryService()).getConnection();
 150  0
             AuthToken auth = this.getAuthToken(con,registry);
 151  0
             PublisherAssertions result =
 152  
                     registry.getPublisherAssertions(auth.getAuthInfo());
 153  0
             List<PublisherAssertion> publisherAssertionList = result.getPublisherAssertion();
 154  0
             LinkedHashSet<Association> col = new LinkedHashSet<Association>();
 155  0
             for (PublisherAssertion pas : publisherAssertionList) {
 156  0
                 String sourceKey = pas.getFromKey();
 157  0
                 String targetKey = pas.getToKey();
 158  0
                 Collection<Key> orgcol = new ArrayList<Key>();
 159  0
                 orgcol.add(new KeyImpl(sourceKey));
 160  0
                 orgcol.add(new KeyImpl(targetKey));
 161  0
                 BulkResponse bl = getRegistryObjects(orgcol, LifeCycleManager.ORGANIZATION);
 162  0
                 Association asso = ScoutUddiV3JaxrHelper.getAssociation(bl.getCollection(),
 163  
                                              registryService.getBusinessLifeCycleManager());
 164  0
                 KeyedReference keyr = pas.getKeyedReference();
 165  0
                 Concept c = new ConceptImpl(getRegistryService().getBusinessLifeCycleManager());
 166  0
                 c.setName(new InternationalStringImpl(keyr.getKeyName()));
 167  0
                 c.setKey( new KeyImpl(keyr.getTModelKey()) );
 168  0
                 c.setValue(keyr.getKeyValue());
 169  0
                 asso.setAssociationType(c);
 170  0
                 col.add(asso);
 171  0
             }
 172  0
             return new BulkResponseImpl(col);
 173  0
         } catch (RegistryV3Exception e)
 174  
         {
 175  0
             throw new JAXRException(e);
 176  
         }
 177  
     }
 178  
 
 179  
     public BulkResponse findCallerAssociations(Collection findQualifiers,
 180  
                                                Boolean confirmedByCaller,
 181  
                                                Boolean confirmedByOtherParty,
 182  
                                                Collection associationTypes) throws JAXRException
 183  
     {
 184  
         //TODO: Currently we just return all the Association objects owned by the caller
 185  0
         IRegistryV3 registry = (IRegistryV3) registryService.getRegistry();
 186  
         try
 187  
         {
 188  0
             ConnectionImpl con = ((RegistryServiceImpl)getRegistryService()).getConnection();
 189  0
             AuthToken auth = this.getAuthToken(con,registry);
 190  
            
 191  0
             AssertionStatusReport report = null;
 192  0
             String confirm = "";
 193  0
             boolean caller = confirmedByCaller.booleanValue();
 194  0
             boolean other = confirmedByOtherParty.booleanValue();
 195  
 
 196  0
             if(caller  && other   )
 197  0
                         confirm = Constants.COMPLETION_STATUS_COMPLETE;
 198  
             else
 199  0
               if(!caller  && other  )
 200  0
                         confirm = Constants.COMPLETION_STATUS_FROMKEY_INCOMPLETE;
 201  
             else
 202  0
                  if(caller  && !other   )
 203  0
                         confirm = Constants.COMPLETION_STATUS_TOKEY_INCOMPLETE;
 204  
 
 205  0
             report = registry.getAssertionStatusReport(auth.getAuthInfo(),confirm);
 206  
             
 207  
             
 208  0
             List<AssertionStatusItem> assertionStatusItemList = report.getAssertionStatusItem();
 209  0
             LinkedHashSet<Association> col = new LinkedHashSet<Association>();
 210  0
             for (AssertionStatusItem asi : assertionStatusItemList) {
 211  0
                 String sourceKey = asi.getFromKey();
 212  0
                 String targetKey = asi.getToKey();
 213  0
                 Collection<Key> orgcol = new ArrayList<Key>();
 214  0
                 orgcol.add(new KeyImpl(sourceKey));
 215  0
                 orgcol.add(new KeyImpl(targetKey));
 216  0
                 BulkResponse bl = getRegistryObjects(orgcol, LifeCycleManager.ORGANIZATION);
 217  0
                 Association asso = ScoutUddiV3JaxrHelper.getAssociation(bl.getCollection(),
 218  
                                              registryService.getBusinessLifeCycleManager());
 219  
                 //Set Confirmation
 220  0
                 ((AssociationImpl)asso).setConfirmedBySourceOwner(caller);
 221  0
                 ((AssociationImpl)asso).setConfirmedByTargetOwner(other);
 222  
 
 223  0
                 if(confirm != Constants.COMPLETION_STATUS_COMPLETE)
 224  0
                      ((AssociationImpl)asso).setConfirmed(false);
 225  
 
 226  0
                 Concept c = new ConceptImpl(getRegistryService().getBusinessLifeCycleManager());
 227  0
                 KeyedReference keyr = asi.getKeyedReference();
 228  0
                 c.setKey(new KeyImpl(keyr.getTModelKey()));
 229  0
                 c.setName(new InternationalStringImpl(keyr.getKeyName()));
 230  0
                 c.setValue(keyr.getKeyValue());
 231  0
                 asso.setKey(new KeyImpl(keyr.getTModelKey())); //TODO:Validate this
 232  0
                 asso.setAssociationType(c);
 233  0
                 col.add(asso);
 234  0
             }
 235  
 
 236  
 
 237  0
             return new BulkResponseImpl(col);
 238  0
         } catch (RegistryV3Exception e)
 239  
         {
 240  0
             throw new JAXRException(e);
 241  
         }
 242  
     }
 243  
 
 244  
     /**
 245  
      *  TODO - need to support the qualifiers
 246  
      *
 247  
      * @param findQualifiers
 248  
      * @param namePatterns
 249  
      * @return ClassificationScheme
 250  
      * @throws JAXRException
 251  
      */
 252  
     public ClassificationScheme findClassificationSchemeByName(Collection findQualifiers,
 253  
                                                                String namePatterns) throws JAXRException
 254  
     {
 255  36
         ClassificationScheme scheme = null;
 256  
 
 257  36
         if (namePatterns.indexOf("uddi-org:types") != -1) {
 258  
 
 259  0
             scheme = new ClassificationSchemeImpl(registryService.getLifeCycleManagerImpl());
 260  0
             scheme.setName(new InternationalStringImpl(namePatterns));
 261  0
             scheme.setKey(new KeyImpl(Constants.TMODEL_TYPES_TMODEL_KEY));
 262  
         }
 263  36
         else if (namePatterns.indexOf("dnb-com:D-U-N-S") != -1) {
 264  
 
 265  0
             scheme = new ClassificationSchemeImpl(registryService.getLifeCycleManagerImpl());
 266  0
             scheme.setName(new InternationalStringImpl(namePatterns));
 267  0
             scheme.setKey(new KeyImpl(Constants.TMODEL_D_U_N_S_TMODEL_KEY));
 268  
         }
 269  36
         else if (namePatterns.indexOf("uddi-org:iso-ch:3166:1999") != -1)
 270  
         {
 271  0
             scheme = new ClassificationSchemeImpl(registryService.getLifeCycleManagerImpl());
 272  0
             scheme.setName(new InternationalStringImpl(namePatterns));
 273  0
             scheme.setKey(new KeyImpl(Constants.TMODEL_ISO_CH_TMODEL_KEY));
 274  
         }
 275  36
         else if (namePatterns.indexOf("uddi-org:iso-ch:3166-1999") != -1)
 276  
         {
 277  0
             scheme = new ClassificationSchemeImpl(registryService.getLifeCycleManagerImpl());
 278  0
             scheme.setName(new InternationalStringImpl(namePatterns));
 279  0
             scheme.setKey(new KeyImpl(Constants.TMODEL_ISO_CH_TMODEL_KEY));
 280  
         }
 281  36
         else if (namePatterns.indexOf("iso-ch:3166:1999") != -1)
 282  
         {
 283  0
             scheme = new ClassificationSchemeImpl(registryService.getLifeCycleManagerImpl());
 284  0
             scheme.setName(new InternationalStringImpl(namePatterns));
 285  0
             scheme.setKey(new KeyImpl(Constants.TMODEL_ISO_CH_TMODEL_KEY));
 286  
         }
 287  36
         else if (namePatterns.indexOf("iso-ch:3166-1999") != -1)
 288  
         {
 289  0
             scheme = new ClassificationSchemeImpl(registryService.getLifeCycleManagerImpl());
 290  0
             scheme.setName(new InternationalStringImpl(namePatterns));
 291  0
             scheme.setKey(new KeyImpl(Constants.TMODEL_ISO_CH_TMODEL_KEY));
 292  
         }
 293  36
         else if (namePatterns.indexOf("unspsc-org:unspsc") != -1) {
 294  
 
 295  0
             scheme = new ClassificationSchemeImpl(registryService.getLifeCycleManagerImpl());
 296  0
             scheme.setName(new InternationalStringImpl(namePatterns));
 297  0
             scheme.setKey(new KeyImpl(Constants.TMODEL_UNSPSC_TMODEL_KEY));
 298  
         }
 299  36
         else if (namePatterns.indexOf("ntis-gov:naics") != -1) {
 300  
 
 301  0
             scheme = new ClassificationSchemeImpl(registryService.getLifeCycleManagerImpl());
 302  0
             scheme.setName(new InternationalStringImpl(namePatterns));
 303  0
             scheme.setKey(new KeyImpl(Constants.TMODEL_NAICS_TMODEL_KEY));
 304  
         }
 305  
         else
 306  
         {   //TODO:Before going to the registry, check if it a predefined Enumeration
 307  
 
 308  
             /*
 309  
              * predefined Enumerations
 310  
              */
 311  
 
 312  36
             if ("AssociationType".equals(namePatterns)) {
 313  6
                 scheme = new ClassificationSchemeImpl(registryService.getLifeCycleManagerImpl());
 314  
 
 315  6
                 scheme.setName(new InternationalStringImpl(namePatterns));
 316  
 
 317  6
                 scheme.setKey(new KeyImpl(Constants.TMODEL_UNSPSC_TMODEL_KEY));
 318  
 
 319  6
                 addChildConcept((ClassificationSchemeImpl)scheme, "RelatedTo");
 320  6
                 addChildConcept((ClassificationSchemeImpl)scheme, "HasChild");
 321  6
                 addChildConcept((ClassificationSchemeImpl)scheme, "HasMember");
 322  6
                 addChildConcept((ClassificationSchemeImpl)scheme, "HasParent");
 323  6
                 addChildConcept((ClassificationSchemeImpl)scheme, "ExternallyLinks");
 324  6
                 addChildConcept((ClassificationSchemeImpl)scheme, "Contains");
 325  6
                 addChildConcept((ClassificationSchemeImpl)scheme, "EquivalentTo");
 326  6
                 addChildConcept((ClassificationSchemeImpl)scheme, "Extends");
 327  6
                 addChildConcept((ClassificationSchemeImpl)scheme, "Implements");
 328  6
                 addChildConcept((ClassificationSchemeImpl)scheme, "InstanceOf");
 329  6
                 addChildConcept((ClassificationSchemeImpl)scheme, "Supersedes");
 330  6
                 addChildConcept((ClassificationSchemeImpl)scheme, "Uses");
 331  6
                 addChildConcept((ClassificationSchemeImpl)scheme, "Replaces");
 332  6
                 addChildConcept((ClassificationSchemeImpl)scheme, "ResponsibleFor");
 333  6
                 addChildConcept((ClassificationSchemeImpl)scheme, "SubmitterOf");
 334  
             }
 335  30
             else if ("ObjectType".equals(namePatterns)) {
 336  12
                 scheme = new ClassificationSchemeImpl(registryService.getLifeCycleManagerImpl());
 337  
 
 338  12
                 scheme.setName(new InternationalStringImpl(namePatterns));
 339  
 
 340  12
                 scheme.setKey(new KeyImpl(Constants.TMODEL_UNSPSC_TMODEL_KEY));
 341  
 
 342  12
                 addChildConcept((ClassificationSchemeImpl)scheme, "CPP");
 343  12
                 addChildConcept((ClassificationSchemeImpl)scheme, "CPA");
 344  12
                 addChildConcept((ClassificationSchemeImpl)scheme, "Process");
 345  12
                 addChildConcept((ClassificationSchemeImpl)scheme, "WSDL");
 346  12
                 addChildConcept((ClassificationSchemeImpl)scheme, "Association");
 347  12
                 addChildConcept((ClassificationSchemeImpl)scheme, "AuditableEvent");
 348  12
                 addChildConcept((ClassificationSchemeImpl)scheme, "Classification");
 349  12
                 addChildConcept((ClassificationSchemeImpl)scheme, "Concept");
 350  12
                 addChildConcept((ClassificationSchemeImpl)scheme, "ExternalIdentifier");
 351  12
                 addChildConcept((ClassificationSchemeImpl)scheme, "ExternalLink");
 352  12
                 addChildConcept((ClassificationSchemeImpl)scheme, "ExtrinsicObject");
 353  12
                 addChildConcept((ClassificationSchemeImpl)scheme, "Organization");
 354  12
                 addChildConcept((ClassificationSchemeImpl)scheme, "Package");
 355  12
                 addChildConcept((ClassificationSchemeImpl)scheme, "Service");
 356  12
                 addChildConcept((ClassificationSchemeImpl)scheme, "ServiceBinding");
 357  12
                 addChildConcept((ClassificationSchemeImpl)scheme, "User");
 358  
             }
 359  18
             else if ("PhoneType".equals(namePatterns)) {
 360  6
                 scheme = new ClassificationSchemeImpl(registryService.getLifeCycleManagerImpl());
 361  
 
 362  6
                 scheme.setName(new InternationalStringImpl(namePatterns));
 363  
 
 364  6
                 scheme.setKey(new KeyImpl(Constants.TMODEL_UNSPSC_TMODEL_KEY));
 365  
 
 366  6
                 addChildConcept((ClassificationSchemeImpl)scheme, "OfficePhone");
 367  6
                 addChildConcept((ClassificationSchemeImpl)scheme, "HomePhone");
 368  6
                 addChildConcept((ClassificationSchemeImpl)scheme, "MobilePhone");
 369  6
                 addChildConcept((ClassificationSchemeImpl)scheme, "Beeper");
 370  6
                 addChildConcept((ClassificationSchemeImpl)scheme, "FAX");
 371  
             }
 372  12
             else if ("URLType".equals(namePatterns)) {
 373  6
                 scheme = new ClassificationSchemeImpl(registryService.getLifeCycleManagerImpl());
 374  
 
 375  6
                 scheme.setName(new InternationalStringImpl(namePatterns));
 376  
 
 377  6
                 scheme.setKey(new KeyImpl(Constants.TMODEL_UNSPSC_TMODEL_KEY));
 378  
 
 379  6
                 addChildConcept((ClassificationSchemeImpl)scheme, "HTTP");
 380  6
                 addChildConcept((ClassificationSchemeImpl)scheme, "HTTPS");
 381  6
                 addChildConcept((ClassificationSchemeImpl)scheme, "SMTP");
 382  6
                 addChildConcept((ClassificationSchemeImpl)scheme, "PHONE");
 383  6
                 addChildConcept((ClassificationSchemeImpl)scheme, "FAX");
 384  6
                 addChildConcept((ClassificationSchemeImpl)scheme, "OTHER");
 385  
             }
 386  6
             else if ("PostalAddressAttributes".equals(namePatterns)) {
 387  6
                 scheme = new ClassificationSchemeImpl(registryService.getLifeCycleManagerImpl());
 388  
 
 389  6
                 scheme.setName(new InternationalStringImpl(namePatterns));
 390  
 
 391  6
                 scheme.setKey(new KeyImpl(Constants.TMODEL_UNSPSC_TMODEL_KEY));
 392  
 
 393  6
                 addChildConcept((ClassificationSchemeImpl)scheme, "StreetNumber");
 394  6
                 addChildConcept((ClassificationSchemeImpl)scheme, "Street");
 395  6
                 addChildConcept((ClassificationSchemeImpl)scheme, "City");
 396  6
                 addChildConcept((ClassificationSchemeImpl)scheme, "State");
 397  6
                 addChildConcept((ClassificationSchemeImpl)scheme, "PostalCode");
 398  6
                 addChildConcept((ClassificationSchemeImpl)scheme, "Country");
 399  
             }
 400  
             else {
 401  
 
 402  
                 //Lets ask the uddi registry if it has the TModels
 403  0
                 IRegistryV3 registry = (IRegistryV3) registryService.getRegistry();
 404  0
                 FindQualifiers juddiFindQualifiers = mapFindQualifiers(findQualifiers);
 405  
                 try
 406  
                 {
 407  
                     //We are looking for one exact match, so getting upto 3 records is fine
 408  0
                     TModelList list = registry.findTModel(namePatterns, null, null, juddiFindQualifiers, 3);
 409  0
                     if (list != null) {
 410  0
                         TModelInfos infos = list.getTModelInfos();
 411  0
                         if (infos != null) {
 412  0
                             List<TModelInfo> tmodelInfoList = infos.getTModelInfo();
 413  0
                             if (tmodelInfoList.size() > 1) {
 414  0
                                 throw new InvalidRequestException("Multiple matches found:" + tmodelInfoList.size());
 415  
                             }
 416  0
                             if (tmodelInfoList.size() ==1) {
 417  0
                                 TModelInfo info = tmodelInfoList.get(0);
 418  0
                                 scheme = new ClassificationSchemeImpl(registryService.getLifeCycleManagerImpl());
 419  0
                                 scheme.setName(new InternationalStringImpl(info.getName().getValue()));
 420  0
                                 scheme.setKey(new KeyImpl(info.getTModelKey()));
 421  
                             }
 422  
                         }
 423  
                     }
 424  
 
 425  0
                 } catch (RegistryV3Exception e)
 426  
                 { 
 427  0
                     throw new JAXRException(e.getLocalizedMessage());
 428  0
                 }
 429  
             }
 430  
         }
 431  36
         return scheme;
 432  
     }
 433  
 
 434  
     /**
 435  
      * Creates a new Concept, associates w/ parent scheme, and then
 436  
      * adds as decendent.
 437  
      * @param scheme
 438  
      * @param name
 439  
      * @throws JAXRException
 440  
      */
 441  
     private void addChildConcept(ClassificationSchemeImpl scheme, String name)
 442  
         throws JAXRException {
 443  384
         Concept c = new ConceptImpl(registryService.getLifeCycleManagerImpl());
 444  
 
 445  384
         c.setName(new InternationalStringImpl(name));
 446  384
         c.setValue(name);
 447  384
         ((ConceptImpl)c).setScheme((ClassificationSchemeImpl)scheme);
 448  
 
 449  384
         scheme.addChildConcept(c);
 450  384
     }
 451  
 
 452  
     public BulkResponse findClassificationSchemes(Collection findQualifiers, 
 453  
                                                                                               Collection namePatterns, 
 454  
                                                                                               Collection classifications, 
 455  
                                                                                               Collection externalLinks) throws JAXRException
 456  
         {
 457  
                 //TODO: Handle this better
 458  0
         LinkedHashSet<ClassificationScheme> col = new LinkedHashSet<ClassificationScheme>();
 459  0
                 Iterator iter = namePatterns.iterator();
 460  0
                 String name = "";
 461  0
                 while(iter.hasNext())
 462  
                 {
 463  0
                         name = (String)iter.next();
 464  
                         break;
 465  
                 }
 466  
                 
 467  0
         ClassificationScheme classificationScheme = findClassificationSchemeByName(findQualifiers,name);
 468  0
         if (classificationScheme!=null) {
 469  0
             col.add(classificationScheme);
 470  
         }
 471  0
                 return new BulkResponseImpl(col);
 472  
         }
 473  
 
 474  
     public Concept findConceptByPath(String path) throws JAXRException
 475  
     {
 476  
         //We will store the enumerations datastructure in the util package
 477  
         /**
 478  
          * I am not clear about how this association type enumerations
 479  
          * are to be implemented.
 480  
          */
 481  0
         return EnumerationHelper.getConceptByPath(path);
 482  
     }
 483  
 
 484  
     public BulkResponse findConcepts(Collection findQualifiers,
 485  
                                      Collection namePatterns,
 486  
                                      Collection classifications,
 487  
                                      Collection externalIdentifiers,
 488  
                                      Collection externalLinks) throws JAXRException
 489  
     {
 490  0
         LinkedHashSet<Concept> col = new LinkedHashSet<Concept>();
 491  
 
 492  
         //Lets ask the uddi registry if it has the TModels
 493  0
         IRegistryV3 registry = (IRegistryV3) registryService.getRegistry();
 494  0
         FindQualifiers juddiFindQualifiers = mapFindQualifiers(findQualifiers);
 495  0
         Iterator iter = null;
 496  0
         if (namePatterns != null) iter = namePatterns.iterator();
 497  0
         while (iter.hasNext())
 498  
         {
 499  0
             String namestr = (String) iter.next();
 500  
             try
 501  
             {
 502  0
                 TModelList list = registry.findTModel(namestr, 
 503  
                         ScoutJaxrUddiV3Helper.getCategoryBagFromClassifications(classifications), 
 504  
                         ScoutJaxrUddiV3Helper.getIdentifierBagFromExternalIdentifiers(externalIdentifiers), 
 505  
                                 juddiFindQualifiers, 10);
 506  
                
 507  0
                 if (list != null && list.getTModelInfos()!=null) {
 508  0
                         List<TModelInfo> tmodelInfoList = list.getTModelInfos().getTModelInfo();
 509  0
                         if (tmodelInfoList!=null) {
 510  0
                                 for (TModelInfo info: tmodelInfoList) {
 511  0
                             col.add(ScoutUddiV3JaxrHelper.getConcept(info, this.registryService.getBusinessLifeCycleManager()));
 512  
                                                 }
 513  
                         }
 514  
                 }
 515  0
             } catch (RegistryV3Exception e) { 
 516  0
                 throw new JAXRException(e.getLocalizedMessage());
 517  0
             }
 518  0
         }
 519  
 
 520  0
         return new BulkResponseImpl(col);
 521  
     }
 522  
 
 523  
     public BulkResponse findRegistryPackages(Collection findQualifiers,
 524  
                                              Collection namePatterns,
 525  
                                              Collection classifications,
 526  
                                              Collection externalLinks) throws JAXRException
 527  
     {
 528  0
         throw new UnsupportedCapabilityException();
 529  
     }
 530  
 
 531  
     public BulkResponse findServiceBindings(Key serviceKey,
 532  
                                             Collection findQualifiers,
 533  
                                             Collection classifications,
 534  
                                             Collection specifications) throws JAXRException
 535  
     {
 536  0
         BulkResponseImpl blkRes = new BulkResponseImpl();
 537  
 
 538  0
         IRegistryV3 iRegistry = (IRegistryV3) registryService.getRegistry();
 539  0
         FindQualifiers juddiFindQualifiers = mapFindQualifiers(findQualifiers);
 540  
 
 541  
         try
 542  
         {
 543  
  
 544  0
             BindingDetail bindingDetail = iRegistry.findBinding(serviceKey.getId(),
 545  
                     ScoutJaxrUddiV3Helper.getCategoryBagFromClassifications(classifications), 
 546  
                             ScoutJaxrUddiV3Helper.getTModelBagFromSpecifications(specifications),
 547  
                             juddiFindQualifiers,registryService.getMaxRows());
 548  
 
 549  
             /*
 550  
              * now convert  from jUDDI ServiceInfo objects to JAXR Services
 551  
              */
 552  0
             if (bindingDetail != null) {
 553  
 
 554  0
                     List<BindingTemplate> bindingTemplateList = bindingDetail.getBindingTemplate();
 555  0
                 BindingTemplate[] bindarr = new BindingTemplate[bindingTemplateList.size()];
 556  0
                 bindingTemplateList.toArray(bindarr);
 557  
                 
 558  0
                 LinkedHashSet<ServiceBinding> col = new LinkedHashSet<ServiceBinding>();
 559  
 
 560  0
                 for (int i=0; bindarr != null && i < bindarr.length; i++) {
 561  0
                     BindingTemplate si = bindarr[i];
 562  0
                     ServiceBinding sb =  ScoutUddiV3JaxrHelper.getServiceBinding(si,
 563  
                             registryService.getBusinessLifeCycleManager());
 564  0
                     col.add(sb);
 565  
                    //Fill the Service object by making a call to registry
 566  0
                    Service s = (Service)getRegistryObject(serviceKey.getId(), LifeCycleManager.SERVICE);
 567  0
                    ((ServiceBindingImpl)sb).setService(s);
 568  
                 }
 569  
 
 570  0
                 blkRes.setCollection(col);
 571  
             }
 572  
         }
 573  0
         catch (RegistryV3Exception e) {
 574  0
             throw new JAXRException(e.getLocalizedMessage());
 575  0
         }
 576  
 
 577  0
         return blkRes;
 578  
     }
 579  
 
 580  
 
 581  
     /**
 582  
      * Finds all Service objects that match all of the criteria specified by
 583  
      * the parameters of this call.  This is a logical AND operation between
 584  
      * all non-null parameters
 585  
      *
 586  
      * TODO - support findQualifiers, classifications and specifications
 587  
      *
 588  
      * @param orgKey
 589  
      * @param findQualifiers
 590  
      * @param namePatterns
 591  
      * @param classifications
 592  
      * @param specificationa
 593  
      * @return BulkResponse
 594  
      * @throws JAXRException
 595  
      */
 596  
     public BulkResponse findServices(Key orgKey, Collection findQualifiers,
 597  
                                      Collection namePatterns,
 598  
                                      Collection classifications,
 599  
                                      Collection specificationa) throws JAXRException
 600  
     {
 601  0
         BulkResponseImpl blkRes = new BulkResponseImpl();
 602  
 
 603  0
         IRegistryV3 iRegistry = (IRegistryV3) registryService.getRegistry();
 604  0
         FindQualifiers juddiFindQualifiers = mapFindQualifiers(findQualifiers);
 605  0
         Name[] juddiNames = mapNamePatterns(namePatterns);
 606  
 
 607  
         try
 608  
         {
 609  
             /*
 610  
              * hit the registry.  The key is not required for UDDI2
 611  
              */
 612  
 
 613  0
             String id = null;
 614  
 
 615  0
             if (orgKey != null) {
 616  0
                 id = orgKey.getId();
 617  
             }
 618  
 
 619  0
             ServiceList serviceList = iRegistry.findService(id, 
 620  
                             juddiNames,
 621  
                     ScoutJaxrUddiV3Helper.getCategoryBagFromClassifications(classifications), 
 622  
                     null, 
 623  
                     juddiFindQualifiers, registryService.getMaxRows());
 624  
 
 625  
             /*
 626  
              * now convert  from jUDDI ServiceInfo objects to JAXR Services
 627  
              */
 628  0
             if (serviceList != null) {
 629  
 
 630  0
                 ServiceInfos serviceInfos = serviceList.getServiceInfos();
 631  0
                 LinkedHashSet<Service> col = new LinkedHashSet<Service>();
 632  
                 
 633  0
                 if(serviceInfos != null && serviceInfos.getServiceInfo()!=null) {
 634  0
                         for (ServiceInfo si : serviceInfos.getServiceInfo()) {
 635  0
                                 Service srv = (Service) getRegistryObject(si.getServiceKey(), LifeCycleManager.SERVICE);
 636  0
                         col.add(srv);
 637  0
                                         }
 638  
                         
 639  
                 }
 640  0
                 blkRes.setCollection(col);
 641  
             }
 642  
         }
 643  0
         catch (RegistryV3Exception e) {
 644  0
             throw new JAXRException(e.getLocalizedMessage());
 645  0
         }
 646  
 
 647  0
         return blkRes;
 648  
     }
 649  
 
 650  
     public RegistryObject getRegistryObject(String id) throws JAXRException
 651  
     {
 652  0
         throw new UnsupportedCapabilityException();
 653  
     }
 654  
 
 655  
     public RegistryObject getRegistryObject(String id, String objectType) throws JAXRException
 656  
     {
 657  0
         IRegistryV3 registry = (IRegistryV3) registryService.getRegistry();
 658  0
         BusinessLifeCycleManager lcm = registryService.getBusinessLifeCycleManager();
 659  
 
 660  0
         if (LifeCycleManager.CLASSIFICATION_SCHEME.equalsIgnoreCase(objectType)) {
 661  
 
 662  
             try {
 663  
 
 664  0
                 TModelDetail tmodeldetail = registry.getTModelDetail(id);
 665  0
                 Concept c = ScoutUddiV3JaxrHelper.getConcept(tmodeldetail, lcm);
 666  
 
 667  
                 /*
 668  
                  * now turn into a concrete ClassificationScheme
 669  
                  */
 670  
 
 671  0
                 ClassificationScheme scheme = new ClassificationSchemeImpl(lcm);
 672  
 
 673  0
                 scheme.setName(c.getName());
 674  0
                 scheme.setDescription(c.getDescription());
 675  0
                 scheme.setKey(c.getKey());
 676  
 
 677  0
                 return scheme;
 678  
             }
 679  0
             catch (RegistryV3Exception e) {
 680  0
                 throw new JAXRException(e.getLocalizedMessage());
 681  
             }
 682  
         }
 683  0
         else if (LifeCycleManager.ORGANIZATION.equalsIgnoreCase(objectType)) {                
 684  
             try
 685  
             {
 686  0
                 BusinessDetail orgdetail = registry.getBusinessDetail(id);
 687  0
                 return ScoutUddiV3JaxrHelper.getOrganization(orgdetail, lcm);
 688  
             }
 689  0
             catch (RegistryV3Exception e) {
 690  0
                 throw new JAXRException(e.getLocalizedMessage());
 691  
             }
 692  
 
 693  
         }
 694  0
         else if (LifeCycleManager.CONCEPT.equalsIgnoreCase(objectType)) {
 695  
 
 696  
             try
 697  
             {
 698  0
                 TModelDetail tmodeldetail = registry.getTModelDetail(id);
 699  0
                 return ScoutUddiV3JaxrHelper.getConcept(tmodeldetail, lcm);
 700  
             }
 701  0
             catch (RegistryV3Exception e) { 
 702  0
                 throw new JAXRException(e.getLocalizedMessage());
 703  
             }
 704  
         }
 705  0
         else if (LifeCycleManager.SERVICE.equalsIgnoreCase(objectType)) {
 706  
 
 707  
             try {
 708  0
                 ServiceDetail sd = registry.getServiceDetail(id);
 709  0
                 if (sd != null && sd.getBusinessService()!=null) {
 710  0
                     for (BusinessService businessService : sd.getBusinessService()) {
 711  0
                             Service service = getServiceFromBusinessService(businessService, lcm);
 712  0
                             return service;
 713  
                                         }
 714  
                 }
 715  
             }
 716  0
             catch (RegistryV3Exception e) {
 717  0
                 throw new RuntimeException(e);
 718  0
             }
 719  
         }
 720  
 
 721  0
         return null;
 722  
     }
 723  
 
 724  
     /**
 725  
      *  Helper routine to take a jUDDI business service and turn into a useful
 726  
      *  Service.  Needs to go back to the registry to get the organization to
 727  
      *  properly hydrate the Service
 728  
      *
 729  
      * @param bs  BusinessService object to turn in to a Service
 730  
      * @param lcm manager to use
 731  
      * @return new Service object
 732  
      * @throws JAXRException
 733  
      */
 734  
     protected Service getServiceFromBusinessService(BusinessService bs, LifeCycleManager lcm)
 735  
         throws JAXRException {
 736  
 
 737  0
         ServiceImpl service  = (ServiceImpl) ScoutUddiV3JaxrHelper.getService(bs, lcm);
 738  0
         service.setSubmittingOrganizationKey(bs.getBusinessKey());
 739  
 
 740  0
         return service;
 741  
     }
 742  
 
 743  
     /**
 744  
      * Gets the RegistryObjects owned by the caller. The objects
 745  
      * are returned as their concrete type (e.g. Organization, User etc.)
 746  
      *
 747  
      *  TODO - need to figure out what the set are.  This is just to get some
 748  
      *  basic functionality
 749  
      *
 750  
      * @return BulkResponse
 751  
      * @throws JAXRException
 752  
      */
 753  
     public BulkResponse getRegistryObjects() throws JAXRException
 754  
     {
 755  0
         String types[] = {
 756  
             LifeCycleManager.ORGANIZATION,
 757  
             LifeCycleManager.SERVICE};
 758  
 
 759  0
         LinkedHashSet<Object> c = new LinkedHashSet<Object>();
 760  
 
 761  0
         for (int i = 0; i < types.length; i++) {
 762  
             try {
 763  0
                 BulkResponse bk = getRegistryObjects(types[i]);
 764  
 
 765  0
                 if (bk.getCollection() != null) {
 766  0
                     c.addAll(bk.getCollection());
 767  
                 }
 768  0
             } catch(JAXRException e) {
 769  0
                     log.debug("ignore - just a problem with that type? " + e.getMessage(), e);
 770  0
             }
 771  
         }
 772  
 
 773  0
         return new BulkResponseImpl(c);
 774  
     }
 775  
 
 776  
     public BulkResponse getRegistryObjects(Collection objectKeys) throws JAXRException
 777  
     {
 778  0
         throw new UnsupportedCapabilityException();
 779  
     }
 780  
 
 781  
     public BulkResponse getRegistryObjects(Collection objectKeys, String objectType) throws JAXRException
 782  
     {
 783  0
         IRegistryV3 registry = (IRegistryV3) registryService.getRegistry();
 784  
         //Convert into a vector of strings
 785  0
         String[] keys = new String[objectKeys.size()];
 786  0
         int currLoc = 0;
 787  0
         for (Key key : (Collection<Key>) objectKeys) {
 788  0
             keys[currLoc] = key.getId();
 789  0
             currLoc++;
 790  
         }
 791  0
         LinkedHashSet<RegistryObject> col = new LinkedHashSet<RegistryObject>();
 792  0
         LifeCycleManager lcm = registryService.getLifeCycleManagerImpl();
 793  
 
 794  0
         if (LifeCycleManager.CLASSIFICATION_SCHEME.equalsIgnoreCase(objectType))
 795  
         {
 796  
             try
 797  
             {
 798  0
                 TModelDetail tmodeldetail = registry.getTModelDetail(keys);
 799  0
                 List<TModel> tmodelList = tmodeldetail.getTModel();
 800  
 
 801  0
                 for (TModel tModel: tmodelList)
 802  
                 {
 803  0
                     col.add(ScoutUddiV3JaxrHelper.getConcept(tModel, lcm));
 804  
                 }
 805  
 
 806  0
             } catch (RegistryV3Exception e)
 807  
             { 
 808  0
                 throw new JAXRException(e.getLocalizedMessage());
 809  0
             }
 810  
         }
 811  0
         else if (LifeCycleManager.ORGANIZATION.equalsIgnoreCase(objectType))
 812  
         {
 813  0
                 ConnectionImpl con = ((RegistryServiceImpl)getRegistryService()).getConnection();
 814  0
             AuthToken auth = this.getAuthToken(con,registry);
 815  
                 
 816  
             try
 817  
             {
 818  0
                     RegisteredInfo ri = registry.getRegisteredInfo(auth.getAuthInfo());
 819  0
                 if (ri != null) {
 820  0
                     BusinessInfos infos = ri.getBusinessInfos();
 821  0
                     if (infos != null) {
 822  0
                         List<BusinessInfo> bizInfoList = infos.getBusinessInfo();
 823  0
                         for (BusinessInfo businessInfo: bizInfoList) {
 824  0
                             BusinessDetail detail = registry.getBusinessDetail(businessInfo.getBusinessKey());
 825  0
                             col.add(((BusinessLifeCycleManagerV3Impl)registryService.getLifeCycleManagerImpl()).createOrganization(detail));
 826  0
                         }
 827  
                     }
 828  
                 }
 829  0
             } catch (RegistryV3Exception e) {
 830  0
                     throw new JAXRException(e.getLocalizedMessage());
 831  0
             }
 832  0
         }
 833  0
         else if (LifeCycleManager.CONCEPT.equalsIgnoreCase(objectType))
 834  
         {
 835  
             try {
 836  0
                 TModelDetail tmodeldetail = registry.getTModelDetail(keys);
 837  0
                 List<TModel> tmodelList = tmodeldetail.getTModel();
 838  
 
 839  0
                 for (TModel tmodel: tmodelList)
 840  
                 {
 841  0
                     col.add(ScoutUddiV3JaxrHelper.getConcept(tmodel, lcm));
 842  
                 }
 843  
 
 844  
             }
 845  0
             catch (RegistryV3Exception e)
 846  
             { 
 847  0
                 throw new JAXRException(e.getLocalizedMessage());
 848  0
             }
 849  
         }
 850  0
         else if (LifeCycleManager.SERVICE.equalsIgnoreCase(objectType)) {
 851  
 
 852  
             try {
 853  0
                 ServiceDetail serviceDetail = registry.getServiceDetail(keys);
 854  
 
 855  0
                 if (serviceDetail != null) {
 856  0
                     List<BusinessService> bizServiceList = serviceDetail.getBusinessService();
 857  
 
 858  0
                     for (BusinessService businessService: bizServiceList) {
 859  
 
 860  0
                         Service service = getServiceFromBusinessService(businessService, lcm);
 861  
                         
 862  0
                         col.add(service);
 863  0
                     }
 864  
                 }
 865  
             }
 866  0
             catch (RegistryV3Exception e) {
 867  0
                 throw new JAXRException(e);
 868  0
             }
 869  
         }
 870  
         else {
 871  0
             throw new JAXRException("Unsupported type " + objectType +
 872  
                     " for getRegistryObjects() in Apache Scout");
 873  
         }
 874  
 
 875  0
         return new BulkResponseImpl(col);
 876  
 
 877  
     }
 878  
 
 879  
     public BulkResponse getRegistryObjects(String id) throws JAXRException
 880  
     {
 881  0
         if (LifeCycleManager.ORGANIZATION.equalsIgnoreCase(id)) {
 882  0
             IRegistryV3 registry = (IRegistryV3) registryService.getRegistry();
 883  0
                 ConnectionImpl con = ((RegistryServiceImpl)getRegistryService()).getConnection();
 884  0
             AuthToken auth = this.getAuthToken(con,registry);
 885  0
                     LinkedHashSet<Organization> orgs = null;
 886  
             try
 887  
             {
 888  0
                     RegisteredInfo ri = registry.getRegisteredInfo(auth.getAuthInfo());
 889  0
                     if (ri != null && ri.getBusinessInfos()!=null) {
 890  0
                             List<BusinessInfo> bizInfoList = ri.getBusinessInfos().getBusinessInfo();
 891  0
                             orgs = new LinkedHashSet<Organization>();
 892  0
                             for (BusinessInfo businessInfo : bizInfoList) {
 893  0
                                     BusinessDetail detail = registry.getBusinessDetail(businessInfo.getBusinessKey());
 894  0
                         orgs.add(((BusinessLifeCycleManagerV3Impl)registryService.getLifeCycleManagerImpl()).createOrganization(detail));
 895  0
                                         }
 896  
                     }
 897  
                     
 898  0
             } catch (RegistryV3Exception re) {
 899  0
                     throw new JAXRException(re);
 900  0
             }
 901  0
             return new BulkResponseImpl(orgs);
 902  
         }
 903  0
         else if (LifeCycleManager.SERVICE.equalsIgnoreCase(id)) {
 904  0
             List<String> a = new ArrayList<String>();
 905  0
             a.add("%");
 906  
 
 907  0
             BulkResponse br = this.findServices(null,null, a, null, null);
 908  
 
 909  0
             return br;
 910  
         }
 911  
         else
 912  
         {
 913  0
             throw new JAXRException("Unsupported type for getRegistryObjects() :" + id);
 914  
         }
 915  
 
 916  
     }
 917  
 
 918  
     static FindQualifiers mapFindQualifiers(Collection jaxrQualifiers) throws UnsupportedCapabilityException
 919  
     {
 920  0
         if (jaxrQualifiers == null)
 921  
         {
 922  0
             return null;
 923  
         }
 924  0
         FindQualifiers result = objectFactory.createFindQualifiers();
 925  0
         for (Iterator i = jaxrQualifiers.iterator(); i.hasNext();)
 926  
         {
 927  0
             String jaxrQualifier = (String) i.next();
 928  0
             String juddiQualifier = jaxrQualifier;
 929  0
             if (juddiQualifier == null)
 930  
             {
 931  0
                 throw new UnsupportedCapabilityException("jUDDI does not support FindQualifer: " + jaxrQualifier);
 932  
             }
 933  0
             result.getFindQualifier().add(juddiQualifier);
 934  0
         }
 935  0
         return result;
 936  
     }
 937  
 
 938  
     static Name[] mapNamePatterns(Collection namePatterns)
 939  
         throws JAXRException
 940  
     {
 941  0
         if (namePatterns == null)
 942  0
             return null;
 943  0
         Name[] result = new Name[namePatterns.size()];
 944  0
         int currLoc = 0;
 945  0
         for (Iterator i = namePatterns.iterator(); i.hasNext();)
 946  
         {
 947  0
             Object obj = i.next();
 948  0
             Name name = objectFactory.createName();
 949  0
             if (obj instanceof String) {
 950  0
                 name.setValue((String)obj);
 951  0
             } else if (obj instanceof LocalizedString) {
 952  0
                 LocalizedString ls = (LocalizedString)obj;
 953  0
                 name.setValue(ls.getValue());
 954  0
                 name.setLang(ls.getLocale().getLanguage());
 955  
             }
 956  0
             result[currLoc] = name;
 957  0
             currLoc++;
 958  0
         }
 959  0
         return result;
 960  
     }
 961  
 
 962  
    /**
 963  
      * Get the Auth Token from the registry
 964  
      *
 965  
      * @param connection
 966  
      * @param ireg
 967  
      * @return auth token
 968  
      * @throws JAXRException
 969  
      */
 970  
     private AuthToken getAuthToken(ConnectionImpl connection, IRegistryV3 ireg)
 971  
             throws JAXRException {
 972  0
         Set creds = connection.getCredentials();
 973  0
         Iterator it = creds.iterator();
 974  0
         String username = "", pwd = "";
 975  0
         while (it.hasNext()) {
 976  0
             PasswordAuthentication pass = (PasswordAuthentication) it.next();
 977  0
             username = pass.getUserName();
 978  0
             pwd = new String(pass.getPassword());
 979  0
         }
 980  0
         AuthToken token = null;
 981  
         try {
 982  0
             token = ireg.getAuthToken(username, pwd);
 983  
         }
 984  0
         catch (Exception e) {
 985  0
             throw new JAXRException(e);
 986  0
         }
 987  0
         return token;
 988  
     }
 989  
 }