This project has retired. For details please refer to its Attic page.
Coverage Report
Coverage Report - org.apache.ws.scout.registry.infomodel.OrganizationImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
OrganizationImpl
29%
22/74
10%
3/28
1.963
 
 1  
 /*
 2  
  * Copyright 2001-2004 The Apache Software Foundation.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 
 17  
 package org.apache.ws.scout.registry.infomodel;
 18  
 
 19  
 import java.util.ArrayList;
 20  
 import java.util.Collection;
 21  
 import java.util.HashSet;
 22  
 import java.util.Iterator;
 23  
 import java.util.Set;
 24  
 
 25  
 import javax.xml.registry.JAXRException;
 26  
 import javax.xml.registry.LifeCycleManager;
 27  
 import javax.xml.registry.UnsupportedCapabilityException;
 28  
 import javax.xml.registry.infomodel.Organization;
 29  
 import javax.xml.registry.infomodel.PostalAddress;
 30  
 import javax.xml.registry.infomodel.Service;
 31  
 import javax.xml.registry.infomodel.TelephoneNumber;
 32  
 import javax.xml.registry.infomodel.User;
 33  
 
 34  
 /**
 35  
  * Organization Interface
 36  
  * * Implements JAXR Interface.
 37  
  * For futher details, look into the JAXR API Javadoc.
 38  
  *
 39  
  * @author <a href="mailto:anil@apache.org">Anil Saldhana</a>
 40  
  * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
 41  
  */
 42  
 public class OrganizationImpl extends RegistryObjectImpl implements Organization
 43  
 {
 44  
     private User primaryContact;
 45  115
     private Set<User> users = new HashSet<User>();
 46  115
     private Set<TelephoneNumber> telephoneNumbers = new HashSet<TelephoneNumber>();
 47  115
     private Collection<Service> services = new ArrayList<Service>();
 48  
 
 49  
     public OrganizationImpl(LifeCycleManager lifeCycleManager)
 50  
     {
 51  115
         super(lifeCycleManager);
 52  115
     }
 53  
 
 54  
     public User getPrimaryContact() throws JAXRException
 55  
     {
 56  
         //TODO: How do we fix this? Run JAXRQueryTest and you will hit this problem.
 57  
         //
 58  
         //  gmj : I think I fixed w/ primary contact hack...
 59  
         //
 60  
         //if (primaryContact == null) {
 61  
         //    throw new IllegalStateException("primaryContact is null and the spec says we cannot return a null value");
 62  
         //}
 63  158
         return primaryContact;
 64  
     }
 65  
 
 66  
     public void setPrimaryContact(User user) throws JAXRException
 67  
     {
 68  105
         if (user == null)
 69  
         {
 70  0
             throw new IllegalArgumentException("primaryContact must not be null");
 71  
         }
 72  
 
 73  
         /*
 74  
          * first check to see if user already exists in user set
 75  
          */
 76  
 
 77  105
         primaryContact = user;
 78  
 
 79  105
         if (!users.contains(user)) {
 80  105
             addUser(user);
 81  
         }
 82  105
     }
 83  
 
 84  
     public void addUser(User user) throws JAXRException
 85  
     {
 86  121
         doPrimaryContactHack(user);
 87  
 
 88  121
         users.add(user);
 89  121
         ((UserImpl) user).setOrganization(this);
 90  121
     }
 91  
 
 92  
     /**
 93  
      *
 94  
      *  to solve the getPrimaryContactProblem(), if we have no defined
 95  
      *  primaryContact, we'll designate the first user as such
 96  
      *
 97  
      * @param user
 98  
      */
 99  
     private void doPrimaryContactHack(User user) {
 100  
 
 101  121
         if (primaryContact == null && users.size() == 0) {
 102  0
             primaryContact = user;
 103  
         }
 104  121
     }
 105  
 
 106  
     public void addUsers(Collection collection) throws JAXRException
 107  
     {
 108  
         // do this by hand to ensure all members are actually instances of User
 109  0
         for (Iterator iterator = collection.iterator(); iterator.hasNext();)
 110  
         {
 111  0
             User user = (User) iterator.next();
 112  0
             addUser(user);
 113  0
         }
 114  0
     }
 115  
 
 116  
     public Collection<User> getUsers() throws JAXRException
 117  
     {
 118  38
         return users;
 119  
     }
 120  
 
 121  
     public void removeUser(User user) throws JAXRException
 122  
     {
 123  0
         if (user != null) {
 124  0
             users.remove(user);
 125  
         }
 126  
 
 127  
         /*
 128  
          * more primaryContact hakiness - nothing says that you can't
 129  
          * remove the user that is the PC...
 130  
          */
 131  
 
 132  0
         if (!users.contains(primaryContact)) {
 133  0
             primaryContact = null;
 134  
         }
 135  0
     }
 136  
 
 137  
     public void removeUsers(Collection collection) throws JAXRException
 138  
     {
 139  0
         if (collection != null) {
 140  0
             users.removeAll(collection);
 141  
         }
 142  
 
 143  
         /*
 144  
          * more primaryContact hakiness - nothing says that you can't
 145  
          * remove the user that is the PC...
 146  
          */
 147  
 
 148  0
         if (!users.contains(primaryContact)) {
 149  0
             primaryContact = null;
 150  
         }
 151  
 
 152  0
     }
 153  
 
 154  
     public Collection<TelephoneNumber> getTelephoneNumbers(String phoneType) throws JAXRException
 155  
     {
 156  
         Set<TelephoneNumber> filteredNumbers;
 157  0
         if (phoneType == null)
 158  
         {
 159  0
             filteredNumbers = telephoneNumbers;
 160  
         } else
 161  
         {
 162  0
             filteredNumbers = new HashSet<TelephoneNumber>(telephoneNumbers.size());
 163  0
             for (Iterator i = telephoneNumbers.iterator(); i.hasNext();)
 164  
             {
 165  0
                 TelephoneNumber number = (TelephoneNumber) i.next();
 166  0
                 if (phoneType.equals(number.getType()))
 167  
                 {
 168  0
                     filteredNumbers.add(number);
 169  
                 }
 170  0
             }
 171  
         }
 172  0
         return filteredNumbers;
 173  
     }
 174  
 
 175  
     public void setTelephoneNumbers(Collection collection) throws JAXRException
 176  
     {
 177  
         // do this by hand to ensure all members are actually instances of TelephoneNumber
 178  0
         Set<TelephoneNumber> numbers = new HashSet<TelephoneNumber>(collection.size());
 179  0
         for (Object number : collection) {
 180  0
             numbers.add((TelephoneNumber) number);
 181  0
         }
 182  0
         this.telephoneNumbers = numbers;
 183  0
     }
 184  
 
 185  
     public void addService(Service service) throws JAXRException
 186  
     {
 187  42
         services.add(service);
 188  
 
 189  
         /*
 190  
          * we need to tell the service who it's organization is so
 191  
          * we can set the UDDI Business Key...
 192  
          */
 193  
 
 194  42
         service.setProvidingOrganization(this);
 195  42
     }
 196  
 
 197  
     public void addServices(Collection collection) throws JAXRException
 198  
     {
 199  
         // do this by hand to ensure all members are actually instances of Service
 200  0
         for (Iterator iterator = collection.iterator(); iterator.hasNext();)
 201  
         {
 202  0
             Service service = (Service) iterator.next();
 203  
 
 204  0
             addService(service);
 205  0
         }
 206  0
     }
 207  
 
 208  
     public Collection<Service> getServices() throws JAXRException
 209  
     {
 210  48
         return services;
 211  
     }
 212  
 
 213  
     public void removeService(Service service) throws JAXRException
 214  
     {
 215  0
             services.remove(service);
 216  0
     }
 217  
 
 218  
     public void removeServices(Collection collection) throws JAXRException
 219  
     {
 220  0
         services.removeAll(collection);
 221  0
     }
 222  
 
 223  
     ///////////////////////////////////////////////////////////////////////////
 224  
     // Level 1 features must throw exceptions
 225  
     ///////////////////////////////////////////////////////////////////////////
 226  
 
 227  
     public Organization getParentOrganization() throws JAXRException
 228  
     {
 229  0
         throw new UnsupportedCapabilityException("Level 1 feature");
 230  
     }
 231  
 
 232  
     public Collection<Organization> getDescendantOrganizations() throws JAXRException
 233  
     {
 234  0
         throw new UnsupportedCapabilityException("Level 1 feature");
 235  
     }
 236  
 
 237  
     public Organization getRootOrganization() throws JAXRException
 238  
     {
 239  0
         throw new UnsupportedCapabilityException("Level 1 feature");
 240  
     }
 241  
 
 242  
     public void addChildOrganization(Organization organization) throws JAXRException
 243  
     {
 244  0
         throw new UnsupportedCapabilityException("Level 1 feature");
 245  
     }
 246  
 
 247  
     public void addChildOrganizations(Collection collection) throws JAXRException
 248  
     {
 249  0
         throw new UnsupportedCapabilityException("Level 1 feature");
 250  
     }
 251  
 
 252  
     public int getChildOrganizationCount() throws JAXRException
 253  
     {
 254  0
         throw new UnsupportedCapabilityException("Level 1 feature");
 255  
     }
 256  
 
 257  
     public Collection<Organization> getChildOrganizations() throws JAXRException
 258  
     {
 259  0
         throw new UnsupportedCapabilityException("Level 1 feature");
 260  
     }
 261  
 
 262  
     public void removeChildOrganization(Organization organization) throws JAXRException
 263  
     {
 264  0
         throw new UnsupportedCapabilityException("Level 1 feature");
 265  
     }
 266  
 
 267  
     public void removeChildOrganizations(Collection collection) throws JAXRException
 268  
     {
 269  0
         throw new UnsupportedCapabilityException("Level 1 feature");
 270  
     }
 271  
 
 272  
     public PostalAddress getPostalAddress() throws JAXRException
 273  
     {
 274  0
         throw new UnsupportedCapabilityException("Level 1 feature");
 275  
     }
 276  
 
 277  
     public void setPostalAddress(PostalAddress postalAddress) throws JAXRException
 278  
     {
 279  0
         throw new UnsupportedCapabilityException("Level 1 feature");
 280  
     }
 281  
 }