KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

50     public PropertyRange() {
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 = true;
59         
60         PropertyValue propVal = (PropertyValue) value;
61         
62         List JavaDoc vals = propVal.getValue();
63         
64         Iterator JavaDoc iter = vals.iterator();
65         
66         while (iter.hasNext() && bIsValid == true) {
67             PropertyInstance propInst = (PropertyInstance) iter.next();
68             
69             Property prop = propInst.getDefinition();
70         
71             String JavaDoc sHREF = prop.getHREF();
72             
73             Iterator JavaDoc hrefIter = m_aHREFs.iterator();
74             boolean bFound = false;
75             
76             while (hrefIter.hasNext() && bFound == false) {
77                 String JavaDoc tmpHREF = (String JavaDoc) hrefIter.next();
78                 
79                 if(sHREF.startsWith(tmpHREF) == true) {
80                     bFound = true;
81                 }
82             }
83             
84             bIsValid = bFound;
85             
86             if(bIsValid == true) {
87                 bIsValid = propInst
88                             .getDefinition().getRange()
89                             .validate(propInst.getValues())
90                             .isValid();
91             }
92         }
93         
94         return new ValidationResult(bIsValid,"");
95     }
96     
97     /**
98      * Returns a list of the properties that are part of this range.
99      *
100      * @return List of {@link Property} objects
101      */

102     public List JavaDoc getProperties() {
103         ArrayList JavaDoc props = new ArrayList JavaDoc(this.m_aHREFs.size());
104         Iterator JavaDoc itor = this.m_aHREFs.iterator();
105         while(itor.hasNext()) {
106             PropertyGroup propGroup = PropertyCache.getInstance().getPropertyGroup((String JavaDoc)itor.next());
107             if(propGroup!=null) {
108                 props.addAll( propGroup.getChildren() );
109             }
110         }
111         return props;
112     }
113     
114     /**
115      * Sets the list of full paths to virtual files for properties that
116      * are part of this range.
117      *
118      * @param aHREFs List of full paths
119      */

120     public void setHREFs(List JavaDoc aHREFs) {
121         this.m_aHREFs = new ArrayList JavaDoc(aHREFs);
122     }
123     
124     public List JavaDoc getHREFs() {
125         return this.m_aHREFs;
126     }
127
128     /* (non-Javadoc)
129      * @see com.simulacramedia.vfs.metadata.Range#instantiate(org.w3c.dom.Element)
130      */

131     public void instantiate(Element JavaDoc elRange) {
132         NodeList JavaDoc nl = elRange.getElementsByTagNameNS("DAV:", "href");
133         for(int i=0; i<nl.getLength(); i++) {
134             Element JavaDoc elHREF = (Element JavaDoc)nl.item(i);
135             if(elHREF.getParentNode().getLocalName().equalsIgnoreCase("properties")) {
136                 if(elHREF.getChildNodes().getLength()==1) {
137                     Node JavaDoc node = elHREF.getFirstChild();
138                     if(node.getNodeType()==Node.TEXT_NODE) {
139                         this.m_aHREFs.add( ((Text JavaDoc)node).getNodeValue() );
140                     }
141                 }
142             }
143         }
144     }
145
146     public String JavaDoc toString() {
147         StringBuffer JavaDoc sBuff = new StringBuffer JavaDoc();
148         
149         sBuff.append("PropertyRange:\n").append("[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[");
150         Iterator JavaDoc itor = this.m_aHREFs.iterator();
151         while(itor.hasNext()) {
152             String JavaDoc sHREF = (String JavaDoc)itor.next();
153             Property prop = PropertyCache.getInstance().getPropertyByPath(sHREF);
154             sBuff.append("PROP: ").append(prop).append("\n");
155         }
156         
157         return sBuff.append("]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]").toString();
158     }
159
160 }
161
Popular Tags