KickJava   Java API By Example, From Geeks To Geeks.

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


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 vocabulary type properties.
35  *
36  * @author Matthew Large
37  * @version $Revision: 1.1 $
38  *
39  */

40 public class ValueRange extends AbstractRange implements Range {
41
42     /**
43      * List of full paths to virtual files for values that are valid for this range.
44      */

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

50     public ValueRange() {
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 = ((ValueValue)value).getValue();
61         
62         Iterator JavaDoc iter = m_aValueGroups.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     public List JavaDoc getValueGroups() {
75         ArrayList JavaDoc aVals = new ArrayList JavaDoc();
76         Iterator JavaDoc itor = this.m_aValueGroups.iterator();
77         while(itor.hasNext()) {
78             String JavaDoc sHREF = (String JavaDoc) itor.next();
79             ValueGroup val = ValueCache.getInstance().getValueGroup(sHREF);
80             aVals.add(val);
81         }
82         
83         return aVals;
84     }
85     
86     public List JavaDoc getHREFs() {
87         return this.m_aValueGroups;
88     }
89     
90     public void setHREFs(List JavaDoc aHREFs) {
91         this.m_aValueGroups = new ArrayList JavaDoc(aHREFs);
92     }
93     
94     public void setValueGroups(List JavaDoc aValueGroups) {
95         this.m_aValueGroups = new ArrayList JavaDoc(aValueGroups);
96     }
97
98     /* (non-Javadoc)
99      * @see com.simulacramedia.vfs.metadata.Range#instantiate(org.w3c.dom.Element)
100      */

101     public void instantiate(Element JavaDoc elRange) {
102         NodeList JavaDoc nl = elRange.getElementsByTagNameNS("DAV:", "href");
103         for(int i=0; i<nl.getLength(); i++) {
104             Element JavaDoc elHREF = (Element JavaDoc)nl.item(i);
105             if(elHREF.getParentNode().getLocalName().equalsIgnoreCase("property")) {
106                 if(elHREF.getChildNodes().getLength()==1) {
107                     Node JavaDoc node = elHREF.getFirstChild();
108                     if(node.getNodeType()==Node.TEXT_NODE) {
109                         //this.m_aHREFs.add( ((Text)node).getNodeValue() );
110
}
111                 }
112             }
113         }
114         
115
116         nl = elRange.getElementsByTagNameNS("http://www.simulacramedia.com/harmoniseclient/propdefs", "valuegroups");
117         for(int i=0; i<nl.getLength(); i++) {
118             Element JavaDoc elValue = (Element JavaDoc)nl.item(i);
119             NodeList JavaDoc nl2 = elValue.getElementsByTagNameNS("DAV:", "href");
120             for(int j=0; j<nl2.getLength(); j++) {
121                 Element JavaDoc elHREF = (Element JavaDoc)nl2.item(j);
122                 if(elHREF.getChildNodes().getLength()==1) {
123                     Node JavaDoc node = elHREF.getFirstChild();
124                     if(node.getNodeType()==Node.TEXT_NODE) {
125                         String JavaDoc sHREF = ((Text JavaDoc)node).getNodeValue();
126                         this.m_aValueGroups.add(sHREF);
127                     }
128                 }
129             }
130         }
131     }
132
133     public String JavaDoc toString() {
134         StringBuffer JavaDoc sBuff = new StringBuffer JavaDoc();
135         
136         sBuff.append("ValueRange:\n");
137         
138         sBuff.append("Values:\n");
139         Iterator JavaDoc itor = this.m_aValueGroups.iterator();
140         while(itor.hasNext()) {
141             ValueGroup val = ValueCache.getInstance().getValueGroup((String JavaDoc)itor.next());
142             sBuff.append(val).append("\n");
143         }
144         
145         return sBuff.toString();
146     }
147
148 }
149
Popular Tags