KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.List JavaDoc;
20
21 import org.alfresco.repo.policy.JavaBehaviour;
22 import org.alfresco.service.cmr.repository.ChildAssociationRef;
23 import org.alfresco.service.cmr.repository.NodeRef;
24 import org.alfresco.service.cmr.rule.RuleServiceException;
25 import org.alfresco.service.namespace.NamespaceService;
26 import org.alfresco.service.namespace.QName;
27
28 public class SingleNodeRefPolicyRuleTrigger extends RuleTriggerAbstractBase
29 {
30     private static final String JavaDoc ERR_POLICY_NAME_NOT_SET = "Unable to register rule trigger since policy name has not been set.";
31     
32     private String JavaDoc policyNamespace = NamespaceService.ALFRESCO_URI;
33     
34     private String JavaDoc policyName;
35     
36     private boolean triggerParentRules = true;
37     
38     public void setPolicyNamespace(String JavaDoc policyNamespace)
39     {
40         this.policyNamespace = policyNamespace;
41     }
42     
43     public void setPolicyName(String JavaDoc policyName)
44     {
45         this.policyName = policyName;
46     }
47     
48     public void setTriggerParentRules(boolean triggerParentRules)
49     {
50         this.triggerParentRules = triggerParentRules;
51     }
52     
53     public void registerRuleTrigger()
54     {
55         if (policyName == null)
56         {
57             throw new RuleServiceException(ERR_POLICY_NAME_NOT_SET);
58         }
59         
60         this.policyComponent.bindClassBehaviour(
61                 QName.createQName(this.policyNamespace, this.policyName),
62                 this,
63                 new JavaBehaviour(this, "policyBehaviour"));
64     }
65
66     public void policyBehaviour(NodeRef nodeRef)
67     {
68         if (triggerParentRules == true)
69         {
70             List JavaDoc<ChildAssociationRef> parentsAssocRefs = this.nodeService.getParentAssocs(nodeRef);
71             for (ChildAssociationRef parentAssocRef : parentsAssocRefs)
72             {
73                 triggerRules(parentAssocRef.getParentRef(), nodeRef);
74             }
75         }
76         else
77         {
78             triggerRules(nodeRef, nodeRef);
79         }
80     }
81 }
82
Popular Tags