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;
020:
021: import java.util.ArrayList;
022: import java.util.Iterator;
023: import java.util.List;
024:
025: import org.w3c.dom.Element;
026: import org.w3c.dom.Node;
027: import org.w3c.dom.NodeList;
028: import org.w3c.dom.Text;
029:
030: /**
031: * A property group is essentially just a virtual file collection, this class
032: * wraps the data that is required for use as a property group thus
033: * simplifying usage in certain situations.
034: *
035: * @author Matthew Large
036: * @version $Revision: 1.1 $
037: *
038: */
039: public class PropertyGroup {
040:
041: /**
042: * Full path to the virtual file for this property group.
043: */
044: private String m_sHREF;
045:
046: /**
047: * Version identifier for this property group.
048: */
049: private int m_nVersion;
050:
051: /**
052: * Name for this property group.
053: */
054: private String m_sName;
055:
056: /**
057: * Display name for this property group.
058: */
059: private String m_sDisplayName;
060:
061: /**
062: * List of {@link Property} objects which are children of this property group.
063: */
064: private ArrayList m_aChildren = new ArrayList(5);
065:
066: /**
067: * List of {@link PropertyGroup} objects which are children of this property.
068: */
069: private ArrayList m_aSubGroups = new ArrayList(5);
070:
071: /**
072: *
073: */
074: public PropertyGroup() {
075: super ();
076: }
077:
078: /**
079: * Sets the name of this property group.
080: *
081: * @param sName Name
082: */
083: public void setName(String sName) {
084: this .m_sName = sName;
085: }
086:
087: /**
088: * Sets the full path to the virtual file for this property group.
089: *
090: * @param sHREF Full path
091: */
092: public void setHREF(String sHREF) {
093: this .m_sHREF = sHREF;
094: }
095:
096: /**
097: * Returns the full path to the virtual file for this property group.
098: *
099: * @return Full path
100: */
101: public String getHREF() {
102: return this .m_sHREF;
103: }
104:
105: /**
106: * Returns a list of {@link Property} objects that are children of
107: * this property group.
108: *
109: * @return List of {@link Property} objects.
110: */
111: public List getChildren() {
112: ArrayList vals = new ArrayList();
113: Iterator itor = m_aChildren.iterator();
114: while (itor.hasNext()) {
115: String sHREF = (String) itor.next();
116: vals.add(PropertyCache.getInstance().getPropertyByPath(
117: sHREF));
118: }
119:
120: return vals;
121: }
122:
123: /**
124: * Returns a list of paths to the virtual files of properties
125: * which are children of this property group.
126: *
127: * @return List of paths
128: */
129: public List getChildrenHREFs() {
130: return this .m_aChildren;
131: }
132:
133: /**
134: * Sets the paths to the virtual files of properties
135: * which are children of this property group.
136: *
137: * @param aHREFs List of paths
138: */
139: public void setChildrenHREFs(List aHREFs) {
140: this .m_aChildren = new ArrayList(aHREFs);
141: }
142:
143: /**
144: * Returns a list of {@link PropertyGroup} objects which are
145: * children of this property group.
146: *
147: * @return List of {@link PropertyGroup} objects.
148: */
149: public List getSubGroups() {
150: ArrayList vals = new ArrayList();
151: Iterator itor = m_aSubGroups.iterator();
152: while (itor.hasNext()) {
153: String sHREF = (String) itor.next();
154: vals.add(PropertyCache.getInstance()
155: .getPropertyGroup(sHREF));
156: }
157:
158: return vals;
159: }
160:
161: /**
162: * Populates this property group from a XML element.
163: *
164: * @param elValue Root element of the property group XML
165: */
166: public void instantiate(Element elValue) {
167: this .m_sName = elValue
168: .getAttributeNS(
169: "http://www.simulacramedia.com/harmoniseclient/propdefs",
170: "name");
171: NodeList nl = elValue.getChildNodes();
172: for (int i = 0; i < nl.getLength(); i++) {
173: Node node = nl.item(i);
174: if (node.getNodeType() == Node.ELEMENT_NODE) {
175: Element element = (Element) node;
176: if (element.getLocalName().equalsIgnoreCase(
177: "displayname")) {
178: Node node2 = element.getFirstChild();
179: if (node2.getNodeType() == Node.TEXT_NODE) {
180: this .m_sDisplayName = ((Text) node2)
181: .getNodeValue();
182: }
183: } else if (element.getLocalName().equalsIgnoreCase(
184: "version")) {
185: Node node2 = element.getFirstChild();
186: if (node2.getNodeType() == Node.TEXT_NODE) {
187: this .m_nVersion = Integer
188: .parseInt(((Text) node2).getNodeValue());
189: }
190: } else if (element.getLocalName().equalsIgnoreCase(
191: "href")) {
192: Node node2 = element.getFirstChild();
193: if (node2.getNodeType() == Node.TEXT_NODE) {
194: this .m_sHREF = ((Text) node2).getNodeValue();
195: }
196: } else if (element.getLocalName().equalsIgnoreCase(
197: "children")) {
198: NodeList nl2 = element.getChildNodes();
199: for (int j = 0; j < nl2.getLength(); j++) {
200: Node childNode = (Node) nl2.item(j);
201: if (childNode.getNodeType() == Node.ELEMENT_NODE) {
202: Element childElement = (Element) childNode;
203: Node node2 = childElement.getFirstChild();
204: if (node2.getNodeType() == Node.TEXT_NODE) {
205: String sTemp = ((Text) node2)
206: .getNodeValue();
207: this .m_aChildren.add(sTemp.trim());
208: }
209: }
210: }
211: } else if (element.getLocalName().equalsIgnoreCase(
212: "subgroups")) {
213: NodeList nl2 = element.getChildNodes();
214: for (int j = 0; j < nl2.getLength(); j++) {
215: Node childNode = (Node) nl2.item(j);
216: if (childNode.getNodeType() == Node.ELEMENT_NODE) {
217: Element childElement = (Element) childNode;
218: Node node2 = childElement.getFirstChild();
219: if (node2.getNodeType() == Node.TEXT_NODE) {
220: String sTemp = ((Text) node2)
221: .getNodeValue();
222: this.m_aSubGroups.add(sTemp.trim());
223: }
224: }
225: }
226: }
227: }
228: }
229: }
230: }
|