diff --git a/source/java/org/alfresco/repo/googledocs/GoogleEditableAspect.java b/source/java/org/alfresco/repo/googledocs/GoogleEditableAspect.java index 098280063a..785ddcc536 100755 --- a/source/java/org/alfresco/repo/googledocs/GoogleEditableAspect.java +++ b/source/java/org/alfresco/repo/googledocs/GoogleEditableAspect.java @@ -21,7 +21,9 @@ package org.alfresco.repo.googledocs; import java.io.InputStream; import java.io.Serializable; import java.util.Collections; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.model.ContentModel; @@ -35,6 +37,8 @@ import org.alfresco.repo.copy.DefaultCopyBehaviourCallback; import org.alfresco.repo.node.NodeServicePolicies; import org.alfresco.repo.node.NodeServicePolicies.BeforeDeleteNodePolicy; import org.alfresco.repo.node.NodeServicePolicies.OnAddAspectPolicy; +import org.alfresco.repo.policy.BehaviourDefinition; +import org.alfresco.repo.policy.ClassBehaviourBinding; import org.alfresco.repo.policy.JavaBehaviour; import org.alfresco.repo.policy.PolicyComponent; import org.alfresco.repo.policy.Behaviour.NotificationFrequency; @@ -46,6 +50,7 @@ import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; +import org.springframework.beans.factory.DisposableBean; /** * Behaviour associated with google editable documents @@ -55,7 +60,8 @@ public class GoogleEditableAspect implements NodeServicePolicies.OnAddAspectPoli CheckOutCheckInServicePolicies.OnCheckOut, CheckOutCheckInServicePolicies.BeforeCheckIn, CheckOutCheckInServicePolicies.OnCheckIn, - NodeServicePolicies.BeforeDeleteNodePolicy + NodeServicePolicies.BeforeDeleteNodePolicy, + DisposableBean { /** Policy component */ private PolicyComponent policyComponent; @@ -72,6 +78,9 @@ public class GoogleEditableAspect implements NodeServicePolicies.OnAddAspectPoli /** Content service */ private ContentService contentService; + /** binded behaviours definitions*/ + private Set> behaviours; + /** * @param policyComponent policy component */ @@ -117,34 +126,35 @@ public class GoogleEditableAspect implements NodeServicePolicies.OnAddAspectPoli */ public void init() { + behaviours = new HashSet>(); // GoogleEditable resource behaviours - policyComponent.bindClassBehaviour(OnAddAspectPolicy.QNAME, + behaviours.add(policyComponent.bindClassBehaviour(OnAddAspectPolicy.QNAME, GoogleDocsModel.ASPECT_GOOGLEEDITABLE , - new JavaBehaviour(this, "onAddAspect", NotificationFrequency.FIRST_EVENT)); - policyComponent.bindClassBehaviour(OnCheckOut.QNAME, + new JavaBehaviour(this, "onAddAspect", NotificationFrequency.FIRST_EVENT))); + behaviours.add(policyComponent.bindClassBehaviour(OnCheckOut.QNAME, GoogleDocsModel.ASPECT_GOOGLEEDITABLE, - new JavaBehaviour(this, "onCheckOut", NotificationFrequency.FIRST_EVENT)); + new JavaBehaviour(this, "onCheckOut", NotificationFrequency.FIRST_EVENT))); // Google resource behaviours - policyComponent.bindClassBehaviour(BeforeCheckIn.QNAME, + behaviours.add(policyComponent.bindClassBehaviour(BeforeCheckIn.QNAME, GoogleDocsModel.ASPECT_GOOGLERESOURCE, - new JavaBehaviour(this, "beforeCheckIn", NotificationFrequency.FIRST_EVENT)); - policyComponent.bindClassBehaviour(OnCheckIn.QNAME, + new JavaBehaviour(this, "beforeCheckIn", NotificationFrequency.FIRST_EVENT))); + behaviours.add(policyComponent.bindClassBehaviour(OnCheckIn.QNAME, GoogleDocsModel.ASPECT_GOOGLERESOURCE, - new JavaBehaviour(this, "onCheckIn", NotificationFrequency.FIRST_EVENT)); - policyComponent.bindClassBehaviour(BeforeDeleteNodePolicy.QNAME, + new JavaBehaviour(this, "onCheckIn", NotificationFrequency.FIRST_EVENT))); + behaviours.add(policyComponent.bindClassBehaviour(BeforeDeleteNodePolicy.QNAME, GoogleDocsModel.ASPECT_GOOGLERESOURCE, - new JavaBehaviour(this, "beforeDeleteNode", NotificationFrequency.FIRST_EVENT)); + new JavaBehaviour(this, "beforeDeleteNode", NotificationFrequency.FIRST_EVENT))); // Copy behaviours - this.policyComponent.bindClassBehaviour( + behaviours.add(policyComponent.bindClassBehaviour( QName.createQName(NamespaceService.ALFRESCO_URI, "getCopyCallback"), GoogleDocsModel.ASPECT_GOOGLEEDITABLE, - new JavaBehaviour(this, "getGoogleEditableCopyCallback")); - this.policyComponent.bindClassBehaviour( + new JavaBehaviour(this, "getGoogleEditableCopyCallback"))); + behaviours.add(policyComponent.bindClassBehaviour( QName.createQName(NamespaceService.ALFRESCO_URI, "getCopyCallback"), GoogleDocsModel.ASPECT_GOOGLERESOURCE, - new JavaBehaviour(this, "getGoogleResourceCopyCallback")); + new JavaBehaviour(this, "getGoogleResourceCopyCallback"))); } /** @@ -272,4 +282,13 @@ public class GoogleEditableAspect implements NodeServicePolicies.OnAddAspectPoli return Collections.emptyMap(); } } + + @Override + public void destroy() throws Exception + { + for(BehaviourDefinition definition : behaviours) + { + policyComponent.removeClassDefinition(definition); + } + } } diff --git a/source/java/org/alfresco/repo/policy/BehaviourMap.java b/source/java/org/alfresco/repo/policy/BehaviourMap.java index 8d05096a20..9fc29d2c7d 100644 --- a/source/java/org/alfresco/repo/policy/BehaviourMap.java +++ b/source/java/org/alfresco/repo/policy/BehaviourMap.java @@ -82,6 +82,23 @@ import java.util.Map; } + /** + * Remove behavior from map + * + * @param behaviourDefinition + */ + public void remove(BehaviourDefinition behaviourDefinition) + { + B binding = behaviourDefinition.getBinding(); + List> existing = index.get(binding); + if (existing != null && existing.contains(behaviourDefinition)) + { + existing.remove(behaviourDefinition); + size--; + } + + } + /** * Gets a Behaviour from the Map diff --git a/source/java/org/alfresco/repo/policy/ClassBehaviourBinding.java b/source/java/org/alfresco/repo/policy/ClassBehaviourBinding.java index 525edf64fa..42bba462d7 100644 --- a/source/java/org/alfresco/repo/policy/ClassBehaviourBinding.java +++ b/source/java/org/alfresco/repo/policy/ClassBehaviourBinding.java @@ -30,7 +30,7 @@ import org.alfresco.service.namespace.QName; * @author David Caruana * */ -/*package*/ class ClassBehaviourBinding implements BehaviourBinding +public class ClassBehaviourBinding implements BehaviourBinding { // The dictionary service private DictionaryService dictionary; diff --git a/source/java/org/alfresco/repo/policy/ClassBehaviourIndex.java b/source/java/org/alfresco/repo/policy/ClassBehaviourIndex.java index a9bea6d1ce..c20ed87a71 100644 --- a/source/java/org/alfresco/repo/policy/ClassBehaviourIndex.java +++ b/source/java/org/alfresco/repo/policy/ClassBehaviourIndex.java @@ -213,4 +213,22 @@ import org.alfresco.service.namespace.QName; } } + /** + * Remove class behaviour + * + * @param behaviour + */ + public void removeClassBehaviour(BehaviourDefinition behaviour) + { + lock.writeLock().lock(); + try + { + classMap.remove(behaviour); + } + finally + { + lock.writeLock().unlock(); + } + } + } diff --git a/source/java/org/alfresco/repo/policy/PolicyComponent.java b/source/java/org/alfresco/repo/policy/PolicyComponent.java index 8a27bd2b2f..5cbe8c3486 100644 --- a/source/java/org/alfresco/repo/policy/PolicyComponent.java +++ b/source/java/org/alfresco/repo/policy/PolicyComponent.java @@ -206,6 +206,13 @@ public interface PolicyComponent */ public BehaviourDefinition bindAssociationBehaviour(QName policy, Object service, Behaviour behaviour); + /** + * Unbind behaviour + * + * @param definition + */ + public void removeClassDefinition(BehaviourDefinition definition); + } diff --git a/source/java/org/alfresco/repo/policy/PolicyComponentImpl.java b/source/java/org/alfresco/repo/policy/PolicyComponentImpl.java index 990ec9c0c0..d77a90bb51 100644 --- a/source/java/org/alfresco/repo/policy/PolicyComponentImpl.java +++ b/source/java/org/alfresco/repo/policy/PolicyComponentImpl.java @@ -137,6 +137,11 @@ public class PolicyComponentImpl implements PolicyComponent return delegate; } + @Override + public void removeClassDefinition(BehaviourDefinition definition) + { + getClassBehaviourIndex(definition.getPolicy()).removeClassBehaviour(definition); + } /* (non-Javadoc) * @see org.alfresco.repo.policy.PolicyComponent#registerPropertyPolicy(java.lang.Class)