KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > rule > ruletrigger > SingleChildAssocRefPolicyRuleTrigger


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

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 JavaDoc ERR_POLICY_NAME_NOT_SET = "Unable to register rule trigger since policy name has not been set.";
30     
31     /**
32      * The logger
33      */

34     private static Log logger = LogFactory.getLog(SingleChildAssocRefPolicyRuleTrigger.class);
35     
36     private String JavaDoc policyNamespace = NamespaceService.ALFRESCO_URI;
37     
38     private String JavaDoc policyName;
39     
40     private boolean isClassBehaviour = false;
41     
42     public void setPolicyNamespace(String JavaDoc policyNamespace)
43     {
44         this.policyNamespace = policyNamespace;
45     }
46     
47     public void setPolicyName(String JavaDoc policyName)
48     {
49         this.policyName = policyName;
50     }
51     
52     public void setIsClassBehaviour(boolean isClassBehaviour)
53     {
54         this.isClassBehaviour = isClassBehaviour;
55     }
56     
57     /**
58      * @see org.alfresco.repo.rule.ruletrigger.RuleTrigger#registerRuleTrigger()
59      */

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