KickJava   Java API By Example, From Geeks To Geeks.

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


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.content.ContentServicePolicies;
22 import org.alfresco.repo.policy.JavaBehaviour;
23 import org.alfresco.service.cmr.repository.ChildAssociationRef;
24 import org.alfresco.service.cmr.repository.NodeRef;
25
26 /**
27  * @author Roy Wetherall
28  */

29 public class OnContentUpdateRuleTrigger extends RuleTriggerAbstractBase
30                                         implements ContentServicePolicies.OnContentUpdatePolicy
31 {
32     /** True trigger on new content, false otherwise */
33     private boolean onNewContent = false;
34     
35     /** True trigger parent rules, false otherwier */
36     private boolean triggerParentRules = true;
37     
38     /**
39      * If set to true the trigger will fire on new content, otherwise it will fire on content update
40      *
41      * @param onNewContent indicates whether to fire on content create or update
42      */

43     public void setOnNewContent(boolean onNewContent)
44     {
45         this.onNewContent = onNewContent;
46     }
47     
48     /**
49      * Indicates whether the parent rules should be triggered or the rules on the node itself
50      *
51      * @param triggerParentRules true trigger parent rules, false otherwise
52      */

53     public void setTriggerParentRules(boolean triggerParentRules)
54     {
55         this.triggerParentRules = triggerParentRules;
56     }
57
58     /*
59      * @see org.alfresco.repo.rule.ruletrigger.RuleTrigger#registerRuleTrigger()
60      */

61     public void registerRuleTrigger()
62     {
63         // Bind behaviour
64
this.policyComponent.bindClassBehaviour(
65                 ContentServicePolicies.ON_CONTENT_UPDATE,
66                 this,
67                 new JavaBehaviour(this, "onContentUpdate"));
68     }
69
70     /**
71      * @see org.alfresco.repo.content.ContentServicePolicies.OnContentUpdatePolicy#onContentUpdate(org.alfresco.service.cmr.repository.NodeRef, boolean)
72      */

73     public void onContentUpdate(NodeRef nodeRef, boolean newContent)
74     {
75         if (newContent == this.onNewContent)
76         {
77             if (triggerParentRules == true)
78             {
79                 List JavaDoc<ChildAssociationRef> parentsAssocRefs = this.nodeService.getParentAssocs(nodeRef);
80                 for (ChildAssociationRef parentAssocRef : parentsAssocRefs)
81                 {
82                     triggerRules(parentAssocRef.getParentRef(), nodeRef);
83                 }
84             }
85             else
86             {
87                 triggerRules(nodeRef, nodeRef);
88             }
89         }
90     }
91
92 }
93
Popular Tags