From 9aaeac455896db34e78bdf956d3b878bf54b61a7 Mon Sep 17 00:00:00 2001 From: David Caruana Date: Mon, 7 Apr 2008 15:31:47 +0000 Subject: [PATCH] Finally resolved "AR-401 Can only have one policy handler". Multiple handlers may now be registered. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@8698 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../alfresco/repo/policy/BehaviourMap.java | 37 ++++++++++++++++--- .../repo/policy/ClassBehaviourIndex.java | 4 +- .../repo/policy/PolicyComponentTest.java | 16 +++++++- 3 files changed, 49 insertions(+), 8 deletions(-) diff --git a/source/java/org/alfresco/repo/policy/BehaviourMap.java b/source/java/org/alfresco/repo/policy/BehaviourMap.java index 139bdb898b..05b54d55f7 100644 --- a/source/java/org/alfresco/repo/policy/BehaviourMap.java +++ b/source/java/org/alfresco/repo/policy/BehaviourMap.java @@ -40,10 +40,15 @@ import java.util.Map; */ /*package*/ class BehaviourMap { + /** + * The count of behaviours + */ + int size = 0; + /** * The map of bindings to behaviour */ - private Map> index = new HashMap>(); + private Map>> index = new HashMap>>(); /** * The list of registered observers @@ -59,11 +64,28 @@ import java.util.Map; public void put(BehaviourDefinition behaviourDefinition) { B binding = behaviourDefinition.getBinding(); - index.put(binding, behaviourDefinition); + List> existing = index.get(binding); + if (existing == null) + { + List> behaviourList = new ArrayList>(); + behaviourList.add(behaviourDefinition); + index.put(binding, behaviourList); + size++; + } + else + { + if (!existing.contains(behaviourDefinition)) + { + existing.add(behaviourDefinition); + size++; + } + } + for (BehaviourChangeObserver listener : observers) { listener.addition(binding, behaviourDefinition.getBehaviour()); } + } @@ -73,7 +95,7 @@ import java.util.Map; * @param binding the binding * @return the behaviour */ - public BehaviourDefinition get(B binding) + public List> get(B binding) { return index.get(binding); } @@ -86,7 +108,12 @@ import java.util.Map; */ public Collection> getAll() { - return index.values(); + List> allBehaviours = new ArrayList>(size); + for (List> behaviours : index.values()) + { + allBehaviours.addAll(behaviours); + } + return allBehaviours; } @@ -97,7 +124,7 @@ import java.util.Map; */ public int size() { - return index.size(); + return size; } diff --git a/source/java/org/alfresco/repo/policy/ClassBehaviourIndex.java b/source/java/org/alfresco/repo/policy/ClassBehaviourIndex.java index 49c8fc65a2..14b54e0940 100644 --- a/source/java/org/alfresco/repo/policy/ClassBehaviourIndex.java +++ b/source/java/org/alfresco/repo/policy/ClassBehaviourIndex.java @@ -139,7 +139,7 @@ import org.alfresco.service.namespace.QName; if (isEnabled) { // Find class behaviour by scanning up the class hierarchy - BehaviourDefinition behaviour = null; + List> behaviour = null; while(behaviour == null && binding != null) { behaviour = classMap.get(binding); @@ -150,7 +150,7 @@ import org.alfresco.service.namespace.QName; } if (behaviour != null) { - behaviours.add(behaviour); + behaviours.addAll(behaviour); } } diff --git a/source/java/org/alfresco/repo/policy/PolicyComponentTest.java b/source/java/org/alfresco/repo/policy/PolicyComponentTest.java index a903cb1220..b07059741e 100644 --- a/source/java/org/alfresco/repo/policy/PolicyComponentTest.java +++ b/source/java/org/alfresco/repo/policy/PolicyComponentTest.java @@ -283,6 +283,15 @@ public class PolicyComponentTest extends TestCase assertTrue(file2Policies.size() == 2); TestClassPolicy filePolicy2 = delegate.get(FILE_TYPE); assertNotNull(filePolicy2); + + // Test multiple class behaviours + Behaviour file2Behaviour = new JavaBehaviour(this, "fileTest2"); + policyComponent.bindClassBehaviour(policyName, FILE_TYPE, file2Behaviour); + Collection file3Policies = delegate.getList(FILE_TYPE); + assertNotNull(file3Policies); + assertTrue(file3Policies.size() == 3); + TestClassPolicy filePolicy3 = delegate.get(FILE_TYPE); + assertNotNull(filePolicy3); } @@ -623,7 +632,12 @@ public class PolicyComponentTest extends TestCase { return "File: " + argument; } - + + public String fileTest2(String argument) + { + return "File2: " + argument; + } + public String folderTest(String argument) { return "Folder: " + argument;