This project has retired. For details please refer to its Attic page.
Coverage Report
Coverage Report - org.apache.ws.scout.registry.infomodel.RegistryObjectImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
RegistryObjectImpl
43%
53/121
37%
15/40
1.634
 
 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.Collection;
 20  
 import java.util.Collections;
 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.Association;
 29  
 import javax.xml.registry.infomodel.Classification;
 30  
 import javax.xml.registry.infomodel.Concept;
 31  
 import javax.xml.registry.infomodel.ExternalIdentifier;
 32  
 import javax.xml.registry.infomodel.ExternalLink;
 33  
 import javax.xml.registry.infomodel.InternationalString;
 34  
 import javax.xml.registry.infomodel.Key;
 35  
 import javax.xml.registry.infomodel.Organization;
 36  
 import javax.xml.registry.infomodel.RegistryObject;
 37  
 
 38  
 /**
 39  
  * Implements  RegistryObject Interface
 40  
  * Implements JAXR Interface.
 41  
  * For futher details, look into the JAXR API Javadoc.
 42  
  *
 43  
  * @author <a href="mailto:anil@apache.org">Anil Saldhana</a>
 44  
  * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
 45  
  */
 46  
 public class RegistryObjectImpl extends ExtensibleObjectImpl implements RegistryObject
 47  
 {
 48  
     private final LifeCycleManager lifeCycleManager;
 49  
     private Key key;
 50  1001
     private InternationalString name = new InternationalStringImpl();
 51  1001
     private InternationalString desc = new InternationalStringImpl();
 52  
 
 53  1001
     private Set<Classification> classifications = new HashSet<Classification>();
 54  1001
     private Set<Association> associations = new HashSet<Association>();
 55  1001
     private Set<ExternalIdentifier> externalIds = new HashSet<ExternalIdentifier>();
 56  1001
     private Set<ExternalLink> externalLinks = new HashSet<ExternalLink>();
 57  
 
 58  
     //TODO never assigned
 59  
     private OrganizationImpl submittingOrganization;
 60  
 
 61  
     public RegistryObjectImpl(LifeCycleManager lifeCycleManager)
 62  1001
     {
 63  1001
         this.lifeCycleManager = lifeCycleManager;
 64  1001
     }
 65  
 
 66  
     public RegistryObjectImpl(LifeCycleManager lifeCycleManager, InternationalString n)
 67  0
     {
 68  0
         this.lifeCycleManager = lifeCycleManager;
 69  0
         name = n;
 70  0
     }
 71  
 
 72  
     public Key getKey()
 73  
     {
 74  416
         return key;
 75  
     }
 76  
 
 77  
     public InternationalString getDescription()
 78  
     {
 79  204
         return desc;
 80  
     }
 81  
 
 82  
     public void setDescription(InternationalString description)
 83  
     {
 84  268
         this.desc = description;
 85  268
     }
 86  
 
 87  
     public InternationalString getName()
 88  
     {
 89  268
         return name;
 90  
     }
 91  
 
 92  
     public void setName(InternationalString name)
 93  
     {
 94  529
         this.name = name;
 95  529
     }
 96  
 
 97  
     public void setKey(Key k)
 98  
     {
 99  365
         key = k;
 100  365
     }
 101  
 
 102  
     public String toXML() throws JAXRException
 103  
     {
 104  0
         throw new UnsupportedCapabilityException("toXML is not supported");
 105  
     }
 106  
 
 107  
     public void addClassification(Classification classification)
 108  
     {
 109  12
         classifications.add(classification);
 110  12
     }
 111  
 
 112  
     public void addClassifications(Collection collection)
 113  
     {
 114  125
         if (collection!=null) {
 115  30
             for (Object classification : collection) {
 116  30
                 classifications.add((Classification)classification);
 117  30
             }
 118  
         }
 119  125
     }
 120  
 
 121  
     public void removeClassification(Classification classification)
 122  
     {
 123  0
         classifications.remove(classification);
 124  0
     }
 125  
 
 126  
     public void removeClassifications(Collection collection)
 127  
     {
 128  0
         classifications.removeAll(collection);
 129  0
     }
 130  
 
 131  
     public Collection getClassifications()
 132  
     {
 133  110
         return Collections.unmodifiableSet(classifications);
 134  
     }
 135  
 
 136  
     public void setClassifications(Collection collection)
 137  
     {
 138  0
         Set<Classification> newClassifications = new HashSet<Classification>(collection.size());
 139  0
         for (Object classification : collection) {
 140  0
             newClassifications.add((Classification) classification);
 141  0
         }
 142  0
         classifications = newClassifications;
 143  0
     }
 144  
 
 145  
     /**
 146  
      *  Adds specified Association to use this object as source.
 147  
      *  Silently replaces the sourceObject in Association with
 148  
      *  reference to this object.
 149  
      *
 150  
      * @param association association to add
 151  
      * @throws JAXRException
 152  
      */
 153  
     public void addAssociation(Association association)
 154  
         throws JAXRException
 155  
     {
 156  4
         associations.add(association);
 157  
 
 158  4
         association.setSourceObject(this);
 159  4
     }
 160  
 
 161  
     public void addAssociations(Collection collection) throws JAXRException
 162  
     {
 163  0
         for (Object association : collection) {
 164  0
             addAssociation((Association) association);
 165  0
         }
 166  0
     }
 167  
 
 168  
     public Collection<Association> getAssociations() throws JAXRException
 169  
     {
 170  0
         return Collections.unmodifiableSet(associations);
 171  
     }
 172  
 
 173  
     public void setAssociations(Collection collection)
 174  
     {
 175  0
         Set<Association> newAssociations = new HashSet<Association>(collection.size());
 176  0
         for (Object association : collection) {
 177  0
             newAssociations.add((Association) association);
 178  0
         }
 179  0
         associations = newAssociations;
 180  0
     }
 181  
 
 182  
     public void removeAssociation(Association association)
 183  
     {
 184  0
         associations.remove(association);
 185  0
     }
 186  
 
 187  
     public void removeAssociations(Collection collection)
 188  
     {
 189  0
         associations.removeAll(collection);
 190  0
     }
 191  
 
 192  
     public void addExternalIdentifier(ExternalIdentifier externalIdentifier)
 193  
     {
 194  0
         externalIds.add(externalIdentifier);
 195  0
         ((ExternalIdentifierImpl) externalIdentifier).setRegistryObject(this);
 196  0
     }
 197  
 
 198  
     public void addExternalIdentifiers(Collection collection)
 199  
     {
 200  79
         if (collection!=null) {
 201  0
             for (Object externalId : collection) {
 202  0
                 externalIds.add((ExternalIdentifier) externalId);
 203  0
                 ((ExternalIdentifierImpl) externalId).setRegistryObject(this);
 204  0
             }
 205  
         }
 206  79
     }
 207  
 
 208  
     public void removeExternalIdentifier(ExternalIdentifier externalIdentifier)
 209  
     {
 210  0
         externalIds.remove(externalIdentifier);
 211  0
         ((ExternalIdentifierImpl) externalIdentifier).setRegistryObject(null);
 212  0
     }
 213  
 
 214  
     public void removeExternalIdentifiers(Collection collection)
 215  
     {
 216  
         //Lets clear out the reference to this in the ext id
 217  0
         Iterator iter = collection.iterator();
 218  0
         while (iter != null && iter.hasNext())
 219  
         {
 220  0
             ExternalIdentifier externalId = (ExternalIdentifier) iter.next();
 221  0
             ((ExternalIdentifierImpl) externalId).setRegistryObject(null);
 222  0
         }
 223  0
         externalIds.removeAll(collection);
 224  0
     }
 225  
 
 226  
     public Collection<ExternalIdentifier> getExternalIdentifiers()
 227  
     {
 228  74
         return Collections.unmodifiableSet(externalIds);
 229  
     }
 230  
 
 231  
     public void setExternalIdentifiers(Collection collection)
 232  
     {
 233  0
         Set<ExternalIdentifier> newExternalIds = new HashSet<ExternalIdentifier>(collection.size());
 234  0
         for (Object externalId : collection) {
 235  0
             newExternalIds.add((ExternalIdentifier) externalId);
 236  0
         }
 237  0
         externalIds = newExternalIds;
 238  0
     }
 239  
 
 240  
     public void addExternalLink(ExternalLink externalLink)
 241  
     {
 242  77
         externalLinks.add(externalLink);
 243  77
         ((ExternalLinkImpl) externalLink).addLinkedObject(this);
 244  77
     }
 245  
 
 246  
     public void addExternalLinks(Collection collection)
 247  
     {
 248  4
         for (Object externalLink : collection) {
 249  4
             externalLinks.add((ExternalLink) externalLink);
 250  4
             ((ExternalLinkImpl) externalLink).addLinkedObject(this);
 251  4
         }
 252  4
     }
 253  
 
 254  
     public void removeExternalLink(ExternalLink externalLink)
 255  
     {
 256  0
         ((ExternalLinkImpl) externalLink).removeLinkedObject(this);
 257  0
         externalLinks.remove(externalLink);
 258  0
     }
 259  
 
 260  
     public void removeExternalLinks(Collection collection)
 261  
     {
 262  0
         Iterator iter = collection.iterator();
 263  0
         while (iter != null && iter.hasNext())
 264  
         {
 265  0
             ExternalLink externalLink = (ExternalLink) iter.next();
 266  0
             ((ExternalLinkImpl) externalLink).removeLinkedObject(this);
 267  0
         }
 268  0
         externalLinks.removeAll(collection);
 269  0
     }
 270  
 
 271  
     public Collection<ExternalLink> getExternalLinks()
 272  
     {
 273  44
         return Collections.unmodifiableSet(externalLinks);
 274  
     }
 275  
 
 276  
     public void setExternalLinks(Collection collection)
 277  
     {
 278  6
         Set<ExternalLink> newExternalLinks = new HashSet<ExternalLink>(collection.size());
 279  6
         for (Object externalLink : collection) {
 280  6
             newExternalLinks.add((ExternalLink) externalLink);
 281  6
         }
 282  6
         externalLinks = newExternalLinks;
 283  6
     }
 284  
 
 285  
     public Organization getSubmittingOrganization()
 286  
     {
 287  0
         return submittingOrganization;
 288  
     }
 289  
 
 290  
     public LifeCycleManager getLifeCycleManager()
 291  
     {
 292  20
         return lifeCycleManager;
 293  
     }
 294  
 
 295  
     /**
 296  
      * The spec does not define how equality is defined for RegistryObject's.
 297  
      * We choose to define it as having the same class and key value; if the
 298  
      * key is null then the objects are not equal.
 299  
      *
 300  
      * @param obj the object to compare to
 301  
      * @return true if the other object is of the same class and has the same key value
 302  
      */
 303  
     public boolean equals(Object obj)
 304  
     {
 305  30
         if (obj == this) return true;
 306  30
         if (obj == null || !this.getClass().equals(obj.getClass())) return false;
 307  30
         final RegistryObjectImpl other = (RegistryObjectImpl) obj;
 308  30
         return this.key != null && key.equals(other.key);
 309  
     }
 310  
 
 311  
     public int hashCode()
 312  
     {
 313  479
         return key == null ? 0 : key.hashCode();
 314  
     }
 315  
 
 316  
     ///////////////////////////////////////////////////////////////////////////
 317  
     // Level 1 features must throw exceptions
 318  
     ///////////////////////////////////////////////////////////////////////////
 319  
 
 320  
     public Collection getAuditTrail() throws JAXRException
 321  
     {
 322  0
         throw new UnsupportedCapabilityException("Level 1 feature");
 323  
     }
 324  
 
 325  
     public Collection getAssociatedObjects() throws JAXRException
 326  
     {
 327  0
         throw new UnsupportedCapabilityException("Level 1 feature");
 328  
     }
 329  
 
 330  
     public Concept getObjectType() throws JAXRException
 331  
     {
 332  0
         throw new UnsupportedCapabilityException("Level 1 feature");
 333  
     }
 334  
 
 335  
     public Collection getRegistryPackages() throws JAXRException
 336  
     {
 337  0
         throw new UnsupportedCapabilityException("Level 1 feature");
 338  
     }
 339  
 }