KickJava   Java API By Example, From Geeks To Geeks.

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


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.openharmonise.vfs.metadata.range.*;
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  * A Property is the definition of an item of metadata. Most of the specifics
34  * about the definition are contained in the {@link Range} and {@link Domain}
35  * objects. Properties are stored as {@link org.openharmonise.vfs.VirtualFile}s on a Harmonise server.
36  *
37  * @author Matthew Large
38  * @version $Revision: 1.1 $
39  *
40  */

41 public class Property {
42
43     /**
44      * List of {@link Domain} objects, specifying where the property is allowed to be used.
45      */

46     private ArrayList JavaDoc m_aDomains = new ArrayList JavaDoc(3);
47     
48     /**
49      * The range of the property, specifying what value(s) the property is allowed to contain.
50      */

51     private Range m_range = null;
52
53     /**
54      * Namespace, allows for multiple properties with the same name but in different namespaces.
55      */

56     private String JavaDoc m_sNamespace = null;
57     
58     /**
59      * Name of the property, must be unique for the namespace.
60      */

61     private String JavaDoc m_sName = null;
62     
63     /**
64      * Display name of the property.
65      */

66     private String JavaDoc m_sDisplayName = null;
67     
68     /**
69      * Version identifier for the property.
70      */

71     private String JavaDoc m_sVersion = null;
72     
73     /**
74      * Full path to the virtual file for this property.
75      */

76     private String JavaDoc m_sHREF = null;
77     
78     /**
79      * Summary of the property, usually containing some specific help text.
80      */

81     private String JavaDoc m_sSummary = "";
82
83     public Property() {
84         super();
85     }
86
87     /**
88      * Constructs a new property.
89      *
90      * @param sNamespace Namespace
91      * @param sName Name
92      * @param sPath Full path
93      */

94     public Property(String JavaDoc sNamespace, String JavaDoc sName, String JavaDoc sPath) {
95         super();
96         this.m_sNamespace = sNamespace;
97         this.m_sName = sName;
98         this.m_sDisplayName = sName;
99         this.m_sHREF = sPath;
100     }
101     
102     /**
103      * Sets the name of this property.
104      *
105      * @param sName Name
106      */

107     public void setName(String JavaDoc sName) {
108         this.m_sName = sName;
109     }
110     
111     /**
112      * Sets the summary of this property.
113      *
114      * @param sSummary Summary
115      */

116     public void setSummary(String JavaDoc sSummary) {
117         this.m_sSummary = sSummary;
118     }
119     
120     /**
121      * Returns the summary of this property.
122      *
123      * @return Summary
124      */

125     public String JavaDoc getSummary() {
126         return this.m_sSummary;
127     }
128     
129     /**
130      * Sets the namespace of this property.
131      *
132      * @param sNamespace Namespace
133      */

134     public void setNamespace(String JavaDoc sNamespace) {
135         this.m_sNamespace = sNamespace;
136     }
137     
138     /**
139      * Sets the display name of this property.
140      *
141      * @param sDisplayName Display name
142      */

143     public void setDisplayName(String JavaDoc sDisplayName) {
144         this.m_sDisplayName = sDisplayName;
145     }
146     
147     /**
148      * Returns the display name of this property.
149      *
150      * @return Display name
151      */

152     public String JavaDoc getDisplayName() {
153         return this.m_sDisplayName;
154     }
155     
156     /**
157      * Sets the version identifier of this property.
158      *
159      * @param sVersion Version identifier
160      */

161     public void setVersion(String JavaDoc sVersion) {
162         this.m_sVersion = sVersion;
163     }
164     
165     /**
166      * Returns the version identifier of this property.
167      *
168      * @return Version identifier
169      */

170     public String JavaDoc getVersion() {
171         return this.m_sVersion;
172     }
173     
174     /**
175      * Returns the namespace of this property.
176      *
177      * @return Namespace
178      */

179     public String JavaDoc getNamespace() {
180         return this.m_sNamespace;
181     }
182     
183     /**
184      * Returns the name of this property.
185      *
186      * @return Name
187      */

188     public String JavaDoc getName() {
189         return this.m_sName;
190     }
191     
192     /**
193      * Returns the full path to the virtual file for this property.
194      *
195      * @return Full path
196      */

197     public String JavaDoc getHREF() {
198         return this.m_sHREF;
199     }
200     
201     /**
202      * Sets the full path to the virtual file for this property.
203      *
204      * @param sHREF Full path
205      */

206     public void setHREF(String JavaDoc sHREF) {
207         this.m_sHREF = sHREF;
208     }
209
210     /**
211      * Adds a domain to this property.
212      *
213      * @param domain Domain to add
214      */

215     public void addDomain(Domain domain) {
216         this.m_aDomains.add(domain);
217     }
218     
219     /**
220      * Returns a list of {@link Domain} objects for this property.
221      *
222      * @return List of {@link Domain} objects
223      */

224     public List JavaDoc getDomains() {
225         return (List JavaDoc)this.m_aDomains.clone();
226     }
227
228     /**
229      * Sets the range for this property.
230      *
231      * @param range Range
232      */

233     public void setRange(Range range) {
234         this.m_range = range;
235     }
236     
237     /**
238      * Returns the range for this property.
239      *
240      * @return Range
241      */

242     public Range getRange() {
243         if(this.m_range==null) {
244             return new StringRange();
245         }
246         return this.m_range;
247     }
248     
249     /**
250      * Populates this property from a XML element.
251      *
252      * @param elProperty Root element of property XML
253      */

254     public void instantiate(Element JavaDoc elProperty) {
255         NodeList JavaDoc nl = elProperty.getElementsByTagNameNS("http://www.simulacramedia.com/harmoniseclient/propdefs", "displayname");
256         for(int i=0; i<nl.getLength(); i++) {
257             Element JavaDoc elPath = (Element JavaDoc)nl.item(i);
258             if(elPath.getChildNodes().getLength()==1) {
259                 Node JavaDoc node = elPath.getFirstChild();
260                 if(node.getNodeType()==Node.TEXT_NODE) {
261                     this.m_sDisplayName = ((Text JavaDoc)node).getNodeValue();
262                 }
263                 break;
264             }
265         }
266
267         nl = elProperty.getElementsByTagNameNS("http://www.simulacramedia.com/harmoniseclient/propdefs", "version");
268         for(int i=0; i<nl.getLength(); i++) {
269             Element JavaDoc elVersion = (Element JavaDoc)nl.item(i);
270             if(elVersion.getChildNodes().getLength()==1) {
271                 Node JavaDoc node = elVersion.getFirstChild();
272                 if(node.getNodeType()==Node.TEXT_NODE) {
273                     this.m_sVersion = ((Text JavaDoc)node).getNodeValue();
274                 }
275                 break;
276             }
277         }
278         
279         nl = elProperty.getElementsByTagNameNS("DAV:", "href");
280         for(int i=0; i<nl.getLength(); i++) {
281             Element JavaDoc elPath = (Element JavaDoc)nl.item(i);
282             if(elPath.getChildNodes().getLength()==1) {
283                 Node JavaDoc node = elPath.getFirstChild();
284                 if(node.getNodeType()==Node.TEXT_NODE) {
285                     this.m_sHREF = ((Text JavaDoc)node).getNodeValue();
286                 }
287                 break;
288             }
289         }
290         
291         nl = elProperty.getElementsByTagNameNS("DAV:", "range");
292         for(int i=0; i<nl.getLength(); i++) {
293             Element JavaDoc elRange = (Element JavaDoc)nl.item(i);
294             if(elRange!=null) {
295                 this.m_range = RangeFactory.getRange(elRange);
296             }
297             
298         }
299         
300         nl = elProperty.getElementsByTagNameNS("http://www.simulacramedia.com/harmoniseclient/propdefs", "domains");
301         for(int i=0; i<nl.getLength(); i++) {
302             Element JavaDoc elDomains = (Element JavaDoc)nl.item(i);
303             if(elDomains.getChildNodes().getLength()>0) {
304                 NodeList JavaDoc domains = elDomains.getChildNodes();
305                 for(int j=0; j<domains.getLength(); j++) {
306                     if(domains.item(j).getNodeType()==Node.ELEMENT_NODE) {
307                         Domain domain = new Domain();
308                         domain.instantiate( ((Element JavaDoc)domains.item(j)) );
309                         this.m_aDomains.add(domain);
310                     }
311                 }
312             }
313         }
314     }
315
316     public String JavaDoc toString() {
317         StringBuffer JavaDoc sBuff = new StringBuffer JavaDoc();
318         
319         sBuff.append("-----------------------------\n");
320         
321         sBuff.append("Property [")
322              .append(this.m_sNamespace).append("#").append(this.m_sName).append("]\n")
323              .append("DisplayName: ").append(this.m_sDisplayName).append("\n")
324              .append("Version: ").append(this.m_sVersion).append("\n")
325              .append("Path: ").append(this.m_sHREF).append("\n")
326              .append(this.m_range).append("\n");
327              
328         Iterator JavaDoc itor = this.m_aDomains.iterator();
329         while(itor.hasNext()) {
330             sBuff.append( ((Domain)itor.next()) ).append("\n");
331         }
332         
333         sBuff.append("-----------------------------\n");
334         
335         return sBuff.toString();
336     }
337 }
338
Popular Tags