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
This commit is contained in:
David Caruana 2008-04-07 15:31:47 +00:00
parent 0e407d054b
commit 9aaeac4558
3 changed files with 49 additions and 8 deletions

View File

@ -40,10 +40,15 @@ import java.util.Map;
*/
/*package*/ class BehaviourMap<B extends BehaviourBinding>
{
/**
* The count of behaviours
*/
int size = 0;
/**
* The map of bindings to behaviour
*/
private Map<B, BehaviourDefinition<B>> index = new HashMap<B, BehaviourDefinition<B>>();
private Map<B, List<BehaviourDefinition<B>>> index = new HashMap<B, List<BehaviourDefinition<B>>>();
/**
* The list of registered observers
@ -59,11 +64,28 @@ import java.util.Map;
public void put(BehaviourDefinition<B> behaviourDefinition)
{
B binding = behaviourDefinition.getBinding();
index.put(binding, behaviourDefinition);
List<BehaviourDefinition<B>> existing = index.get(binding);
if (existing == null)
{
List<BehaviourDefinition<B>> behaviourList = new ArrayList<BehaviourDefinition<B>>();
behaviourList.add(behaviourDefinition);
index.put(binding, behaviourList);
size++;
}
else
{
if (!existing.contains(behaviourDefinition))
{
existing.add(behaviourDefinition);
size++;
}
}
for (BehaviourChangeObserver<B> listener : observers)
{
listener.addition(binding, behaviourDefinition.getBehaviour());
}
}
@ -73,7 +95,7 @@ import java.util.Map;
* @param binding the binding
* @return the behaviour
*/
public BehaviourDefinition<B> get(B binding)
public List<BehaviourDefinition<B>> get(B binding)
{
return index.get(binding);
}
@ -86,7 +108,12 @@ import java.util.Map;
*/
public Collection<BehaviourDefinition<B>> getAll()
{
return index.values();
List<BehaviourDefinition<B>> allBehaviours = new ArrayList<BehaviourDefinition<B>>(size);
for (List<BehaviourDefinition<B>> behaviours : index.values())
{
allBehaviours.addAll(behaviours);
}
return allBehaviours;
}
@ -97,7 +124,7 @@ import java.util.Map;
*/
public int size()
{
return index.size();
return size;
}

View File

@ -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<BehaviourDefinition<B>> 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);
}
}

View File

@ -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<TestClassPolicy> 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;