This project has retired. For details please refer to its Attic page.
RegistryObjectImpl xref
View Javadoc
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      private InternationalString name = new InternationalStringImpl();
51      private InternationalString desc = new InternationalStringImpl();
52  
53      private Set<Classification> classifications = new HashSet<Classification>();
54      private Set<Association> associations = new HashSet<Association>();
55      private Set<ExternalIdentifier> externalIds = new HashSet<ExternalIdentifier>();
56      private Set<ExternalLink> externalLinks = new HashSet<ExternalLink>();
57  
58      //TODO never assigned
59      private OrganizationImpl submittingOrganization;
60  
61      public RegistryObjectImpl(LifeCycleManager lifeCycleManager)
62      {
63          this.lifeCycleManager = lifeCycleManager;
64      }
65  
66      public RegistryObjectImpl(LifeCycleManager lifeCycleManager, InternationalString n)
67      {
68          this.lifeCycleManager = lifeCycleManager;
69          name = n;
70      }
71  
72      public Key getKey()
73      {
74          return key;
75      }
76  
77      public InternationalString getDescription()
78      {
79          return desc;
80      }
81  
82      public void setDescription(InternationalString description)
83      {
84          this.desc = description;
85      }
86  
87      public InternationalString getName()
88      {
89          return name;
90      }
91  
92      public void setName(InternationalString name)
93      {
94          this.name = name;
95      }
96  
97      public void setKey(Key k)
98      {
99          key = k;
100     }
101 
102     public String toXML() throws JAXRException
103     {
104         throw new UnsupportedCapabilityException("toXML is not supported");
105     }
106 
107     public void addClassification(Classification classification)
108     {
109         classifications.add(classification);
110     }
111 
112     public void addClassifications(Collection collection)
113     {
114         if (collection!=null) {
115             for (Object classification : collection) {
116                 classifications.add((Classification)classification);
117             }
118         }
119     }
120 
121     public void removeClassification(Classification classification)
122     {
123         classifications.remove(classification);
124     }
125 
126     public void removeClassifications(Collection collection)
127     {
128         classifications.removeAll(collection);
129     }
130 
131     public Collection getClassifications()
132     {
133         return Collections.unmodifiableSet(classifications);
134     }
135 
136     public void setClassifications(Collection collection)
137     {
138         Set<Classification> newClassifications = new HashSet<Classification>(collection.size());
139         for (Object classification : collection) {
140             newClassifications.add((Classification) classification);
141         }
142         classifications = newClassifications;
143     }
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         associations.add(association);
157 
158         association.setSourceObject(this);
159     }
160 
161     public void addAssociations(Collection collection) throws JAXRException
162     {
163         for (Object association : collection) {
164             addAssociation((Association) association);
165         }
166     }
167 
168     public Collection<Association> getAssociations() throws JAXRException
169     {
170         return Collections.unmodifiableSet(associations);
171     }
172 
173     public void setAssociations(Collection collection)
174     {
175         Set<Association> newAssociations = new HashSet<Association>(collection.size());
176         for (Object association : collection) {
177             newAssociations.add((Association) association);
178         }
179         associations = newAssociations;
180     }
181 
182     public void removeAssociation(Association association)
183     {
184         associations.remove(association);
185     }
186 
187     public void removeAssociations(Collection collection)
188     {
189         associations.removeAll(collection);
190     }
191 
192     public void addExternalIdentifier(ExternalIdentifier externalIdentifier)
193     {
194         externalIds.add(externalIdentifier);
195         ((ExternalIdentifierImpl) externalIdentifier).setRegistryObject(this);
196     }
197 
198     public void addExternalIdentifiers(Collection collection)
199     {
200         if (collection!=null) {
201             for (Object externalId : collection) {
202                 externalIds.add((ExternalIdentifier) externalId);
203                 ((ExternalIdentifierImpl) externalId).setRegistryObject(this);
204             }
205         }
206     }
207 
208     public void removeExternalIdentifier(ExternalIdentifier externalIdentifier)
209     {
210         externalIds.remove(externalIdentifier);
211         ((ExternalIdentifierImpl) externalIdentifier).setRegistryObject(null);
212     }
213 
214     public void removeExternalIdentifiers(Collection collection)
215     {
216         //Lets clear out the reference to this in the ext id
217         Iterator iter = collection.iterator();
218         while (iter != null && iter.hasNext())
219         {
220             ExternalIdentifier externalId = (ExternalIdentifier) iter.next();
221             ((ExternalIdentifierImpl) externalId).setRegistryObject(null);
222         }
223         externalIds.removeAll(collection);
224     }
225 
226     public Collection<ExternalIdentifier> getExternalIdentifiers()
227     {
228         return Collections.unmodifiableSet(externalIds);
229     }
230 
231     public void setExternalIdentifiers(Collection collection)
232     {
233         Set<ExternalIdentifier> newExternalIds = new HashSet<ExternalIdentifier>(collection.size());
234         for (Object externalId : collection) {
235             newExternalIds.add((ExternalIdentifier) externalId);
236         }
237         externalIds = newExternalIds;
238     }
239 
240     public void addExternalLink(ExternalLink externalLink)
241     {
242         externalLinks.add(externalLink);
243         ((ExternalLinkImpl) externalLink).addLinkedObject(this);
244     }
245 
246     public void addExternalLinks(Collection collection)
247     {
248         for (Object externalLink : collection) {
249             externalLinks.add((ExternalLink) externalLink);
250             ((ExternalLinkImpl) externalLink).addLinkedObject(this);
251         }
252     }
253 
254     public void removeExternalLink(ExternalLink externalLink)
255     {
256         ((ExternalLinkImpl) externalLink).removeLinkedObject(this);
257         externalLinks.remove(externalLink);
258     }
259 
260     public void removeExternalLinks(Collection collection)
261     {
262         Iterator iter = collection.iterator();
263         while (iter != null && iter.hasNext())
264         {
265             ExternalLink externalLink = (ExternalLink) iter.next();
266             ((ExternalLinkImpl) externalLink).removeLinkedObject(this);
267         }
268         externalLinks.removeAll(collection);
269     }
270 
271     public Collection<ExternalLink> getExternalLinks()
272     {
273         return Collections.unmodifiableSet(externalLinks);
274     }
275 
276     public void setExternalLinks(Collection collection)
277     {
278         Set<ExternalLink> newExternalLinks = new HashSet<ExternalLink>(collection.size());
279         for (Object externalLink : collection) {
280             newExternalLinks.add((ExternalLink) externalLink);
281         }
282         externalLinks = newExternalLinks;
283     }
284 
285     public Organization getSubmittingOrganization()
286     {
287         return submittingOrganization;
288     }
289 
290     public LifeCycleManager getLifeCycleManager()
291     {
292         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         if (obj == this) return true;
306         if (obj == null || !this.getClass().equals(obj.getClass())) return false;
307         final RegistryObjectImpl/../../org/apache/ws/scout/registry/infomodel/RegistryObjectImpl.html#RegistryObjectImpl">RegistryObjectImpl other = (RegistryObjectImpl) obj;
308         return this.key != null && key.equals(other.key);
309     }
310 
311     public int hashCode()
312     {
313         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         throw new UnsupportedCapabilityException("Level 1 feature");
323     }
324 
325     public Collection getAssociatedObjects() throws JAXRException
326     {
327         throw new UnsupportedCapabilityException("Level 1 feature");
328     }
329 
330     public Concept getObjectType() throws JAXRException
331     {
332         throw new UnsupportedCapabilityException("Level 1 feature");
333     }
334 
335     public Collection getRegistryPackages() throws JAXRException
336     {
337         throw new UnsupportedCapabilityException("Level 1 feature");
338     }
339 }