1 19 package org.openharmonise.vfs.metadata; 20 21 import java.util.ArrayList ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 25 import org.w3c.dom.Element ; 26 import org.w3c.dom.Node ; 27 import org.w3c.dom.NodeList ; 28 import org.w3c.dom.Text ; 29 30 40 public class Domain { 41 42 45 private String m_sResourceType = null; 46 47 50 private ArrayList m_aContentTypes = new ArrayList (3); 51 52 55 private ArrayList m_aPaths = new ArrayList (3); 56 57 60 private int m_nMinOccurs = 0; 61 62 65 private int m_nMaxOccurs = -1; 66 67 70 public Domain() { 71 super(); 72 } 73 74 75 76 81 public int getMaxOccurs() { 82 return m_nMaxOccurs; 83 } 84 85 90 public int getMinOccurs() { 91 return m_nMinOccurs; 92 } 93 94 99 public List getContentTypes() { 100 return (List )m_aContentTypes.clone(); 101 } 102 103 108 public String getResourceType() { 109 return m_sResourceType; 110 } 111 112 117 public void setMaxOccurs(int i) { 118 m_nMaxOccurs = i; 119 } 120 121 126 public void setMinOccurs(int i) { 127 m_nMinOccurs = i; 128 } 129 130 135 public void addContentType(String string) { 136 m_aContentTypes.add( string); 137 } 138 139 144 public void setResourceType(String string) { 145 m_sResourceType = string; 146 } 147 148 153 public void addPath(String sPath) { 154 this.m_aPaths.add(sPath); 155 } 156 157 162 public List getPaths() { 163 return (List ) this.m_aPaths.clone(); 164 } 165 166 172 public ValidationResult validate(List aValues) { 173 ValidationResult result = new ValidationResult(); 174 175 if( aValues.size()< this.m_nMinOccurs ) { 176 result.setValid(false); 177 result.setMessage(this.m_nMinOccurs + " is the minimum number of values required for this property."); 178 } 179 180 if( this.m_nMaxOccurs>-1 && aValues.size()>this.m_nMaxOccurs) { 181 result.setValid(false); 182 result.setMessage(this.m_nMaxOccurs + " is the maximum number of values allowed for this property."); 183 } 184 185 return result; 186 } 187 188 193 public void instantiate(Element elDomain) { 194 NodeList nl = elDomain.getElementsByTagNameNS("DAV:", "href"); 195 for(int i=0; i<nl.getLength(); i++) { 196 Element elPath = (Element )nl.item(i); 197 if(elPath.getChildNodes().getLength()==1) { 198 Node node = elPath.getFirstChild(); 199 if(node.getNodeType()==Node.TEXT_NODE) { 200 this.m_aPaths.add( ((Text )node).getNodeValue() ); 201 } 202 } 203 } 204 205 nl = elDomain.getElementsByTagNameNS("DAV:", "resourcetype"); 206 for(int i=0; i<nl.getLength(); i++) { 207 Element elResourceType = (Element )nl.item(i); 208 if(elResourceType.getChildNodes().getLength()>0) { 209 NodeList nl2 = elResourceType.getChildNodes(); 210 for(int j=0; j<nl2.getLength(); j++) { 211 if(nl2.item(j).getNodeType()==Node.ELEMENT_NODE) { 213 this.m_sResourceType = ((Element )nl2.item(j)).getTagName(); 214 } 215 } 216 } 217 } 218 219 nl = elDomain.getElementsByTagNameNS("DAV:", "contenttype"); 220 for(int i=0; i<nl.getLength(); i++) { 221 Element elContentType = (Element )nl.item(i); 222 if(elContentType.getChildNodes().getLength()==1) { 223 Node node = elContentType.getFirstChild(); 224 if(node.getNodeType()==Node.TEXT_NODE) { 225 this.m_aContentTypes.add( ((Text )node).getNodeValue() ); 226 } 227 } 228 } 229 230 nl = elDomain.getElementsByTagNameNS("DAV:", "minOccurs"); 231 for(int i=0; i<nl.getLength(); i++) { 232 Element elMinOccurs = (Element )nl.item(i); 233 if(elMinOccurs.getChildNodes().getLength()==1) { 234 Node node = elMinOccurs.getFirstChild(); 235 if(node.getNodeType()==Node.TEXT_NODE) { 236 this.m_nMinOccurs = Integer.parseInt( ((Text )node).getNodeValue() ); 237 } 238 } 239 } 240 241 nl = elDomain.getElementsByTagNameNS("DAV:", "maxOccurs"); 242 for(int i=0; i<nl.getLength(); i++) { 243 Element elMaxOccurs = (Element )nl.item(i); 244 if(elMaxOccurs.getChildNodes().getLength()==1) { 245 Node node = elMaxOccurs.getFirstChild(); 246 if(node.getNodeType()==Node.TEXT_NODE) { 247 this.m_nMaxOccurs = Integer.parseInt( ((Text )node).getNodeValue() ); 248 } 249 } 250 } 251 } 252 253 public String toString() { 254 StringBuffer sBuff = new StringBuffer (); 255 256 sBuff.append("Domain:\n") 257 .append("Resourcetype: ").append(this.m_sResourceType).append("\n") 258 .append("MinOccurs: ").append(this.m_nMinOccurs).append("\n") 259 .append("MaxOccurs: ").append(this.m_nMaxOccurs).append("\n"); 260 261 Iterator itor = this.m_aContentTypes.iterator(); 262 while(itor.hasNext()) { 263 sBuff.append("Contenttype: ").append(((String )itor.next())).append("\n"); 264 } 265 266 itor = this.m_aPaths.iterator(); 267 while(itor.hasNext()) { 268 sBuff.append("Path: ").append(((String )itor.next())).append("\n"); 269 } 270 271 return sBuff.toString(); 272 } 273 274 } 275 | Popular Tags |