| 1 19 package org.openharmonise.vfs.metadata.range; 20 21 import java.util.ArrayList ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 25 import org.openharmonise.vfs.metadata.*; 26 import org.openharmonise.vfs.metadata.value.*; 27 import org.w3c.dom.Element ; 28 import org.w3c.dom.Node ; 29 import org.w3c.dom.NodeList ; 30 import org.w3c.dom.Text ; 31 32 33 40 public class PropertyRange extends AbstractRange implements Range { 41 42 45 private ArrayList m_aHREFs = new ArrayList (3); 46 47 50 public PropertyRange() { 51 super(); 52 } 53 54 57 public ValidationResult validate(ValueInstance value) { 58 boolean bIsValid = true; 59 60 PropertyValue propVal = (PropertyValue) value; 61 62 List vals = propVal.getValue(); 63 64 Iterator 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 sHREF = prop.getHREF(); 72 73 Iterator hrefIter = m_aHREFs.iterator(); 74 boolean bFound = false; 75 76 while (hrefIter.hasNext() && bFound == false) { 77 String tmpHREF = (String ) 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 102 public List getProperties() { 103 ArrayList props = new ArrayList (this.m_aHREFs.size()); 104 Iterator itor = this.m_aHREFs.iterator(); 105 while(itor.hasNext()) { 106 PropertyGroup propGroup = PropertyCache.getInstance().getPropertyGroup((String )itor.next()); 107 if(propGroup!=null) { 108 props.addAll( propGroup.getChildren() ); 109 } 110 } 111 return props; 112 } 113 114 120 public void setHREFs(List aHREFs) { 121 this.m_aHREFs = new ArrayList (aHREFs); 122 } 123 124 public List getHREFs() { 125 return this.m_aHREFs; 126 } 127 128 131 public void instantiate(Element elRange) { 132 NodeList nl = elRange.getElementsByTagNameNS("DAV:", "href"); 133 for(int i=0; i<nl.getLength(); i++) { 134 Element elHREF = (Element )nl.item(i); 135 if(elHREF.getParentNode().getLocalName().equalsIgnoreCase("properties")) { 136 if(elHREF.getChildNodes().getLength()==1) { 137 Node node = elHREF.getFirstChild(); 138 if(node.getNodeType()==Node.TEXT_NODE) { 139 this.m_aHREFs.add( ((Text )node).getNodeValue() ); 140 } 141 } 142 } 143 } 144 } 145 146 public String toString() { 147 StringBuffer sBuff = new StringBuffer (); 148 149 sBuff.append("PropertyRange:\n").append("[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["); 150 Iterator itor = this.m_aHREFs.iterator(); 151 while(itor.hasNext()) { 152 String sHREF = (String )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 |