KickJava   Java API By Example, From Geeks To Geeks.

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


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.openharmonise.vfs.metadata.value.*;
27 import org.w3c.dom.Element JavaDoc;
28 import org.w3c.dom.Node JavaDoc;
29 import org.w3c.dom.NodeList JavaDoc;
30 import org.w3c.dom.Text JavaDoc;
31
32
33 /**
34  * This is the range for collection relationship type properties.
35  *
36  * @author Matthew Large
37  * @version $Revision: 1.1 $
38  *
39  */

40 public class CollectionRange extends AbstractRange implements Range {
41
42     /**
43      * List of full paths to collections which contain valid values.
44      */

45     private ArrayList JavaDoc m_aHREFs = new ArrayList JavaDoc(3);
46
47     /**
48      *
49      */

50     public CollectionRange() {
51         super();
52     }
53
54     /* (non-Javadoc)
55      * @see com.simulacramedia.vfs.metadata.range.AbstractRange#validate(java.lang.String)
56      */

57     public ValidationResult validate(ValueInstance value) {
58         boolean bIsValid = false;
59         
60         String JavaDoc sValue = ((ResourceValue)value).getValue();
61         
62         Iterator JavaDoc iter = m_aHREFs.iterator();
63         
64         while (iter.hasNext() && bIsValid == false) {
65             String JavaDoc sPath = (String JavaDoc) iter.next();
66             if(sValue.startsWith(sPath)) {
67                 bIsValid = true;
68             }
69         }
70         
71         return new ValidationResult(bIsValid,"");
72     }
73
74     /* (non-Javadoc)
75      * @see com.simulacramedia.vfs.metadata.Range#instantiate(org.w3c.dom.Element)
76      */

77     public void instantiate(Element JavaDoc elRange) {
78         NodeList JavaDoc nl = elRange.getElementsByTagNameNS("DAV:", "href");
79         for(int i=0; i<nl.getLength(); i++) {
80             Element JavaDoc elHREF = (Element JavaDoc)nl.item(i);
81             if(elHREF.getChildNodes().getLength()==1) {
82                 Node JavaDoc node = elHREF.getFirstChild();
83                 if(node.getNodeType()==Node.TEXT_NODE) {
84                     this.m_aHREFs.add( ((Text JavaDoc)node).getNodeValue() );
85                 }
86             }
87         }
88     }
89     
90     /**
91      * Returns a list of collections which contain valid values.
92      *
93      * @return List of full paths
94      */

95     public List JavaDoc getHREFs() {
96         return (List JavaDoc) this.m_aHREFs.clone();
97     }
98     
99     /**
100      * Sets the list of collections which contain valid values.
101      *
102      * @param aHREFs List of full paths
103      */

104     public void setHREFs(List JavaDoc aHREFs) {
105         this.m_aHREFs = new ArrayList JavaDoc(aHREFs);
106     }
107
108     public String JavaDoc toString() {
109         StringBuffer JavaDoc sBuff = new StringBuffer JavaDoc();
110         
111         sBuff.append("CollectionRange:\n");
112         Iterator JavaDoc itor = this.m_aHREFs.iterator();
113         while(itor.hasNext()) {
114             sBuff.append("HREF: ").append(((String JavaDoc)itor.next())).append("\n");
115         }
116         
117         return sBuff.toString();
118     }
119
120 }
121
Popular Tags