001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.vfs.metadata.range;
020:
021: import java.util.ArrayList;
022: import java.util.Iterator;
023: import java.util.List;
024:
025: import org.openharmonise.vfs.metadata.*;
026: import org.w3c.dom.Element;
027: import org.w3c.dom.Node;
028: import org.w3c.dom.NodeList;
029: import org.w3c.dom.Text;
030:
031: /**
032: * Represents a value group in a vocabulary.
033: *
034: * @author Matthew Large
035: * @version $Revision: 1.1 $
036: *
037: */
038: public class ValueGroup {
039:
040: /**
041: * Full path to the virtual file for this value group.
042: */
043: private String m_sHREF;
044:
045: /**
046: * Name.
047: */
048: private String m_sName;
049:
050: /**
051: * Display name.
052: */
053: private String m_sDisplayName;
054:
055: /**
056: * List of the full paths to the virtual files for values that are under this value group
057: */
058: private ArrayList m_aChildren = new ArrayList();
059:
060: /**
061: * List of the full paths to the virtual files for value groups that are under this value group.
062: */
063: private ArrayList m_aSubGroups = new ArrayList();
064:
065: /**
066: *
067: */
068: public ValueGroup() {
069: super ();
070: }
071:
072: /**
073: * Constructs a new value group.
074: *
075: * @param sName Name
076: * @param sHREF Full path
077: */
078: public ValueGroup(String sName, String sHREF) {
079: super ();
080: this .m_sName = sName;
081: this .m_sHREF = sHREF;
082: }
083:
084: /**
085: * Returns the display name for this value group.
086: *
087: * @return Display name
088: */
089: public String getDisplayName() {
090: return this .m_sDisplayName;
091: }
092:
093: /**
094: * Sets the display name for this value group.
095: *
096: * @param sDisplayName Display name
097: */
098: public void setDisplayName(String sDisplayName) {
099: this .m_sDisplayName = sDisplayName;
100: }
101:
102: /**
103: * Sets the name for this value group.
104: *
105: * @param sName Name
106: */
107: public void setName(String sName) {
108: this .m_sName = sName;
109: }
110:
111: /**
112: * Returns the name for this value group.
113: *
114: * @return Name
115: */
116: public String getName() {
117: return this .m_sName;
118: }
119:
120: /**
121: * Returns the full path to the virtual file for this value group.
122: *
123: * @return Full path
124: */
125: public String getHREF() {
126: return this .m_sHREF;
127: }
128:
129: /**
130: * Adds a full path to the virtual file for a value.
131: *
132: * @param sHREF Full path to add
133: */
134: public void addChild(String sHREF) {
135: this .m_aChildren.add(sHREF);
136: }
137:
138: /**
139: * Adds a full path to the virtual file for a value group.
140: *
141: * @param sHREF Full path to add
142: */
143: public void addSubGroup(String sHREF) {
144: this .m_aSubGroups.add(sHREF);
145: }
146:
147: /**
148: * List of {@link Value} objects which are under this value group.
149: *
150: * @return List of values
151: */
152: public List getChildren() {
153: ArrayList vals = new ArrayList();
154: Iterator itor = m_aChildren.iterator();
155: while (itor.hasNext()) {
156: String sHREF = (String) itor.next();
157: vals.add(ValueCache.getInstance().getValue(sHREF));
158: }
159:
160: return vals;
161: }
162:
163: /**
164: * Returns a list of {@link ValueGroup} objects which are under this
165: * value group.
166: *
167: * @return List of value groups
168: */
169: public List getSubGroups() {
170: ArrayList vals = new ArrayList();
171: Iterator itor = m_aSubGroups.iterator();
172: while (itor.hasNext()) {
173: String sHREF = (String) itor.next();
174: vals.add(ValueCache.getInstance().getValueGroup(sHREF));
175: }
176:
177: return vals;
178: }
179:
180: public void instantiate(Element elValue) {
181: this .m_sName = elValue
182: .getAttributeNS(
183: "http://www.simulacramedia.com/harmoniseclient/propdefs",
184: "name");
185: NodeList nl = elValue.getChildNodes();
186: for (int i = 0; i < nl.getLength(); i++) {
187: Node node = nl.item(i);
188: if (node.getNodeType() == Node.ELEMENT_NODE) {
189: Element element = (Element) node;
190: if (element.getLocalName().equalsIgnoreCase(
191: "displayname")) {
192: Node node2 = element.getFirstChild();
193: if (node2.getNodeType() == Node.TEXT_NODE) {
194: this .m_sDisplayName = ((Text) node2)
195: .getNodeValue();
196: }
197: } else if (element.getLocalName().equalsIgnoreCase(
198: "href")) {
199: Node node2 = element.getFirstChild();
200: if (node2.getNodeType() == Node.TEXT_NODE) {
201: this .m_sHREF = ((Text) node2).getNodeValue();
202: }
203: } else if (element.getLocalName().equalsIgnoreCase(
204: "children")) {
205: NodeList nl2 = element.getChildNodes();
206: for (int j = 0; j < nl2.getLength(); j++) {
207: Node childNode = (Node) nl2.item(j);
208: if (childNode.getNodeType() == Node.ELEMENT_NODE) {
209: Element childElement = (Element) childNode;
210: Node node2 = childElement.getFirstChild();
211: if (node2.getNodeType() == Node.TEXT_NODE) {
212: String sTemp = ((Text) node2)
213: .getNodeValue();
214: this .m_aChildren.add(sTemp.trim());
215: }
216: }
217: }
218: } else if (element.getLocalName().equalsIgnoreCase(
219: "subgroups")) {
220: NodeList nl2 = element.getChildNodes();
221: for (int j = 0; j < nl2.getLength(); j++) {
222: Node childNode = (Node) nl2.item(j);
223: if (childNode.getNodeType() == Node.ELEMENT_NODE) {
224: Element childElement = (Element) childNode;
225: Node node2 = childElement.getFirstChild();
226: if (node2.getNodeType() == Node.TEXT_NODE) {
227: String sTemp = ((Text) node2)
228: .getNodeValue();
229: this .m_aSubGroups.add(sTemp.trim());
230: }
231: }
232: }
233: }
234: }
235: }
236: }
237:
238: public String toString() {
239: StringBuffer sBuff = new StringBuffer();
240:
241: sBuff.append("ValueGroup: [").append(this .m_sName)
242: .append("]\n").append("DisplayName: ").append(
243: this .m_sDisplayName).append("\n").append(
244: "Path: ").append(this .m_sHREF).append("\n");
245:
246: Iterator itor = this .m_aSubGroups.iterator();
247: while (itor.hasNext()) {
248: String sHREF = (String) itor.next();
249: sBuff.append(sHREF);
250: }
251:
252: itor = this .m_aChildren.iterator();
253: while (itor.hasNext()) {
254: String sHREF = (String) itor.next();
255: sBuff.append(sHREF);
256: }
257:
258: return sBuff.toString();
259: }
260:
261: }
|