mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-06-16 17:55:15 +00:00
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:
parent
0e407d054b
commit
9aaeac4558
@ -40,10 +40,15 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
/*package*/ class BehaviourMap<B extends BehaviourBinding>
|
/*package*/ class BehaviourMap<B extends BehaviourBinding>
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* The count of behaviours
|
||||||
|
*/
|
||||||
|
int size = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The map of bindings to behaviour
|
* 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
|
* The list of registered observers
|
||||||
@ -59,11 +64,28 @@ import java.util.Map;
|
|||||||
public void put(BehaviourDefinition<B> behaviourDefinition)
|
public void put(BehaviourDefinition<B> behaviourDefinition)
|
||||||
{
|
{
|
||||||
B binding = behaviourDefinition.getBinding();
|
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)
|
for (BehaviourChangeObserver<B> listener : observers)
|
||||||
{
|
{
|
||||||
listener.addition(binding, behaviourDefinition.getBehaviour());
|
listener.addition(binding, behaviourDefinition.getBehaviour());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -73,7 +95,7 @@ import java.util.Map;
|
|||||||
* @param binding the binding
|
* @param binding the binding
|
||||||
* @return the behaviour
|
* @return the behaviour
|
||||||
*/
|
*/
|
||||||
public BehaviourDefinition<B> get(B binding)
|
public List<BehaviourDefinition<B>> get(B binding)
|
||||||
{
|
{
|
||||||
return index.get(binding);
|
return index.get(binding);
|
||||||
}
|
}
|
||||||
@ -86,7 +108,12 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
public Collection<BehaviourDefinition<B>> getAll()
|
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()
|
public int size()
|
||||||
{
|
{
|
||||||
return index.size();
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ import org.alfresco.service.namespace.QName;
|
|||||||
if (isEnabled)
|
if (isEnabled)
|
||||||
{
|
{
|
||||||
// Find class behaviour by scanning up the class hierarchy
|
// Find class behaviour by scanning up the class hierarchy
|
||||||
BehaviourDefinition behaviour = null;
|
List<BehaviourDefinition<B>> behaviour = null;
|
||||||
while(behaviour == null && binding != null)
|
while(behaviour == null && binding != null)
|
||||||
{
|
{
|
||||||
behaviour = classMap.get(binding);
|
behaviour = classMap.get(binding);
|
||||||
@ -150,7 +150,7 @@ import org.alfresco.service.namespace.QName;
|
|||||||
}
|
}
|
||||||
if (behaviour != null)
|
if (behaviour != null)
|
||||||
{
|
{
|
||||||
behaviours.add(behaviour);
|
behaviours.addAll(behaviour);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,6 +283,15 @@ public class PolicyComponentTest extends TestCase
|
|||||||
assertTrue(file2Policies.size() == 2);
|
assertTrue(file2Policies.size() == 2);
|
||||||
TestClassPolicy filePolicy2 = delegate.get(FILE_TYPE);
|
TestClassPolicy filePolicy2 = delegate.get(FILE_TYPE);
|
||||||
assertNotNull(filePolicy2);
|
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;
|
return "File: " + argument;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String fileTest2(String argument)
|
||||||
|
{
|
||||||
|
return "File2: " + argument;
|
||||||
|
}
|
||||||
|
|
||||||
public String folderTest(String argument)
|
public String folderTest(String argument)
|
||||||
{
|
{
|
||||||
return "Folder: " + argument;
|
return "Folder: " + argument;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user