KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > vfs > metadata > PropertyGroup


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;
20
21 import java.util.ArrayList JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.List JavaDoc;
24
25 import org.w3c.dom.Element JavaDoc;
26 import org.w3c.dom.Node JavaDoc;
27 import org.w3c.dom.NodeList JavaDoc;
28 import org.w3c.dom.Text JavaDoc;
29
30 /**
31  * A property group is essentially just a virtual file collection, this class
32  * wraps the data that is required for use as a property group thus
33  * simplifying usage in certain situations.
34  *
35  * @author Matthew Large
36  * @version $Revision: 1.1 $
37  *
38  */

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

44     private String JavaDoc m_sHREF;
45
46     /**
47      * Version identifier for this property group.
48      */

49     private int m_nVersion;
50
51     /**
52      * Name for this property group.
53      */

54     private String JavaDoc m_sName;
55
56     /**
57      * Display name for this property group.
58      */

59     private String JavaDoc m_sDisplayName;
60
61     /**
62      * List of {@link Property} objects which are children of this property group.
63      */

64     private ArrayList JavaDoc m_aChildren = new ArrayList JavaDoc(5);
65     
66     /**
67      * List of {@link PropertyGroup} objects which are children of this property.
68      */

69     private ArrayList JavaDoc m_aSubGroups = new ArrayList JavaDoc(5);
70
71     /**
72      *
73      */

74     public PropertyGroup() {
75         super();
76     }
77     
78     /**
79      * Sets the name of this property group.
80      *
81      * @param sName Name
82      */

83     public void setName(String JavaDoc sName) {
84         this.m_sName = sName;
85     }
86     
87     /**
88      * Sets the full path to the virtual file for this property group.
89      *
90      * @param sHREF Full path
91      */

92     public void setHREF(String JavaDoc sHREF) {
93         this.m_sHREF = sHREF;
94     }
95     
96     /**
97      * Returns the full path to the virtual file for this property group.
98      *
99      * @return Full path
100      */

101     public String JavaDoc 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 JavaDoc getChildren() {
112         ArrayList JavaDoc vals = new ArrayList JavaDoc();
113         Iterator JavaDoc itor = m_aChildren.iterator();
114         while(itor.hasNext()) {
115             String JavaDoc sHREF = (String JavaDoc)itor.next();
116             vals.add(PropertyCache.getInstance().getPropertyByPath(sHREF));
117         }
118         
119         return vals;
120     }
121     
122     /**
123      * Returns a list of paths to the virtual files of properties
124      * which are children of this property group.
125      *
126      * @return List of paths
127      */

128     public List JavaDoc getChildrenHREFs() {
129         return this.m_aChildren;
130     }
131     
132     /**
133      * Sets the paths to the virtual files of properties
134      * which are children of this property group.
135      *
136      * @param aHREFs List of paths
137      */

138     public void setChildrenHREFs(List JavaDoc aHREFs) {
139         this.m_aChildren = new ArrayList JavaDoc(aHREFs);
140     }
141     
142     /**
143      * Returns a list of {@link PropertyGroup} objects which are
144      * children of this property group.
145      *
146      * @return List of {@link PropertyGroup} objects.
147      */

148     public List JavaDoc getSubGroups() {
149         ArrayList JavaDoc vals = new ArrayList JavaDoc();
150         Iterator JavaDoc itor = m_aSubGroups.iterator();
151         while(itor.hasNext()) {
152             String JavaDoc sHREF = (String JavaDoc)itor.next();
153             vals.add(PropertyCache.getInstance().getPropertyGroup(sHREF));
154         }
155         
156         return vals;
157     }
158
159     /**
160      * Populates this property group from a XML element.
161      *
162      * @param elValue Root element of the property group XML
163      */

164     public void instantiate(Element JavaDoc elValue) {
165         this.m_sName =
166             elValue.getAttributeNS(
167                 "http://www.simulacramedia.com/harmoniseclient/propdefs",
168                 "name");
169         NodeList JavaDoc nl = elValue.getChildNodes();
170         for (int i = 0; i < nl.getLength(); i++) {
171             Node JavaDoc node = nl.item(i);
172             if (node.getNodeType() == Node.ELEMENT_NODE) {
173                 Element JavaDoc element = (Element JavaDoc) node;
174                 if (element.getLocalName().equalsIgnoreCase("displayname")) {
175                     Node JavaDoc node2 = element.getFirstChild();
176                     if (node2.getNodeType() == Node.TEXT_NODE) {
177                         this.m_sDisplayName = ((Text JavaDoc) node2).getNodeValue();
178                     }
179                 } else if (
180                     element.getLocalName().equalsIgnoreCase("version")) {
181                     Node JavaDoc node2 = element.getFirstChild();
182                     if (node2.getNodeType() == Node.TEXT_NODE) {
183                         this.m_nVersion =
184                             Integer.parseInt(((Text JavaDoc) node2).getNodeValue());
185                     }
186                 } else if (element.getLocalName().equalsIgnoreCase("href")) {
187                     Node JavaDoc node2 = element.getFirstChild();
188                     if (node2.getNodeType() == Node.TEXT_NODE) {
189                         this.m_sHREF = ((Text JavaDoc) node2).getNodeValue();
190                     }
191                 } else if (
192                     element.getLocalName().equalsIgnoreCase("children")) {
193                     NodeList JavaDoc nl2 = element.getChildNodes();
194                     for (int j = 0; j < nl2.getLength(); j++) {
195                         Node JavaDoc childNode = (Node JavaDoc) nl2.item(j);
196                         if (childNode.getNodeType() == Node.ELEMENT_NODE) {
197                             Element JavaDoc childElement = (Element JavaDoc) childNode;
198                             Node JavaDoc node2 = childElement.getFirstChild();
199                             if (node2.getNodeType() == Node.TEXT_NODE) {
200                                 String JavaDoc sTemp = ((Text JavaDoc) node2).getNodeValue();
201                                 this.m_aChildren.add(sTemp.trim());
202                             }
203                         }
204                     }
205                 } else if (
206                     element.getLocalName().equalsIgnoreCase("subgroups")) {
207                     NodeList JavaDoc nl2 = element.getChildNodes();
208                     for (int j = 0; j < nl2.getLength(); j++) {
209                         Node JavaDoc childNode = (Node JavaDoc) nl2.item(j);
210                         if (childNode.getNodeType() == Node.ELEMENT_NODE) {
211                             Element JavaDoc childElement = (Element JavaDoc) childNode;
212                             Node JavaDoc node2 = childElement.getFirstChild();
213                             if (node2.getNodeType() == Node.TEXT_NODE) {
214                                 String JavaDoc sTemp = ((Text JavaDoc) node2).getNodeValue();
215                                 this.m_aSubGroups.add(sTemp.trim());
216                             }
217                         }
218                     }
219                 }
220             }
221         }
222     }
223 }
224
Popular Tags