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.openharmonise.vfs.*; 26 import org.openharmonise.vfs.event.*; 27 import org.openharmonise.vfs.metadata.range.*; 28 import org.openharmonise.vfs.metadata.value.*; 29 import org.openharmonise.vfs.servers.ServerList; 30 31 32 40 public class PropertyInstance { 41 42 45 private String m_sNamespaceURI = null; 46 47 50 private String m_sName = null; 51 52 55 private String m_sPropDefnPath = null; 56 57 60 private String m_sPropDefnVersion = null; 61 62 65 private ArrayList m_values = new ArrayList (); 66 67 70 private VirtualFile m_vfFile = null; 71 72 public PropertyInstance() { 73 super(); 74 } 75 76 82 public PropertyInstance(String sNamespaceURI, String sName) { 83 super(); 84 this.m_sNamespaceURI = sNamespaceURI; 85 this.m_sName = sName; 86 } 87 88 95 public PropertyInstance(String sNamespaceURI, String sName, List aValues) { 96 this(sNamespaceURI, sName); 97 this.m_values.addAll(aValues); 98 } 99 100 104 public void clearAllValues() { 105 this.m_values.clear(); 106 if(this.m_vfFile!=null) { 107 this.m_vfFile.fireVirtualFileEvent(VirtualFileEvent.FILE_METADATA_CHANGED); 108 } else { 109 } 110 } 111 112 117 public String getNamespaceURI() { 118 return this.m_sNamespaceURI; 119 } 120 121 126 public void setNamespaceURI(String sNamespaceURI) { 127 this.m_sNamespaceURI = sNamespaceURI; 128 } 129 130 135 public String getName() { 136 return this.m_sName; 137 } 138 139 144 public void setName(String sName) { 145 this.m_sName = sName; 146 } 147 148 153 public List getValues() { 154 return (List )this.m_values.clone(); 155 } 156 157 162 public void setValue(ValueInstance value) { 163 if(this.m_values.size()>0) { 164 this.m_values.set(0, value); 165 } else { 166 this.m_values.add(value); 167 } 168 if(this.m_vfFile!=null) { 169 this.m_vfFile.fireVirtualFileEvent(VirtualFileEvent.FILE_METADATA_CHANGED); 170 } else { 171 } 172 } 173 174 179 public void setValues(List aValues) { 180 this.m_values=(ArrayList ) aValues; 181 if(this.m_vfFile!=null) { 182 this.m_vfFile.fireVirtualFileEvent(VirtualFileEvent.FILE_METADATA_CHANGED); 183 } else { 184 } 185 } 186 187 194 public void addValueWithoutFiringVirtualFileEvent(ValueInstance value) { 195 boolean bAddValue = true; 196 if(this.getDefinition().getRange() instanceof ValueRange) { 197 if( !((ValueRange)this.getDefinition().getRange()).validate(value).isValid() ) { 198 bAddValue=false; 199 } 200 } 201 202 if(bAddValue && !this.m_values.contains(value)) { 203 this.m_values.add(value); 204 } 205 } 206 207 212 public void addValue(ValueInstance value) { 213 boolean bAddValue = true; 214 if(this.getDefinition().getRange() instanceof ValueRange) { 215 if( !((ValueRange)this.getDefinition().getRange()).validate(value).isValid() ) { 216 bAddValue=false; 217 } 218 } 219 220 if(bAddValue && !this.m_values.contains(value)) { 221 this.m_values.add(value); 222 } 223 if(bAddValue && this.m_vfFile!=null) { 224 this.m_vfFile.fireVirtualFileEvent(VirtualFileEvent.FILE_METADATA_CHANGED); 225 } 226 } 227 228 233 public void removeValue(ValueInstance value) { 234 this.m_values.remove(value); 235 if(this.m_vfFile!=null) { 236 this.m_vfFile.fireVirtualFileEvent(VirtualFileEvent.FILE_METADATA_CHANGED); 237 } 238 } 239 244 public void removeValueWithoutFiringVirtualFileEvent(ValueInstance value) { 245 this.m_values.remove(value); 246 } 247 248 255 public void setDefinitionPath(String sPath, String sVersion) { 256 this.m_sPropDefnPath = sPath; 257 this.m_sPropDefnVersion = sVersion; 258 } 259 260 266 public String getDefinitionPath() { 267 return this.m_sPropDefnPath; 268 } 269 270 276 public String getDefinitionVersion() { 277 return this.m_sPropDefnVersion; 278 } 279 280 285 public Property getDefinition() { 286 if(this.m_sPropDefnPath!=null) { 287 Property prop = PropertyCache.getInstance().getPropertyByPath(m_sPropDefnPath, m_sPropDefnVersion); 288 if(prop!=null) { 289 prop.setNamespace(m_sNamespaceURI); 290 return prop; 291 } else { 292 return PropertyCache.getInstance().getPropertyByName(this.m_sNamespaceURI, this.m_sName); 293 } 294 } else { 295 return PropertyCache.getInstance().getPropertyByName(this.m_sNamespaceURI, this.m_sName); 296 } 297 } 298 299 public String toString() { 300 return this.m_sNamespaceURI + ":" + this.m_sName + ":" + this.m_values; 301 } 302 303 308 public void setVirtualFile(VirtualFile vfFile) { 309 this.m_vfFile = vfFile; 310 if(this.getDefinition()!=null && this.getDefinition().getRange() instanceof PropertyRange) { 311 Iterator itor = this.m_values.iterator(); 312 while(itor.hasNext()) { 313 PropertyValue val = (PropertyValue)itor.next(); 314 Iterator itor2 = val.getValue().iterator(); 315 while (itor2.hasNext()) { 316 PropertyInstance propInst = (PropertyInstance) itor2.next(); 317 propInst.setVirtualFile(vfFile); 318 } 319 } 320 } 321 } 322 323 328 public VirtualFile getVirtualFile() { 329 return this.m_vfFile; 330 } 331 332 338 public ValueInstance getNewValueInstance() { 339 if(this.m_vfFile.getVFS()!=null) { 340 return this.m_vfFile.getVFS().getNewValueInstance(this); 341 } else { 342 return ServerList.getInstance().getHarmoniseServer().getVFS().getNewValueInstance(this); 343 } 344 } 345 346 349 public boolean equals(Object arg0) { 350 if(super.equals(arg0)) { 351 return true; 352 } else if(arg0 instanceof PropertyInstance) { 353 PropertyInstance propInst = (PropertyInstance)arg0; 354 if(propInst.m_sName.equals(this.m_sName) 355 && propInst.m_sNamespaceURI.equals(this.m_sNamespaceURI) 356 && propInst.m_values.containsAll(this.m_values)) { 357 return true; 358 } else { 359 return false; 360 } 361 } else { 362 return false; 363 } 364 } 365 366 367 } 368 | Popular Tags |