1 17 package org.alfresco.repo.policy; 18 19 import java.io.Serializable ; 20 import java.util.ArrayList ; 21 import java.util.HashMap ; 22 import java.util.List ; 23 import java.util.Map ; 24 import java.util.Set ; 25 26 import org.alfresco.service.cmr.repository.ChildAssociationRef; 27 import org.alfresco.service.cmr.repository.AssociationRef; 28 import org.alfresco.service.namespace.QName; 29 30 38 public class PolicyScope extends AspectDetails 39 { 40 43 protected Map <QName, AspectDetails> aspectCopyDetails = new HashMap <QName, AspectDetails>(); 44 45 50 public PolicyScope(QName classRef) 51 { 52 super(classRef); 53 } 54 55 62 public void addProperty(QName classRef, QName qName, Serializable value) 63 { 64 if (classRef.equals(this.classRef) == true) 65 { 66 addProperty(qName, value); 67 } 68 else 69 { 70 AspectDetails aspectDetails = this.aspectCopyDetails.get(classRef); 71 if (aspectDetails == null) 72 { 73 aspectDetails = addAspect(classRef); 75 } 76 aspectDetails.addProperty(qName, value); 77 } 78 } 79 80 86 public void removeProperty(QName classRef, QName qName) 87 { 88 if (classRef.equals(this.classRef) == true) 89 { 90 removeProperty(qName); 91 } 92 else 93 { 94 AspectDetails aspectDetails = this.aspectCopyDetails.get(classRef); 95 if (aspectDetails != null) 96 { 97 aspectDetails.removeProperty(qName); 98 } 99 } 100 } 101 102 108 public Map <QName, Serializable > getProperties(QName classRef) 109 { 110 Map <QName, Serializable > result = null; 111 if (classRef.equals(this.classRef) == true) 112 { 113 result = getProperties(); 114 } 115 else 116 { 117 AspectDetails aspectDetails = this.aspectCopyDetails.get(classRef); 118 if (aspectDetails != null) 119 { 120 result = aspectDetails.getProperties(); 121 } 122 } 123 124 return result; 125 } 126 127 134 public void addChildAssociation(QName classRef, ChildAssociationRef childAssocRef) 135 { 136 if (classRef.equals(this.classRef) == true) 137 { 138 addChildAssociation(childAssocRef); 139 } 140 else 141 { 142 AspectDetails aspectDetails = this.aspectCopyDetails.get(classRef); 143 if (aspectDetails == null) 144 { 145 aspectDetails = addAspect(classRef); 147 } 148 aspectDetails.addChildAssociation(childAssocRef); 149 } 150 } 151 152 158 public void addChildAssociation(QName classRef, ChildAssociationRef childAssocRef, boolean alwaysTraverseAssociation) 159 { 160 if (classRef.equals(this.classRef) == true) 161 { 162 addChildAssociation(childAssocRef, alwaysTraverseAssociation); 163 } 164 else 165 { 166 AspectDetails aspectDetails = this.aspectCopyDetails.get(classRef); 167 if (aspectDetails == null) 168 { 169 aspectDetails = addAspect(classRef); 171 } 172 aspectDetails.addChildAssociation(childAssocRef, alwaysTraverseAssociation); 173 } 174 } 175 176 182 public List <ChildAssociationRef> getChildAssociations(QName classRef) 183 { 184 List <ChildAssociationRef> result = null; 185 if (classRef.equals(this.classRef) == true) 186 { 187 result = getChildAssociations(); 188 } 189 else 190 { 191 AspectDetails aspectDetails = this.aspectCopyDetails.get(classRef); 192 if (aspectDetails != null) 193 { 194 result = aspectDetails.getChildAssociations(); 195 } 196 } 197 198 return result; 199 } 200 201 public boolean isChildAssociationRefAlwaysTraversed(QName classRef, ChildAssociationRef childAssocRef) 202 { 203 boolean result = false; 204 if (classRef.equals(this.classRef) == true) 205 { 206 result = isChildAssociationRefAlwaysTraversed(childAssocRef); 207 } 208 else 209 { 210 AspectDetails aspectDetails = this.aspectCopyDetails.get(classRef); 211 if (aspectDetails != null) 212 { 213 result = aspectDetails.isChildAssociationRefAlwaysTraversed(childAssocRef); 214 } 215 } 216 217 return result; 218 } 219 220 227 public void addAssociation(QName classRef, AssociationRef nodeAssocRef) 228 { 229 if (classRef.equals(this.classRef) == true) 230 { 231 addAssociation(nodeAssocRef); 232 } 233 else 234 { 235 AspectDetails aspectDetails = this.aspectCopyDetails.get(classRef); 236 if (aspectDetails == null) 237 { 238 aspectDetails = addAspect(classRef); 240 } 241 aspectDetails.addAssociation(nodeAssocRef); 242 } 243 } 244 245 246 247 253 public List <AssociationRef> getAssociations(QName classRef) 254 { 255 List <AssociationRef> result = null; 256 if (classRef.equals(this.classRef) == true) 257 { 258 result = getAssociations(); 259 } 260 else 261 { 262 AspectDetails aspectDetails = this.aspectCopyDetails.get(classRef); 263 if (aspectDetails != null) 264 { 265 result = aspectDetails.getAssociations(); 266 } 267 } 268 269 return result; 270 } 271 272 278 public AspectDetails addAspect(QName aspect) 279 { 280 AspectDetails result = new AspectDetails(aspect); 281 this.aspectCopyDetails.put(aspect, result); 282 return result; 283 } 284 285 290 public void removeAspect(QName aspect) 291 { 292 this.aspectCopyDetails.remove(aspect); 293 } 294 295 300 public Set <QName> getAspects() 301 { 302 return this.aspectCopyDetails.keySet(); 303 } 304 } 305 306 313 class AspectDetails 314 { 315 318 protected Map <QName, Serializable > properties = new HashMap <QName, Serializable >(); 319 320 323 protected List <ChildAssociationRef> childAssocs = new ArrayList <ChildAssociationRef>(); 324 325 328 protected List <AssociationRef> targetAssocs = new ArrayList <AssociationRef>(); 329 330 333 protected QName classRef; 334 335 338 protected Map <ChildAssociationRef, ChildAssociationRef> alwaysTraverseMap = new HashMap <ChildAssociationRef, ChildAssociationRef>(); 339 340 345 public AspectDetails(QName classRef) 346 { 347 this.classRef = classRef; 348 } 349 350 356 public void addProperty(QName qName, Serializable value) 357 { 358 this.properties.put(qName, value); 359 } 360 361 366 public void removeProperty(QName qName) 367 { 368 this.properties.remove(qName); 369 } 370 371 376 public Map <QName, Serializable > getProperties() 377 { 378 return properties; 379 } 380 381 386 protected void addChildAssociation(ChildAssociationRef childAssocRef) 387 { 388 this.childAssocs.add(childAssocRef); 389 } 390 391 397 protected void addChildAssociation(ChildAssociationRef childAssocRef, boolean alwaysTraverseAssociation) 398 { 399 addChildAssociation(childAssocRef); 400 401 if (alwaysTraverseAssociation == true) 402 { 403 this.alwaysTraverseMap.put(childAssocRef, childAssocRef); 405 } 406 } 407 408 414 protected boolean isChildAssociationRefAlwaysTraversed(ChildAssociationRef childAssocRef) 415 { 416 return this.alwaysTraverseMap.containsKey(childAssocRef); 417 } 418 419 424 public List <ChildAssociationRef> getChildAssociations() 425 { 426 return this.childAssocs; 427 } 428 429 435 protected void addAssociation(AssociationRef nodeAssocRef) 436 { 437 this.targetAssocs.add(nodeAssocRef); 438 } 439 440 445 public List <AssociationRef> getAssociations() 446 { 447 return this.targetAssocs; 448 } 449 } | Popular Tags |