1 17 package org.alfresco.repo.policy; 18 19 import java.util.Collection ; 20 import java.util.HashSet ; 21 import java.util.Set ; 22 23 import org.alfresco.service.cmr.dictionary.DictionaryService; 24 import org.alfresco.service.cmr.dictionary.PropertyDefinition; 25 import org.alfresco.service.cmr.repository.NodeRef; 26 import org.alfresco.service.namespace.QName; 27 28 29 37 public class PropertyPolicyDelegate<P extends PropertyPolicy> 38 { 39 private DictionaryService dictionary; 40 private CachedPolicyFactory<ClassFeatureBehaviourBinding, P> factory; 41 42 43 50 @SuppressWarnings ("unchecked") 51 PropertyPolicyDelegate(DictionaryService dictionary, Class <P> policyClass, BehaviourIndex<ClassFeatureBehaviourBinding> index) 52 { 53 Collection <BehaviourDefinition> definitions = index.getAll(); 56 for (BehaviourDefinition definition : definitions) 57 { 58 definition.getBehaviour().getInterface(policyClass); 59 } 60 61 this.factory = new CachedPolicyFactory<ClassFeatureBehaviourBinding, P>(policyClass, index); 64 this.dictionary = dictionary; 65 } 66 67 73 private void checkPropertyType(QName propertyQName) throws IllegalArgumentException 74 { 75 PropertyDefinition propertyDef = dictionary.getProperty(propertyQName); 76 if (propertyDef == null) 77 { 78 throw new IllegalArgumentException ("Property " + propertyQName + " has not been defined in the data dictionary"); 79 } 80 } 81 82 83 94 public P get(QName classQName, QName propertyQName) 95 { 96 return get(null, classQName, propertyQName); 97 } 98 99 111 public P get(NodeRef nodeRef, QName classQName, QName propertyQName) 112 { 113 checkPropertyType(propertyQName); 114 return factory.create(new ClassFeatureBehaviourBinding(dictionary, nodeRef, classQName, propertyQName)); 115 } 116 117 124 public Collection <P> getList(QName classQName, QName propertyQName) 125 { 126 return getList(null, classQName, propertyQName); 127 } 128 129 137 public Collection <P> getList(NodeRef nodeRef, QName classQName, QName propertyQName) 138 { 139 checkPropertyType(propertyQName); 140 return factory.createList(new ClassFeatureBehaviourBinding(dictionary, nodeRef, classQName, propertyQName)); 141 } 142 143 150 public P get(Set <QName> classQNames, QName propertyQName) 151 { 152 return get(null, classQNames, propertyQName); 153 } 154 155 163 public P get(NodeRef nodeRef, Set <QName> classQNames, QName propertyQName) 164 { 165 checkPropertyType(propertyQName); 166 return factory.toPolicy(getList(nodeRef, classQNames, propertyQName)); 167 } 168 169 176 public Collection <P> getList(Set <QName> classQNames, QName propertyQName) 177 { 178 return getList(null, classQNames, propertyQName); 179 } 180 181 189 public Collection <P> getList(NodeRef nodeRef, Set <QName> classQNames, QName propertyQName) 190 { 191 checkPropertyType(propertyQName); 192 Collection <P> policies = new HashSet <P>(); 193 for (QName classQName : classQNames) 194 { 195 P policy = factory.create(new ClassFeatureBehaviourBinding(dictionary, nodeRef, classQName, propertyQName)); 196 if (policy instanceof PolicyList) 197 { 198 policies.addAll(((PolicyList<P>)policy).getPolicies()); 199 } 200 else 201 { 202 policies.add(policy); 203 } 204 } 205 return policies; 206 } 207 208 } 209 | Popular Tags |