001: /*
002: * Copyright 2001-2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.apache.ws.scout.registry.infomodel;
018:
019: import java.util.ArrayList;
020: import java.util.Collection;
021: import java.util.Iterator;
022:
023: import javax.xml.registry.JAXRException;
024: import javax.xml.registry.LifeCycleManager;
025: import javax.xml.registry.infomodel.ClassificationScheme;
026: import javax.xml.registry.infomodel.Concept;
027: import javax.xml.registry.infomodel.RegistryObject;
028:
029: /**
030: * Implements JAXR Interface.
031: * For futher details, look into the JAXR API Javadoc.
032: *
033: * @author Anil Saldhana <anil@apache.org>
034: */
035: public class ConceptImpl extends RegistryObjectImpl implements Concept {
036: private String value = new String();
037:
038: private RegistryObject parent = null;
039: private Concept parentconcept = null;
040:
041: private ClassificationScheme scheme = null;
042: private Collection<Concept> childconcepts = new ArrayList<Concept>();
043:
044: /**
045: * Creates a new instance of ConceptImpl
046: */
047: public ConceptImpl(LifeCycleManager lifeCycleManager) {
048: super (lifeCycleManager);
049: }
050:
051: public void addChildConcept(Concept concept) {
052: this .childconcepts.add(concept);
053: ((ConceptImpl) concept).setParentconcept(this );
054: }
055:
056: public void addChildConcepts(Collection<Concept> collection) {
057: Iterator iter = collection.iterator();
058: while (iter.hasNext()) {
059: Concept c = (Concept) iter.next();
060: ((ConceptImpl) c).setParentconcept(this );
061: childconcepts.add(c);
062: }
063:
064: }
065:
066: public int getChildConceptCount() {
067: return this .childconcepts.size();
068: }
069:
070: public Collection<Concept> getChildrenConcepts() {
071: return this .childconcepts;
072: }
073:
074: public ClassificationScheme getClassificationScheme() {
075: return scheme;
076: }
077:
078: public Collection<Concept> getDescendantConcepts() {
079: Collection<Concept> coll = new ArrayList<Concept>();
080: Iterator iter = childconcepts.iterator();
081: while (iter != null && iter.hasNext()) {
082: ConceptImpl c = (ConceptImpl) iter.next();
083: coll.add(c);
084: coll.addAll(c.getDescendantConcepts());
085: }
086: return coll;
087: }
088:
089: public RegistryObject getParent() {
090: return parent;
091: }
092:
093: public Concept getParentConcept() {
094: return parentconcept;
095: }
096:
097: public String getPath() {
098: return null;
099: }
100:
101: public String getValue() throws JAXRException {
102: return value;
103: }
104:
105: public void removeChildConcept(Concept c) {
106: ((ConceptImpl) c).setParentconcept(null);
107: childconcepts.remove(c);
108: }
109:
110: public void removeChildConcepts(Collection collection) {
111: Iterator iter = collection.iterator();
112: while (iter.hasNext()) {
113: Concept c = (Concept) iter.next();
114: ((ConceptImpl) c).setParentconcept(null);
115: childconcepts.add(c);
116: }
117: }
118:
119: public void setValue(String str) {
120: value = str;
121: }
122:
123: public void setParent(RegistryObject parent) {
124: this .parent = parent;
125: }
126:
127: public void setParentconcept(Concept parentconcept) {
128: this .parentconcept = parentconcept;
129: parent = null; //We deal with concept as parent
130: }
131:
132: public void setScheme(ClassificationSchemeImpl scheme) {
133: this .scheme = scheme;
134: }
135:
136: public void setChildconcepts(Collection<Concept> childconcepts) {
137: this .childconcepts.clear();
138: Iterator iter = childconcepts.iterator();
139: while (iter.hasNext()) {
140: Concept c = (Concept) iter.next();
141: ((ConceptImpl) c).setParentconcept(this );
142: childconcepts.add(c);
143: }
144: }
145:
146: //Specific API
147: public void setClassificationScheme(ClassificationScheme sc) {
148: scheme = sc;
149: parent = sc;
150: }
151: }
|