001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.vfs.metadata.range;
020:
021: import java.util.ArrayList;
022: import java.util.Iterator;
023: import java.util.List;
024:
025: import org.openharmonise.vfs.metadata.*;
026: import org.openharmonise.vfs.metadata.value.*;
027: import org.w3c.dom.Element;
028: import org.w3c.dom.Node;
029: import org.w3c.dom.NodeList;
030: import org.w3c.dom.Text;
031:
032: /**
033: * This is the range for compound type properties.
034: *
035: * @author Matthew Large
036: * @version $Revision: 1.1 $
037: *
038: */
039: public class PropertyRange extends AbstractRange implements Range {
040:
041: /**
042: * List of full paths to virtual files for properties that are part of this range.
043: */
044: private ArrayList m_aHREFs = new ArrayList(3);
045:
046: /**
047: *
048: */
049: public PropertyRange() {
050: super ();
051: }
052:
053: /* (non-Javadoc)
054: * @see com.simulacramedia.vfs.metadata.range.AbstractRange#validate(java.lang.String)
055: */
056: public ValidationResult validate(ValueInstance value) {
057: boolean bIsValid = true;
058:
059: PropertyValue propVal = (PropertyValue) value;
060:
061: List vals = propVal.getValue();
062:
063: Iterator iter = vals.iterator();
064:
065: while (iter.hasNext() && bIsValid == true) {
066: PropertyInstance propInst = (PropertyInstance) iter.next();
067:
068: Property prop = propInst.getDefinition();
069:
070: String sHREF = prop.getHREF();
071:
072: Iterator hrefIter = m_aHREFs.iterator();
073: boolean bFound = false;
074:
075: while (hrefIter.hasNext() && bFound == false) {
076: String tmpHREF = (String) hrefIter.next();
077:
078: if (sHREF.startsWith(tmpHREF) == true) {
079: bFound = true;
080: }
081: }
082:
083: bIsValid = bFound;
084:
085: if (bIsValid == true) {
086: bIsValid = propInst.getDefinition().getRange()
087: .validate(propInst.getValues()).isValid();
088: }
089: }
090:
091: return new ValidationResult(bIsValid, "");
092: }
093:
094: /**
095: * Returns a list of the properties that are part of this range.
096: *
097: * @return List of {@link Property} objects
098: */
099: public List getProperties() {
100: ArrayList props = new ArrayList(this .m_aHREFs.size());
101: Iterator itor = this .m_aHREFs.iterator();
102: while (itor.hasNext()) {
103: PropertyGroup propGroup = PropertyCache.getInstance()
104: .getPropertyGroup((String) itor.next());
105: if (propGroup != null) {
106: props.addAll(propGroup.getChildren());
107: }
108: }
109: return props;
110: }
111:
112: /**
113: * Sets the list of full paths to virtual files for properties that
114: * are part of this range.
115: *
116: * @param aHREFs List of full paths
117: */
118: public void setHREFs(List aHREFs) {
119: this .m_aHREFs = new ArrayList(aHREFs);
120: }
121:
122: public List getHREFs() {
123: return this .m_aHREFs;
124: }
125:
126: /* (non-Javadoc)
127: * @see com.simulacramedia.vfs.metadata.Range#instantiate(org.w3c.dom.Element)
128: */
129: public void instantiate(Element elRange) {
130: NodeList nl = elRange.getElementsByTagNameNS("DAV:", "href");
131: for (int i = 0; i < nl.getLength(); i++) {
132: Element elHREF = (Element) nl.item(i);
133: if (elHREF.getParentNode().getLocalName().equalsIgnoreCase(
134: "properties")) {
135: if (elHREF.getChildNodes().getLength() == 1) {
136: Node node = elHREF.getFirstChild();
137: if (node.getNodeType() == Node.TEXT_NODE) {
138: this .m_aHREFs.add(((Text) node).getNodeValue());
139: }
140: }
141: }
142: }
143: }
144:
145: public String toString() {
146: StringBuffer sBuff = new StringBuffer();
147:
148: sBuff.append("PropertyRange:\n").append(
149: "[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[");
150: Iterator itor = this .m_aHREFs.iterator();
151: while (itor.hasNext()) {
152: String sHREF = (String) itor.next();
153: Property prop = PropertyCache.getInstance()
154: .getPropertyByPath(sHREF);
155: sBuff.append("PROP: ").append(prop).append("\n");
156: }
157:
158: return sBuff.append("]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]")
159: .toString();
160: }
161:
162: }
|