/*
* The contents of this file are subject to the
* Mozilla Public License Version 1.1 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
* See the License for the specific language governing rights and
* limitations under the License.
*
* The Initial Developer of the Original Code is Simulacra Media Ltd.
* Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
*
* All Rights Reserved.
*
* Contributor(s):
*/
package org.openharmonise.vfs.metadata.range;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.openharmonise.vfs.metadata.*;
import org.openharmonise.vfs.metadata.value.*;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
/**
* This is the range for compound type properties.
*
* @author Matthew Large
* @version $Revision: 1.1 $
*
*/
public class PropertyRange extends AbstractRange implements Range {
/**
* List of full paths to virtual files for properties that are part of this range.
*/
private ArrayList m_aHREFs = new ArrayList(3);
/**
*
*/
public PropertyRange() {
super();
}
/* (non-Javadoc)
* @see com.simulacramedia.vfs.metadata.range.AbstractRange#validate(java.lang.String)
*/
public ValidationResult validate(ValueInstance value) {
boolean bIsValid = true;
PropertyValue propVal = (PropertyValue) value;
List vals = propVal.getValue();
Iterator iter = vals.iterator();
while (iter.hasNext() && bIsValid == true) {
PropertyInstance propInst = (PropertyInstance) iter.next();
Property prop = propInst.getDefinition();
String sHREF = prop.getHREF();
Iterator hrefIter = m_aHREFs.iterator();
boolean bFound = false;
while (hrefIter.hasNext() && bFound == false) {
String tmpHREF = (String) hrefIter.next();
if(sHREF.startsWith(tmpHREF) == true) {
bFound = true;
}
}
bIsValid = bFound;
if(bIsValid == true) {
bIsValid = propInst
.getDefinition().getRange()
.validate(propInst.getValues())
.isValid();
}
}
return new ValidationResult(bIsValid,"");
}
/**
* Returns a list of the properties that are part of this range.
*
* @return List of {@link Property} objects
*/
public List getProperties() {
ArrayList props = new ArrayList(this.m_aHREFs.size());
Iterator itor = this.m_aHREFs.iterator();
while(itor.hasNext()) {
PropertyGroup propGroup = PropertyCache.getInstance().getPropertyGroup((String)itor.next());
if(propGroup!=null) {
props.addAll( propGroup.getChildren() );
}
}
return props;
}
/**
* Sets the list of full paths to virtual files for properties that
* are part of this range.
*
* @param aHREFs List of full paths
*/
public void setHREFs(List aHREFs) {
this.m_aHREFs = new ArrayList(aHREFs);
}
public List getHREFs() {
return this.m_aHREFs;
}
/* (non-Javadoc)
* @see com.simulacramedia.vfs.metadata.Range#instantiate(org.w3c.dom.Element)
*/
public void instantiate(Element elRange) {
NodeList nl = elRange.getElementsByTagNameNS("DAV:", "href");
for(int i=0; i<nl.getLength(); i++) {
Element elHREF = (Element)nl.item(i);
if(elHREF.getParentNode().getLocalName().equalsIgnoreCase("properties")) {
if(elHREF.getChildNodes().getLength()==1) {
Node node = elHREF.getFirstChild();
if(node.getNodeType()==Node.TEXT_NODE) {
this.m_aHREFs.add( ((Text)node).getNodeValue() );
}
}
}
}
}
public String toString() {
StringBuffer sBuff = new StringBuffer();
sBuff.append("PropertyRange:\n").append("[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[");
Iterator itor = this.m_aHREFs.iterator();
while(itor.hasNext()) {
String sHREF = (String)itor.next();
Property prop = PropertyCache.getInstance().getPropertyByPath(sHREF);
sBuff.append("PROP: ").append(prop).append("\n");
}
return sBuff.append("]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]").toString();
}
}
|