1 17 package org.alfresco.repo.rule.ruletrigger; 18 19 import org.alfresco.repo.policy.JavaBehaviour; 20 import org.alfresco.service.cmr.repository.ChildAssociationRef; 21 import org.alfresco.service.cmr.rule.RuleServiceException; 22 import org.alfresco.service.namespace.NamespaceService; 23 import org.alfresco.service.namespace.QName; 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 27 public class SingleChildAssocRefPolicyRuleTrigger extends RuleTriggerAbstractBase 28 { 29 private static final String ERR_POLICY_NAME_NOT_SET = "Unable to register rule trigger since policy name has not been set."; 30 31 34 private static Log logger = LogFactory.getLog(SingleChildAssocRefPolicyRuleTrigger.class); 35 36 private String policyNamespace = NamespaceService.ALFRESCO_URI; 37 38 private String policyName; 39 40 private boolean isClassBehaviour = false; 41 42 public void setPolicyNamespace(String policyNamespace) 43 { 44 this.policyNamespace = policyNamespace; 45 } 46 47 public void setPolicyName(String policyName) 48 { 49 this.policyName = policyName; 50 } 51 52 public void setIsClassBehaviour(boolean isClassBehaviour) 53 { 54 this.isClassBehaviour = isClassBehaviour; 55 } 56 57 60 public void registerRuleTrigger() 61 { 62 if (policyName == null) 63 { 64 throw new RuleServiceException(ERR_POLICY_NAME_NOT_SET); 65 } 66 67 if (isClassBehaviour == true) 68 { 69 this.policyComponent.bindClassBehaviour( 70 QName.createQName(this.policyNamespace, this.policyName), 71 this, 72 new JavaBehaviour(this, "policyBehaviour")); 73 } 74 else 75 { 76 this.policyComponent.bindAssociationBehaviour( 77 QName.createQName(this.policyNamespace, this.policyName), 78 this, 79 new JavaBehaviour(this, "policyBehaviour")); 80 } 81 } 82 83 public void policyBehaviour(ChildAssociationRef childAssocRef) 84 { 85 if (logger.isDebugEnabled() == true) 86 { 87 logger.debug("Single child assoc trigger (policy = " + this.policyName + ") fired for parent node " + childAssocRef.getParentRef() + " and child node " + childAssocRef.getChildRef()); 88 } 89 90 triggerRules(childAssocRef.getParentRef(), childAssocRef.getChildRef()); 91 } 92 } 93 | Popular Tags |