KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > vfs > metadata > range > ValueGroup


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.vfs.metadata.range;
20
21 import java.util.ArrayList JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.List JavaDoc;
24
25 import org.openharmonise.vfs.metadata.*;
26 import org.w3c.dom.Element JavaDoc;
27 import org.w3c.dom.Node JavaDoc;
28 import org.w3c.dom.NodeList JavaDoc;
29 import org.w3c.dom.Text JavaDoc;
30
31
32 /**
33  * Represents a value group in a vocabulary.
34  *
35  * @author Matthew Large
36  * @version $Revision: 1.1 $
37  *
38  */

39 public class ValueGroup {
40
41     /**
42      * Full path to the virtual file for this value group.
43      */

44     private String JavaDoc m_sHREF;
45
46     /**
47      * Name.
48      */

49     private String JavaDoc m_sName;
50
51     /**
52      * Display name.
53      */

54     private String JavaDoc m_sDisplayName;
55     
56     /**
57      * List of the full paths to the virtual files for values that are under this value group
58      */

59     private ArrayList JavaDoc m_aChildren = new ArrayList JavaDoc();
60     
61     /**
62      * List of the full paths to the virtual files for value groups that are under this value group.
63      */

64     private ArrayList JavaDoc m_aSubGroups = new ArrayList JavaDoc();
65
66     /**
67      *
68      */

69     public ValueGroup() {
70         super();
71     }
72
73     /**
74      * Constructs a new value group.
75      *
76      * @param sName Name
77      * @param sHREF Full path
78      */

79     public ValueGroup(String JavaDoc sName, String JavaDoc sHREF) {
80         super();
81         this.m_sName = sName;
82         this.m_sHREF = sHREF;
83     }
84     
85     /**
86      * Returns the display name for this value group.
87      *
88      * @return Display name
89      */

90     public String JavaDoc getDisplayName() {
91         return this.m_sDisplayName;
92     }
93     
94     /**
95      * Sets the display name for this value group.
96      *
97      * @param sDisplayName Display name
98      */

99     public void setDisplayName(String JavaDoc sDisplayName) {
100         this.m_sDisplayName = sDisplayName;
101     }
102     
103     /**
104      * Sets the name for this value group.
105      *
106      * @param sName Name
107      */

108     public void setName(String JavaDoc sName) {
109         this.m_sName = sName;
110     }
111     
112     /**
113      * Returns the name for this value group.
114      *
115      * @return Name
116      */

117     public String JavaDoc getName() {
118         return this.m_sName;
119     }
120     
121     /**
122      * Returns the full path to the virtual file for this value group.
123      *
124      * @return Full path
125      */

126     public String JavaDoc getHREF() {
127         return this.m_sHREF;
128     }
129     
130     /**
131      * Adds a full path to the virtual file for a value.
132      *
133      * @param sHREF Full path to add
134      */

135     public void addChild(String JavaDoc sHREF) {
136         this.m_aChildren.add(sHREF);
137     }
138     
139     /**
140      * Adds a full path to the virtual file for a value group.
141      *
142      * @param sHREF Full path to add
143      */

144     public void addSubGroup(String JavaDoc sHREF) {
145         this.m_aSubGroups.add(sHREF);
146     }
147     
148     /**
149      * List of {@link Value} objects which are under this value group.
150      *
151      * @return List of values
152      */

153     public List JavaDoc getChildren() {
154         ArrayList JavaDoc vals = new ArrayList JavaDoc();
155         Iterator JavaDoc itor = m_aChildren.iterator();
156         while(itor.hasNext()) {
157             String JavaDoc sHREF = (String JavaDoc)itor.next();
158             vals.add(ValueCache.getInstance().getValue(sHREF));
159         }
160         
161         return vals;
162     }
163     
164     /**
165      * Returns a list of {@link ValueGroup} objects which are under this
166      * value group.
167      *
168      * @return List of value groups
169      */

170     public List JavaDoc getSubGroups() {
171         ArrayList JavaDoc vals = new ArrayList JavaDoc();
172         Iterator JavaDoc itor = m_aSubGroups.iterator();
173         while(itor.hasNext()) {
174             String JavaDoc sHREF = (String JavaDoc)itor.next();
175             vals.add(ValueCache.getInstance().getValueGroup(sHREF));
176         }
177         
178         return vals;
179     }
180
181     public void instantiate(Element JavaDoc elValue) {
182         this.m_sName =
183             elValue.getAttributeNS(
184                 "http://www.simulacramedia.com/harmoniseclient/propdefs",
185                 "name");
186         NodeList JavaDoc nl = elValue.getChildNodes();
187         for (int i = 0; i < nl.getLength(); i++) {
188             Node JavaDoc node = nl.item(i);
189             if (node.getNodeType() == Node.ELEMENT_NODE) {
190                 Element JavaDoc element = (Element JavaDoc) node;
191                 if (element.getLocalName().equalsIgnoreCase("displayname")) {
192                     Node JavaDoc node2 = element.getFirstChild();
193                     if (node2.getNodeType() == Node.TEXT_NODE) {
194                         this.m_sDisplayName = ((Text JavaDoc) node2).getNodeValue();
195                     }
196                 } else if (element.getLocalName().equalsIgnoreCase("href")) {
197                     Node JavaDoc node2 = element.getFirstChild();
198                     if (node2.getNodeType() == Node.TEXT_NODE) {
199                         this.m_sHREF = ((Text JavaDoc) node2).getNodeValue();
200                     }
201                 } else if (element.getLocalName().equalsIgnoreCase("children")) {
202                     NodeList JavaDoc nl2 = element.getChildNodes();
203                     for(int j=0; j<nl2.getLength(); j++) {
204                         Node JavaDoc childNode = (Node JavaDoc)nl2.item(j);
205                         if(childNode.getNodeType()==Node.ELEMENT_NODE) {
206                             Element JavaDoc childElement = (Element JavaDoc)childNode;
207                             Node JavaDoc node2 = childElement.getFirstChild();
208                             if (node2.getNodeType() == Node.TEXT_NODE) {
209                                 String JavaDoc sTemp = ((Text JavaDoc) node2).getNodeValue();
210                                 this.m_aChildren.add(sTemp.trim());
211                             }
212                         }
213                     }
214                 } else if (element.getLocalName().equalsIgnoreCase("subgroups")) {
215                     NodeList JavaDoc nl2 = element.getChildNodes();
216                     for(int j=0; j<nl2.getLength(); j++) {
217                         Node JavaDoc childNode = (Node JavaDoc)nl2.item(j);
218                         if(childNode.getNodeType()==Node.ELEMENT_NODE) {
219                             Element JavaDoc childElement = (Element JavaDoc)childNode;
220                             Node JavaDoc node2 = childElement.getFirstChild();
221                             if (node2.getNodeType() == Node.TEXT_NODE) {
222                                 String JavaDoc sTemp = ((Text JavaDoc) node2).getNodeValue();
223                                 this.m_aSubGroups.add(sTemp.trim());
224                             }
225                         }
226                     }
227                 }
228             }
229         }
230     }
231     
232     public String JavaDoc toString() {
233         StringBuffer JavaDoc sBuff = new StringBuffer JavaDoc();
234         
235         sBuff.append("ValueGroup: [").append(this.m_sName).append("]\n")
236              .append("DisplayName: ").append(this.m_sDisplayName).append("\n")
237              .append("Path: ").append(this.m_sHREF).append("\n");
238              
239         Iterator JavaDoc itor = this.m_aSubGroups.iterator();
240         while(itor.hasNext()) {
241             String JavaDoc sHREF = (String JavaDoc)itor.next();
242             sBuff.append(sHREF);
243         }
244         
245         itor = this.m_aChildren.iterator();
246         while(itor.hasNext()) {
247             String JavaDoc sHREF = (String JavaDoc)itor.next();
248             sBuff.append(sHREF);
249         }
250         
251         return sBuff.toString();
252     }
253
254 }
255
Popular Tags