This project has retired. For details please refer to its Attic page.
ConceptImpl 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.ArrayList;
20  import java.util.Collection;
21  import java.util.Iterator;
22  
23  import javax.xml.registry.JAXRException;
24  import javax.xml.registry.LifeCycleManager;
25  import javax.xml.registry.infomodel.ClassificationScheme;
26  import javax.xml.registry.infomodel.Concept;
27  import javax.xml.registry.infomodel.RegistryObject;
28  
29  /**
30   * Implements JAXR Interface.
31   * For futher details, look into the JAXR API Javadoc.
32   *
33   * @author Anil Saldhana  <anil@apache.org>
34   */
35  public class ConceptImpl extends RegistryObjectImpl implements Concept
36  {
37      private String value = new String();
38  
39      private RegistryObject parent = null;
40      private Concept parentconcept = null;
41  
42      private ClassificationScheme scheme = null;
43      private Collection<Concept> childconcepts = new ArrayList<Concept>();
44  
45      /**
46       * Creates a new instance of ConceptImpl
47       */
48      public ConceptImpl(LifeCycleManager lifeCycleManager)
49      {
50          super(lifeCycleManager);
51      }
52  
53      public void addChildConcept(Concept concept)
54      {
55          this.childconcepts.add(concept);
56          ((ConceptImpl)concept).setParentconcept(this);
57      }
58  
59      public void addChildConcepts(Collection collection)
60      {
61          for (Object c : collection) {
62              ((ConceptImpl) c).setParentconcept(this);
63              childconcepts.add((Concept) c);
64          }
65  
66      }
67  
68      public int getChildConceptCount()
69      {
70          return this.childconcepts.size();                                                                                                           
71      }
72  
73      public Collection<Concept> getChildrenConcepts()
74      {
75          return this.childconcepts;
76      }
77  
78      public ClassificationScheme getClassificationScheme()
79      {
80          return scheme;
81      }
82  
83      public Collection<Concept> getDescendantConcepts()
84      {
85          Collection<Concept> coll = new ArrayList<Concept>();
86          Iterator iter = childconcepts.iterator();
87          while(iter != null && iter.hasNext())
88          {
89              ConceptImpl../../../../../../org/apache/ws/scout/registry/infomodel/ConceptImpl.html#ConceptImpl">ConceptImpl c = (ConceptImpl)iter.next();
90              coll.add(c);
91              coll.addAll(c.getDescendantConcepts());
92          }
93          return coll;
94      }
95  
96      public RegistryObject getParent()
97      {
98          return parent;
99      }
100 
101     public Concept getParentConcept()
102     {
103         return parentconcept;
104     }
105 
106     public String getPath()
107     {
108         return null;
109     }
110 
111     public String getValue() throws JAXRException
112     {
113         return value;
114     }
115 
116     public void removeChildConcept(Concept c)
117     {
118         ((ConceptImpl)c).setParentconcept(null);
119         childconcepts.remove(c);
120     }
121 
122     public void removeChildConcepts(Collection collection)
123     {
124         Iterator iter = collection.iterator();
125         while(iter.hasNext())
126         {
127             Concept c = (Concept)iter.next();
128             ((ConceptImpl)c).setParentconcept(null);
129             childconcepts.add(c);
130         }
131     }
132 
133     public void setValue(String str)
134     {
135         value = str;
136     }
137 
138     public void setParent(RegistryObject parent)
139     {
140         this.parent = parent;
141     }
142 
143     public void setParentconcept(Concept parentconcept)
144     {
145         this.parentconcept = parentconcept;
146         parent = null; //We deal with concept as parent
147     }
148 
149     public void setScheme(ClassificationSchemeImpl scheme)
150     {
151         this.scheme = scheme;
152     }
153 
154     public void setChildconcepts(Collection<Concept> childconcepts)
155     {
156         this.childconcepts.clear();
157         Iterator iter = childconcepts.iterator();
158         while(iter.hasNext())
159         {
160             Concept c = (Concept)iter.next();
161             ((ConceptImpl)c).setParentconcept(this);
162             childconcepts.add(c);
163         }
164     }
165 
166     //Specific API
167     public void setClassificationScheme(ClassificationScheme sc)
168     {
169         scheme = sc;
170         parent = sc;
171     }
172 }