Coverage Report - org.apache.ws.scout.registry.BusinessLifeCycleManagerV3Impl
 
Classes in this File Line Coverage Branch Coverage Complexity
BusinessLifeCycleManagerV3Impl
1%
5/427
1%
1/178
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.io.Serializable;
 20  
 import java.net.PasswordAuthentication;
 21  
 import java.util.ArrayList;
 22  
 import java.util.Collection;
 23  
 import java.util.HashSet;
 24  
 import java.util.Iterator;
 25  
 import java.util.LinkedHashSet;
 26  
 import java.util.List;
 27  
 import java.util.Set;
 28  
 import java.util.Vector;
 29  
 
 30  
 import javax.xml.registry.BulkResponse;
 31  
 import javax.xml.registry.BusinessLifeCycleManager;
 32  
 import javax.xml.registry.DeleteException;
 33  
 import javax.xml.registry.InvalidRequestException;
 34  
 import javax.xml.registry.JAXRException;
 35  
 import javax.xml.registry.JAXRResponse;
 36  
 import javax.xml.registry.LifeCycleManager;
 37  
 import javax.xml.registry.RegistryService;
 38  
 import javax.xml.registry.SaveException;
 39  
 import javax.xml.registry.UnexpectedObjectException;
 40  
 import javax.xml.registry.infomodel.Association;
 41  
 import javax.xml.registry.infomodel.ClassificationScheme;
 42  
 import javax.xml.registry.infomodel.Concept;
 43  
 import javax.xml.registry.infomodel.Key;
 44  
 import javax.xml.registry.infomodel.Organization;
 45  
 import javax.xml.registry.infomodel.RegistryObject;
 46  
 import javax.xml.registry.infomodel.Service;
 47  
 import javax.xml.registry.infomodel.ServiceBinding;
 48  
 
 49  
 import org.apache.commons.logging.Log;
 50  
 import org.apache.commons.logging.LogFactory;
 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.OrganizationImpl;
 55  
 import org.apache.ws.scout.registry.infomodel.ServiceImpl;
 56  
 import org.apache.ws.scout.util.ScoutJaxrUddiV3Helper;
 57  
 import org.apache.ws.scout.util.ScoutUddiV3JaxrHelper;
 58  
 import org.uddi.api_v3.AssertionStatusItem;
 59  
 import org.uddi.api_v3.AssertionStatusReport;
 60  
 import org.uddi.api_v3.AuthToken;
 61  
 import org.uddi.api_v3.BindingDetail;
 62  
 import org.uddi.api_v3.BindingTemplate;
 63  
 import org.uddi.api_v3.BusinessDetail;
 64  
 import org.uddi.api_v3.BusinessEntity;
 65  
 import org.uddi.api_v3.BusinessInfo;
 66  
 import org.uddi.api_v3.BusinessService;
 67  
 import org.uddi.api_v3.Description;
 68  
 import org.uddi.api_v3.DispositionReport;
 69  
 import org.uddi.api_v3.ErrInfo;
 70  
 import org.uddi.api_v3.KeyedReference;
 71  
 import org.uddi.api_v3.Name;
 72  
 import org.uddi.api_v3.ObjectFactory;
 73  
 import org.uddi.api_v3.PublisherAssertion;
 74  
 import org.uddi.api_v3.PublisherAssertions;
 75  
 import org.uddi.api_v3.Result;
 76  
 import org.uddi.api_v3.ServiceDetail;
 77  
 import org.uddi.api_v3.ServiceInfo;
 78  
 import org.uddi.api_v3.TModel;
 79  
 import org.uddi.api_v3.TModelDetail;
 80  
 
 81  
 /**
 82  
  * Implements JAXR BusinessLifeCycleManager Interface.
 83  
  * For futher details, look into the JAXR API Javadoc.
 84  
  *
 85  
  * @author <a href="mailto:anil@apache.org">Anil Saldhana</a>
 86  
  * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
 87  
  * @author <a href="mailto:tcunning@apache.org">Tom Cunningham</a>
 88  
  */
 89  
 public class BusinessLifeCycleManagerV3Impl extends LifeCycleManagerImpl
 90  
         implements BusinessLifeCycleManager, Serializable {
 91  
                 
 92  
         private static final long serialVersionUID = -1145007155334678356L;
 93  
 
 94  174
         private Log log = LogFactory.getLog(this.getClass());
 95  
     
 96  174
     private transient ObjectFactory objectFactory = new ObjectFactory();
 97  
         
 98  
     public BusinessLifeCycleManagerV3Impl(RegistryService registry) {
 99  174
         super(registry);
 100  174
         if(objectFactory == null)
 101  0
                 objectFactory = new ObjectFactory();
 102  174
     }
 103  
 
 104  
     /**
 105  
      * Deletes one or more previously submitted objects from the registry
 106  
      * using the object keys and a specified objectType attribute.
 107  
      *
 108  
      * @param keys
 109  
      * @param objectType
 110  
      * @return BulkResponse object
 111  
      * @throws JAXRException
 112  
      */
 113  
     public BulkResponse deleteObjects(Collection keys, String objectType) throws JAXRException {
 114  0
         BulkResponse bulk = null;
 115  
 
 116  0
         if (objectType == LifeCycleManager.ASSOCIATION) {
 117  0
             bulk = this.deleteAssociations(keys);
 118  
         }
 119  0
         else if (objectType == LifeCycleManager.CLASSIFICATION_SCHEME) {
 120  0
             bulk = this.deleteClassificationSchemes(keys);
 121  
         }
 122  0
         else if (objectType == LifeCycleManager.CONCEPT) {
 123  0
             bulk = this.deleteConcepts(keys);
 124  
         }
 125  0
         else if (objectType == LifeCycleManager.ORGANIZATION) {
 126  0
             bulk = this.deleteOrganizations(keys);
 127  
         }
 128  0
         else if (objectType == LifeCycleManager.SERVICE) {
 129  0
             bulk = this.deleteServices(keys);
 130  
         }
 131  0
         else if (objectType == LifeCycleManager.SERVICE_BINDING) {
 132  0
             bulk = this.deleteServiceBindings(keys);
 133  
         }
 134  
         else {
 135  0
             throw new JAXRException("Delete Operation for " + objectType + " not implemented by Scout");
 136  
         }
 137  
 
 138  0
         return bulk;
 139  
     }
 140  
 
 141  
     public BulkResponse deleteAssociations(Collection associationKeys) throws JAXRException {
 142  0
         return this.deleteOperation(associationKeys, "DELETE_ASSOCIATION");
 143  
     }
 144  
 
 145  
     public BulkResponse deleteClassificationSchemes(Collection schemeKeys) throws JAXRException {
 146  0
         return this.deleteOperation(schemeKeys, "DELETE_CLASSIFICATIONSCHEME");
 147  
     }
 148  
 
 149  
     public BulkResponse deleteConcepts(Collection conceptKeys) throws JAXRException {
 150  0
         return this.deleteOperation(conceptKeys, "DELETE_CONCEPT");
 151  
     }
 152  
 
 153  
     public BulkResponse deleteOrganizations(Collection orgkeys) throws JAXRException {
 154  0
         return this.deleteOperation(orgkeys, "DELETE_ORG");
 155  
     }
 156  
 
 157  
     public BulkResponse deleteServiceBindings(Collection bindingKeys) throws JAXRException {
 158  0
         return this.deleteOperation(bindingKeys, "DELETE_SERVICEBINDING");
 159  
     }
 160  
 
 161  
     public BulkResponse deleteServices(Collection serviceKeys) throws JAXRException {
 162  0
         return this.deleteOperation(serviceKeys, "DELETE_SERVICE");
 163  
     }
 164  
 
 165  
     /**
 166  
      * Saves one or more Objects to the registry. An object may be a
 167  
      * RegistryObject  subclass instance. If an object is not in the registry,
 168  
      * it is created in the registry.  If it already exists in the registry
 169  
      * and has been modified, then its  state is updated (replaced) in the
 170  
      * registry
 171  
      * <p/>
 172  
      * TODO:Check if juddi can provide a facility to store a collection of heterogenous
 173  
      * objects
 174  
      * <p/>
 175  
      * TODO - does this belong here?  it's really an overload of
 176  
      * LifecycleManager.saveObjects, but all the help we need
 177  
      * like saveOrganization() is up here...
 178  
      *
 179  
      * @param col
 180  
      * @return a BulkResponse containing the Collection of keys for those objects
 181  
      *         that were saved successfully and any SaveException that was encountered
 182  
      *         in case of partial commit
 183  
      * @throws JAXRException
 184  
      */
 185  
     public BulkResponse saveObjects(Collection col) throws JAXRException {
 186  
 
 187  0
         Iterator iter = col.iterator();
 188  
 
 189  0
         LinkedHashSet<Object> suc = new LinkedHashSet<Object>();
 190  0
         Collection<Exception> exc = new ArrayList<Exception>();
 191  
 
 192  0
         while (iter.hasNext()) {
 193  0
             RegistryObject reg = (RegistryObject) iter.next();
 194  
 
 195  0
             BulkResponse br = null;
 196  
 
 197  0
             Collection<RegistryObject> c = new ArrayList<RegistryObject>();
 198  0
             c.add(reg);
 199  
 
 200  0
             if (reg instanceof javax.xml.registry.infomodel.Association) {
 201  0
                 br = saveAssociations(c, true);
 202  
             }
 203  0
             else if (reg instanceof javax.xml.registry.infomodel.ClassificationScheme) {
 204  0
                 br = saveClassificationSchemes(c);
 205  
             }
 206  0
             else if (reg instanceof javax.xml.registry.infomodel.Concept) {
 207  0
                 br = saveConcepts(c);
 208  
             }
 209  0
             else if (reg instanceof javax.xml.registry.infomodel.Organization) {
 210  0
                 br = saveOrganizations(c);
 211  
             }
 212  0
             else if (reg instanceof javax.xml.registry.infomodel.Service) {
 213  0
                 br = saveServices(c);
 214  
             }
 215  0
             else if (reg instanceof javax.xml.registry.infomodel.ServiceBinding) {
 216  0
                 br = saveServiceBindings(c);
 217  
             }
 218  
             else {
 219  0
                 throw new JAXRException("Delete Operation for " + reg.getClass() 
 220  
                         + " not implemented by Scout");
 221  
             }
 222  
 
 223  0
             if (br.getCollection() != null) {
 224  0
                 suc.addAll(br.getCollection());
 225  
             }
 226  
 
 227  0
             if (br.getExceptions() != null) {
 228  0
                 exc.addAll(br.getExceptions());
 229  
             }
 230  0
         }
 231  
 
 232  0
         BulkResponseImpl bulk = new BulkResponseImpl();
 233  
 
 234  
         /*
 235  
          *  TODO - what is the right status?
 236  
          */
 237  0
         bulk.setStatus(JAXRResponse.STATUS_SUCCESS);
 238  
 
 239  0
         bulk.setCollection(suc);
 240  0
         bulk.setExceptions(exc);
 241  
 
 242  0
         return bulk;
 243  
     }
 244  
 
 245  
 
 246  
     public BulkResponse saveAssociations(Collection associations, boolean replace) throws JAXRException {
 247  0
         BulkResponseImpl bulk = new BulkResponseImpl();
 248  0
         PublisherAssertion[] sarr = new PublisherAssertion[associations.size()];
 249  
 
 250  0
         Collection<Key> coll = new ArrayList<Key>();
 251  0
         Collection<Exception> exceptions = new ArrayList<Exception>();
 252  
 
 253  0
         Iterator iter = associations.iterator();
 254  0
         int currLoc = 0;
 255  0
         while (iter.hasNext()) {
 256  
             
 257  0
                 Association association = (Association) iter.next();
 258  0
                 association.getSourceObject();
 259  0
                 PublisherAssertion pa = ScoutJaxrUddiV3Helper.getPubAssertionFromJAXRAssociation(association);
 260  0
                 sarr[currLoc] = pa;
 261  0
                 currLoc++;
 262  
             
 263  
                 // Save PublisherAssertion
 264  0
                 PublisherAssertions bd = null;
 265  
                 try {
 266  0
                     bd = (PublisherAssertions) executeOperation(sarr, "SAVE_ASSOCIATION");
 267  
                 }
 268  0
                 catch (RegistryV3Exception e) {
 269  0
                     exceptions.add(new SaveException(e));
 270  0
                     bulk.setExceptions(exceptions);
 271  0
                     bulk.setStatus(JAXRResponse.STATUS_FAILURE);
 272  0
                     return bulk;
 273  0
                 }
 274  0
                 if(bd != null)
 275  
                 {
 276  0
                         List<PublisherAssertion> publisherAssertionList = bd.getPublisherAssertion();
 277  0
                         PublisherAssertion[] keyarr = new PublisherAssertion[publisherAssertionList.size()];
 278  0
                         publisherAssertionList.toArray(keyarr);
 279  
                         
 280  0
                         for (int i = 0; keyarr != null && i < keyarr.length; i++) {
 281  0
                                 PublisherAssertion result = (PublisherAssertion) keyarr[i];
 282  0
                         KeyedReference keyr = result.getKeyedReference();
 283  0
                         Concept c = new ConceptImpl(getRegistryService().getBusinessLifeCycleManager());
 284  0
                         c.setName(new InternationalStringImpl(keyr.getKeyName()));
 285  0
                         c.setKey( new KeyImpl(keyr.getTModelKey()) );
 286  0
                         c.setValue(keyr.getKeyValue());
 287  0
                         association.setAssociationType(c);
 288  0
                         coll.add(association.getKey());
 289  
                    }
 290  
                 }
 291  0
         }
 292  0
         bulk.setCollection(coll);
 293  0
         bulk.setExceptions(exceptions);
 294  
 
 295  0
         return bulk;
 296  
     }
 297  
 
 298  
     public BulkResponse saveClassificationSchemes(Collection schemes) throws JAXRException {
 299  
         //Now we need to convert the collection into a vector for juddi
 300  0
         BulkResponseImpl bulk = new BulkResponseImpl();
 301  0
         TModel[] entityarr = new TModel[schemes.size()];
 302  
 
 303  0
         LinkedHashSet<Key> coll = new LinkedHashSet<Key>();
 304  0
         Collection<Exception> exceptions = new ArrayList<Exception>();
 305  
 
 306  0
         Iterator iter = schemes.iterator();
 307  0
         int currLoc = 0;
 308  0
         while (iter.hasNext()) {
 309  
             try {
 310  0
                 TModel en =
 311  
                                 ScoutJaxrUddiV3Helper.getTModelFromJAXRClassificationScheme((ClassificationScheme) iter.next());
 312  0
                 entityarr[currLoc] = en;
 313  0
                 currLoc++;
 314  
             }
 315  0
             catch (ClassCastException ce) {
 316  0
                 throw new UnexpectedObjectException();
 317  0
             }
 318  
         }
 319  0
         log.debug("Method:save_classificationscheme: ENlength=" + entityarr.length);
 320  
         // Save business
 321  0
         TModelDetail td = null;
 322  
         try {
 323  0
             td = (TModelDetail) executeOperation(entityarr, "SAVE_TMODEL");
 324  
         }
 325  0
         catch (RegistryV3Exception e) {
 326  0
             exceptions.add(new SaveException(e.getLocalizedMessage()));
 327  0
             bulk.setStatus(JAXRResponse.STATUS_FAILURE);
 328  0
             return bulk;
 329  0
         }
 330  
 
 331  0
         List<TModel> tmodelList = td.getTModel();
 332  0
         entityarr = new TModel[tmodelList.size()];
 333  0
         tmodelList.toArray(entityarr); 
 334  0
         log.debug("After Saving TModel. Obtained vector size:" + entityarr != null ? entityarr.length : 0);
 335  0
         for (int i = 0; entityarr != null && i < entityarr.length; i++) {
 336  0
             TModel tm = (TModel) entityarr[i];
 337  0
             coll.add(new KeyImpl(tm.getTModelKey()));
 338  
         }
 339  
 
 340  0
         bulk.setCollection(coll);
 341  0
         bulk.setExceptions(exceptions);
 342  
 
 343  0
         return bulk;
 344  
     }
 345  
 
 346  
     public BulkResponse saveConcepts(Collection concepts) throws JAXRException {
 347  
         //Now we need to convert the collection into a vector for juddi
 348  0
         BulkResponseImpl bulk = new BulkResponseImpl();
 349  0
         TModel[] entityarr = new TModel[concepts.size()];
 350  
 
 351  0
         LinkedHashSet<Key> coll = new LinkedHashSet<Key>();
 352  0
         Collection<Exception> exceptions = new ArrayList<Exception>();
 353  
 
 354  0
         Iterator iter = concepts.iterator();
 355  0
         int currLoc = 0;
 356  0
         while (iter.hasNext()) {
 357  
             try {
 358  0
                 TModel en =
 359  
                         ScoutJaxrUddiV3Helper.getTModelFromJAXRConcept((Concept) iter.next());
 360  0
                 entityarr[currLoc] = en;
 361  0
                 currLoc++;
 362  
             }
 363  0
             catch (ClassCastException ce) {
 364  0
                 throw new UnexpectedObjectException();
 365  0
             }
 366  
         }
 367  0
         log.debug("Method:save_concept: ENlength=" + entityarr.length);
 368  
         // Save business
 369  0
         TModelDetail td = null;
 370  
         try {
 371  0
             td = (TModelDetail) executeOperation(entityarr, "SAVE_TMODEL");
 372  
         }
 373  0
         catch (RegistryV3Exception e) {
 374  0
             exceptions.add(new SaveException(e.getLocalizedMessage()));
 375  0
             bulk.setStatus(JAXRResponse.STATUS_FAILURE);
 376  0
             return bulk;
 377  0
         }
 378  
 
 379  0
         List<TModel> tmodelList = td.getTModel();
 380  0
         entityarr = new TModel[tmodelList.size()];
 381  0
         tmodelList.toArray(entityarr);
 382  
         
 383  0
         log.debug("After Saving TModel. Obtained vector size:" + entityarr != null ? entityarr.length : 0);
 384  0
         for (int i = 0; entityarr != null && i < entityarr.length; i++) {
 385  0
             TModel tm = (TModel) entityarr[i];
 386  0
             coll.add(new KeyImpl(tm.getTModelKey()));
 387  
         }
 388  
 
 389  0
         bulk.setCollection(coll);
 390  0
         bulk.setExceptions(exceptions);
 391  
 
 392  0
         return bulk;
 393  
     }
 394  
 
 395  
     public BulkResponse saveOrganizations(Collection organizations) throws JAXRException {
 396  
         //Now we need to convert the collection into a vector for juddi
 397  0
         BulkResponseImpl bulk = new BulkResponseImpl();
 398  0
         BusinessEntity[] entityarr = new BusinessEntity[organizations.size()];
 399  
 
 400  0
         LinkedHashSet<Key> coll = new LinkedHashSet<Key>();
 401  0
         Collection<Exception> exceptions = new ArrayList<Exception>();
 402  
 
 403  0
         Iterator iter = organizations.iterator();
 404  0
         int currLoc = 0;
 405  0
         while (iter.hasNext()) {
 406  
             try {
 407  0
                 BusinessEntity en =
 408  
                         ScoutJaxrUddiV3Helper.getBusinessEntityFromJAXROrg((Organization) iter.next());
 409  0
                 entityarr[currLoc] = en;
 410  0
                 currLoc++;
 411  
             }
 412  0
             catch (ClassCastException ce) {
 413  0
                 throw new UnexpectedObjectException();
 414  0
             }
 415  
         }
 416  0
         log.debug("Method:save_business: ENlength=" + entityarr.length);
 417  
         // Save business
 418  0
         BusinessDetail bd = null;
 419  
         try {
 420  0
             bd = (BusinessDetail) executeOperation(entityarr, "SAVE_ORG");
 421  
         }
 422  0
         catch (RegistryV3Exception e) {
 423  0
             exceptions.add(new SaveException(e.getLocalizedMessage()));
 424  0
             bulk.setStatus(JAXRResponse.STATUS_FAILURE);
 425  0
             return bulk;
 426  0
         }
 427  
 
 428  0
         List<BusinessEntity> bizEntityList = bd.getBusinessEntity();
 429  
         
 430  0
         entityarr = new BusinessEntity[bizEntityList.size()];
 431  0
         bizEntityList.toArray(entityarr);
 432  
         
 433  0
         log.debug("After Saving Business. Obtained vector size:" + entityarr != null ? entityarr.length : 0);
 434  0
         for (int i = 0; entityarr != null && i < entityarr.length; i++) {
 435  0
             BusinessEntity entity = (BusinessEntity) entityarr[i];
 436  0
             coll.add(new KeyImpl(entity.getBusinessKey()));
 437  
         }
 438  
 
 439  0
         bulk.setCollection(coll);
 440  0
         bulk.setExceptions(exceptions);
 441  
 
 442  0
         return bulk;
 443  
     }
 444  
 
 445  
     public BulkResponse saveServiceBindings(Collection bindings) throws JAXRException {
 446  0
         BulkResponseImpl bulk = new BulkResponseImpl();
 447  0
         BindingTemplate[] sbarr = new BindingTemplate[bindings.size()];
 448  
 
 449  0
         LinkedHashSet<Key> coll = new LinkedHashSet<Key>();
 450  0
         Collection<Exception> exceptions = new ArrayList<Exception>();
 451  
 
 452  0
         Iterator iter = bindings.iterator();
 453  0
         int currLoc = 0;
 454  0
         while (iter.hasNext()) {
 455  
             try {
 456  0
                 BindingTemplate bs = ScoutJaxrUddiV3Helper.getBindingTemplateFromJAXRSB((ServiceBinding) iter.next());
 457  0
                 sbarr[currLoc] = bs;
 458  0
                 currLoc++;
 459  
             }
 460  0
             catch (ClassCastException ce) {
 461  0
                 throw new UnexpectedObjectException();
 462  0
             }
 463  
         }
 464  
         // Save ServiceBinding
 465  0
         BindingDetail bd = null;
 466  
         try {
 467  0
             bd = (BindingDetail) executeOperation(sbarr, "SAVE_SERVICE_BINDING");
 468  
         }
 469  0
         catch (RegistryV3Exception e) {
 470  0
             exceptions.add(new SaveException(e.getLocalizedMessage()));
 471  0
             bulk.setStatus(JAXRResponse.STATUS_FAILURE);
 472  0
             return bulk;
 473  0
         }
 474  
 
 475  0
         List<BindingTemplate> bindingTemplateList = bd.getBindingTemplate();
 476  0
         sbarr = new BindingTemplate[bindingTemplateList.size()];
 477  0
         bindingTemplateList.toArray(sbarr);
 478  
         
 479  0
         for (int i = 0; sbarr != null && i < sbarr.length; i++) {
 480  0
             BindingTemplate bt = (BindingTemplate) sbarr[i];
 481  0
             coll.add(new KeyImpl(bt.getBindingKey()));
 482  
         }
 483  0
         if (coll.size()>0) {
 484  0
             bulk.setCollection(coll);
 485  
         }
 486  0
         bulk.setExceptions(exceptions);
 487  
 
 488  0
         return bulk;
 489  
     }
 490  
 
 491  
     public BulkResponse saveServices(Collection services) throws JAXRException {
 492  0
         BulkResponseImpl bulk = new BulkResponseImpl();
 493  0
         BusinessService[] sarr = new BusinessService[services.size()];
 494  
 
 495  0
         LinkedHashSet<Key> coll = new LinkedHashSet<Key>();
 496  0
         Collection<Exception> exceptions = new ArrayList<Exception>();
 497  
 
 498  
 
 499  0
         Iterator iter = services.iterator();
 500  0
         int currLoc = 0;
 501  0
         while (iter.hasNext()) {
 502  
             try {
 503  0
                 BusinessService bs = ScoutJaxrUddiV3Helper.getBusinessServiceFromJAXRService((Service) iter.next());
 504  0
                 sarr[currLoc] = bs;
 505  0
                 currLoc++;
 506  
             }
 507  0
             catch (ClassCastException ce) {
 508  0
                 throw new UnexpectedObjectException();
 509  0
             }
 510  
         }
 511  
         // Save Service
 512  0
         ServiceDetail sd = null;
 513  
         try {
 514  0
             sd = (ServiceDetail) executeOperation(sarr, "SAVE_SERVICE");
 515  
         }
 516  0
         catch (RegistryV3Exception e) {
 517  0
             exceptions.add(new SaveException(e.getLocalizedMessage()));
 518  0
             bulk.setStatus(JAXRResponse.STATUS_FAILURE);
 519  0
             return bulk;
 520  0
         }
 521  
 
 522  0
         List<BusinessService> bizServiceList = sd.getBusinessService();
 523  0
         sarr = new BusinessService[bizServiceList.size()];
 524  0
         bizServiceList.toArray(sarr);
 525  
         
 526  0
         for (int i = 0; sarr != null && i < sarr.length; i++) {
 527  0
             BusinessService entity = (BusinessService) sarr[i];
 528  0
             coll.add(new KeyImpl(entity.getServiceKey()));
 529  
         }
 530  0
         bulk.setCollection(coll);
 531  0
         bulk.setExceptions(exceptions);
 532  
 
 533  0
         return bulk;
 534  
     }
 535  
 
 536  
     public void confirmAssociation(Association assoc) throws JAXRException, InvalidRequestException {
 537  
        //Store it in the UDDI registry
 538  0
        HashSet<Association> col = new HashSet<Association>();
 539  0
        col.add(assoc);
 540  0
        BulkResponse br = this.saveAssociations(col, true);
 541  0
        if(br.getExceptions()!= null)
 542  0
           throw new JAXRException("Confiming the Association Failed");
 543  0
     }
 544  
 
 545  
     public void unConfirmAssociation(Association assoc) throws JAXRException, InvalidRequestException {
 546  
        //TODO
 547  
        //Delete it from the UDDI registry
 548  0
        Collection<Key> col = new ArrayList<Key>();
 549  0
        col.add(assoc.getKey());
 550  0
        BulkResponse br = this.deleteAssociations(col);
 551  0
        if(br.getExceptions()!= null)
 552  0
           throw new JAXRException("UnConfiming the Association Failed");
 553  0
     }
 554  
 
 555  
     //Protected Methods
 556  
     protected Object executeOperation(Object dataarray, String op)
 557  
             throws RegistryV3Exception, JAXRException {
 558  0
         if (registry == null) {
 559  0
             throw new IllegalStateException("No registry");
 560  
         }
 561  
 
 562  0
         IRegistryV3 ireg = (IRegistryV3) registry.getRegistry();
 563  
         
 564  0
         ConnectionImpl connection = registry.getConnection();
 565  0
         AuthToken token = getAuthToken(connection, ireg);
 566  0
         if (token == null) {
 567  0
             throw new IllegalStateException("No auth token returned");
 568  
         }
 569  
 
 570  
         Object regobj;
 571  0
         if(op.equalsIgnoreCase("SAVE_ASSOCIATION"))
 572  
         {
 573  0
             regobj = ireg.setPublisherAssertions(token.getAuthInfo(), (PublisherAssertion[]) dataarray);
 574  
         } else
 575  0
         if (op.equalsIgnoreCase("SAVE_SERVICE")) {
 576  0
             regobj = ireg.saveService(token.getAuthInfo(), (BusinessService[])dataarray);
 577  
         }
 578  0
         else if (op.equalsIgnoreCase("SAVE_SERVICE_BINDING")) {
 579  0
             regobj = ireg.saveBinding(token.getAuthInfo(), (BindingTemplate[]) dataarray);
 580  
         }
 581  0
         else if (op.equalsIgnoreCase("SAVE_ORG")) {
 582  0
             regobj = ireg.saveBusiness(token.getAuthInfo(), (BusinessEntity[]) dataarray);
 583  
         }
 584  0
         else if (op.equalsIgnoreCase("SAVE_TMODEL")) {
 585  0
             regobj = ireg.saveTModel(token.getAuthInfo(), (TModel[]) dataarray);
 586  
         }
 587  0
         else if (op.equalsIgnoreCase("DELETE_ORG")) {
 588  0
             clearPublisherAssertions(token.getAuthInfo(), ireg);
 589  0
             regobj = ireg.deleteBusiness(token.getAuthInfo(), (String[]) dataarray);
 590  
         }
 591  0
         else if (op.equalsIgnoreCase("DELETE_SERVICE")) {
 592  0
             regobj = ireg.deleteService(token.getAuthInfo(), (String[]) dataarray);
 593  
         }
 594  0
         else if (op.equalsIgnoreCase("DELETE_SERVICEBINDING")) {
 595  0
             regobj = ireg.deleteBinding(token.getAuthInfo(), (String[]) dataarray);
 596  
         }
 597  0
         else if (op.equalsIgnoreCase("DELETE_CONCEPT")) {
 598  0
             regobj = ireg.deleteTModel(token.getAuthInfo(), (String[]) dataarray);
 599  
         }
 600  0
         else if (op.equalsIgnoreCase("DELETE_ASSOCIATION")) {
 601  0
            int len = ((String[]) dataarray).length;
 602  0
             PublisherAssertion[] paarr = new PublisherAssertion[len];
 603  0
             for(int i=0;i<len;i++)
 604  
             {
 605  0
                String keystr = ((String[])dataarray)[i];
 606  0
                paarr[i] = ScoutJaxrUddiV3Helper.getPubAssertionFromJAXRAssociationKey(keystr);
 607  
             }
 608  0
             regobj = ireg.deletePublisherAssertions(token.getAuthInfo(), paarr);
 609  0
         }
 610  0
         else if (op.equalsIgnoreCase("DELETE_CLASSIFICATIONSCHEME")) {
 611  0
             regobj = ireg.deleteTModel(token.getAuthInfo(), (String[]) dataarray);
 612  
         }
 613  
         else {
 614  0
             throw new JAXRException("Unsupported operation:" + op);
 615  
         }
 616  
 
 617  0
         return regobj;
 618  
     }
 619  
 
 620  
     private void clearPublisherAssertions( String authinfo,IRegistryV3 ireg)
 621  
     {
 622  0
        Vector<PublisherAssertion> pasvect  = null;
 623  0
        PublisherAssertion[] pasarr  = null;
 624  
        try
 625  
        {
 626  0
           AssertionStatusReport report = ireg.getAssertionStatusReport(authinfo,"status:complete");
 627  0
           List<AssertionStatusItem> assertionStatusItemList = report.getAssertionStatusItem();
 628  0
           AssertionStatusItem[] assertionStatusItemArr = 
 629  
                   new AssertionStatusItem[assertionStatusItemList.size()];
 630  
 
 631  0
           int len = assertionStatusItemArr != null? assertionStatusItemArr.length : 0;
 632  0
           for (int i = 0; i < len; i++)
 633  
           {
 634  0
                 AssertionStatusItem asi = assertionStatusItemArr[i];
 635  
                /* String sourceKey = asi.getFromKey();
 636  
                 String targetKey = asi.getToKey();
 637  
                 PublisherAssertion pa = new PublisherAssertion();
 638  
                 pa.setFromKey(sourceKey);
 639  
                 pa.setToKey(targetKey);
 640  
                 KeyedReference keyr = asi.getKeyedReference();
 641  
                 pa.setKeyedReference(keyr);
 642  
                 pa.setTModelKey(keyr.getTModelKey());
 643  
                 pa.setKeyName(keyr.getKeyName());
 644  
                 pa.setKeyValue(keyr.getKeyValue());
 645  
                 if(pasvect == null) pasvect = new Vector(len);
 646  
                 pasvect.add(pa);*/
 647  0
                 if(pasvect == null) pasvect = new Vector<PublisherAssertion>(len);
 648  0
                 pasvect.add(this.getPublisherAssertion(asi));
 649  
            }
 650  0
           report = ireg.getAssertionStatusReport(authinfo,"status:toKey_incomplete");
 651  0
           assertionStatusItemArr = report.getAssertionStatusItem().toArray(assertionStatusItemArr);
 652  
 
 653  0
           len = assertionStatusItemArr != null? assertionStatusItemArr.length : 0;
 654  0
           for (int i = 0; i < len; i++)
 655  
           {
 656  0
                 AssertionStatusItem asi = (AssertionStatusItem) assertionStatusItemArr[i];
 657  0
                 if(pasvect == null) pasvect = new Vector<PublisherAssertion>(len);
 658  0
                 pasvect.add(this.getPublisherAssertion(asi));
 659  
           }
 660  
 
 661  0
           report = ireg.getAssertionStatusReport(authinfo,"status:fromKey_incomplete");
 662  0
           assertionStatusItemArr = report.getAssertionStatusItem().toArray(assertionStatusItemArr);
 663  
 
 664  0
           len = assertionStatusItemArr != null? assertionStatusItemArr.length : 0;
 665  0
           for (int i = 0; i < len; i++)
 666  
           {
 667  0
                 AssertionStatusItem asi = (AssertionStatusItem) assertionStatusItemArr[i];
 668  0
                 if(pasvect == null) pasvect = new Vector<PublisherAssertion>(len);
 669  0
                 pasvect.add(this.getPublisherAssertion(asi));
 670  
           }
 671  
 
 672  0
           if (pasvect != null) {
 673  0
                   pasarr = new PublisherAssertion[pasvect.size()];
 674  0
                   Iterator iter = pasvect.iterator();
 675  0
                   int pasarrPos = 0;
 676  0
                   while (iter.hasNext()) {
 677  0
                           pasarr[pasarrPos] = ((PublisherAssertion) iter.next());
 678  0
                           pasarrPos++;
 679  
                   }
 680  
           }
 681  
        }
 682  0
        catch (RegistryV3Exception e)
 683  
        {
 684  0
           throw new RuntimeException(e);
 685  0
        }
 686  
 
 687  0
           if(pasarr != null && pasarr.length > 0)
 688  
              try
 689  
              {
 690  0
                 ireg.deletePublisherAssertions(authinfo, pasarr);
 691  
              }
 692  0
              catch (RegistryV3Exception e)
 693  
              { 
 694  0
                 log.debug("Ignoring exception " + e.getMessage(),e);
 695  0
              }
 696  0
        }
 697  
 
 698  
 
 699  
 
 700  
     protected BulkResponse deleteOperation(Collection<Key> keys, String op)
 701  
             throws JAXRException {
 702  0
         if(keys == null)
 703  0
         throw new JAXRException("Keys provided to "+op+" are null");
 704  
        
 705  
         //Now we need to convert the collection into a vector for juddi
 706  0
         BulkResponseImpl bulk = new BulkResponseImpl();
 707  0
         String[] keyarr = new String[keys.size()];
 708  
         Result[] keyResultArr;
 709  
 
 710  0
         LinkedHashSet<Key> coll = new LinkedHashSet<Key>();
 711  0
         Collection<Exception> exceptions = new ArrayList<Exception>();
 712  
 
 713  
         try {
 714  0
             Iterator iter = keys.iterator();
 715  0
             int currLoc = 0;
 716  0
             while (iter.hasNext()) {
 717  0
                 Key key = (Key) iter.next();
 718  0
                 keyarr[currLoc] = key.getId();
 719  0
                 currLoc++;
 720  0
             }
 721  
             // Save business
 722  0
             DispositionReport bd = (DispositionReport) executeOperation(keyarr, op);
 723  0
             List<Result> resultList = bd.getResult();
 724  0
             keyResultArr = new Result[resultList.size()];
 725  0
             resultList.toArray(keyResultArr); 
 726  
             
 727  0
             log.debug("After deleting Business. Obtained vector size:" + keyResultArr != null ? keyResultArr.length : 0);
 728  0
             for (int i = 0; keyResultArr != null && i < keyResultArr.length; i++) {
 729  0
                 Result result = (Result) keyResultArr[i];
 730  0
                 int errno = result.getErrno();
 731  0
                 if (errno == 0) {
 732  0
                     coll.addAll(keys);
 733  
                 }
 734  
                 else {
 735  0
                     ErrInfo errinfo = result.getErrInfo();
 736  0
                     DeleteException de = new DeleteException(errinfo.getErrCode() + ":" + errinfo.getValue());
 737  0
                     bulk.setStatus(JAXRResponse.STATUS_FAILURE);
 738  0
                     exceptions.add(de);
 739  
                 }
 740  
             }
 741  
         }
 742  0
         catch (RegistryV3Exception regExcept) {
 743  
 
 744  
             /*
 745  
              * jUDDI (and prollie others) throw an exception on any fault in
 746  
              * the transaction w/ the registry, so we don't get any partial
 747  
              * success
 748  
              */
 749  0
             DeleteException de = new DeleteException(regExcept.getFaultCode()
 750  
                     + ":" + regExcept.getFaultString(), regExcept);
 751  
 
 752  0
             bulk.setStatus(JAXRResponse.STATUS_FAILURE);
 753  0
             exceptions.add(de);
 754  
         }
 755  0
         catch (JAXRException tran) {
 756  0
             exceptions.add(new JAXRException("Apache JAXR Impl:", tran));
 757  0
             bulk.setStatus(JAXRResponse.STATUS_FAILURE);
 758  0
         }
 759  
 
 760  0
         bulk.setCollection(coll);
 761  0
         bulk.setExceptions(exceptions);
 762  
 
 763  0
         return bulk;
 764  
     }
 765  
 
 766  
 
 767  
     /**
 768  
      * Get the Auth Token from the registry
 769  
      *
 770  
      * @param connection
 771  
      * @param ireg
 772  
      * @return auth token
 773  
      * @throws JAXRException
 774  
      */
 775  
     private AuthToken getAuthToken(ConnectionImpl connection, IRegistryV3 ireg)
 776  
             throws JAXRException {
 777  0
         Set creds = connection.getCredentials();
 778  0
         String username = "", pwd = "";
 779  0
         if (creds != null) {
 780  0
                 Iterator it = creds.iterator();
 781  0
                 while (it.hasNext()) {
 782  0
                         PasswordAuthentication pass = (PasswordAuthentication) it.next();
 783  0
                         username = pass.getUserName();
 784  0
                         pwd = new String(pass.getPassword());
 785  0
                 }
 786  
         }
 787  
 
 788  0
         AuthToken token = null;
 789  
         try {
 790  0
             token = ireg.getAuthToken(username, pwd);
 791  
         }
 792  0
         catch (Exception e)
 793  
         { 
 794  0
             throw new JAXRException(e);
 795  0
         }
 796  0
         return token;
 797  
     }
 798  
 
 799  
     private PublisherAssertion getPublisherAssertion(AssertionStatusItem asi)
 800  
     {
 801  0
             PublisherAssertion pa = this.objectFactory.createPublisherAssertion();
 802  
         
 803  0
             if(asi != null)
 804  
             {
 805  0
             String sourceKey = asi.getFromKey();
 806  0
             String targetKey = asi.getToKey();
 807  
         
 808  0
             if (sourceKey != null) {
 809  0
             pa.setFromKey(sourceKey);
 810  
             }
 811  
             
 812  0
             if (targetKey != null) {
 813  0
             pa.setToKey(targetKey);
 814  
             }
 815  
             
 816  0
             KeyedReference keyr = asi.getKeyedReference();
 817  
             
 818  0
             if (keyr != null) {
 819  0
             pa.setKeyedReference(keyr);
 820  
             }
 821  
             //pa.setTModelKey(keyr.getTModelKey());
 822  
             //pa.setKeyName(keyr.getKeyName());
 823  
             //pa.setKeyValue(keyr.getKeyValue()); // -CBC- These are redundant?
 824  
                     
 825  0
             }return pa;
 826  
     }
 827  
     
 828  
     Organization createOrganization(BusinessDetail bizDetail) throws JAXRException {
 829  0
         return ScoutUddiV3JaxrHelper.getOrganization(bizDetail, this);
 830  
     }    
 831  
     
 832  
     Organization createOrganization(BusinessInfo bizInfo) throws JAXRException {
 833  0
         String key = bizInfo.getBusinessKey();
 834  0
         List<Name> names = bizInfo.getName(); 
 835  
         
 836  0
         List<Description> descriptions = bizInfo.getDescription();
 837  0
         List<ServiceInfo> serviceInfos = bizInfo.getServiceInfos().getServiceInfo();
 838  
         
 839  0
         OrganizationImpl org = new OrganizationImpl(this);
 840  0
         org.setKey(createKey(key));
 841  0
         if (names != null && names.size() > 0) {
 842  0
             org.setName(createInternationalString(names.get(0).getValue()));
 843  
         }
 844  0
         if (descriptions != null && descriptions.size() > 0) {
 845  0
             org.setDescription(createInternationalString(descriptions.get(0).getValue()));
 846  
         }
 847  0
         if (serviceInfos != null && serviceInfos.size() > 0) {
 848  0
             List<Service> services = new ArrayList<Service>(serviceInfos.size());
 849  0
             for (int i = 0; i < serviceInfos.size(); i++) {
 850  0
                 ServiceInfo serviceInfo = serviceInfos.get(i);
 851  0
                 services.add(createService(serviceInfo));
 852  
             }
 853  0
             org.addServices(services);
 854  
         }
 855  
 
 856  0
         return org;
 857  
     }
 858  
 
 859  
     Service createService(ServiceInfo serviceInfo) throws JAXRException {
 860  0
         String key = serviceInfo.getServiceKey();
 861  0
         List<Name> names = serviceInfo.getName();
 862  0
         ServiceImpl service = new ServiceImpl(this);
 863  0
         service.setKey(createKey(key));
 864  0
         if (names != null && names.size() > 0) {
 865  0
             service.setName(createInternationalString(names.get(0).getValue()));
 866  
         }
 867  0
         return service;
 868  
     }
 869  
 
 870  
 }