KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > action > ActionsAspect


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.action;
18
19 import java.util.List JavaDoc;
20 import java.util.Map JavaDoc;
21
22 import org.alfresco.model.ContentModel;
23 import org.alfresco.repo.policy.Behaviour;
24 import org.alfresco.repo.policy.JavaBehaviour;
25 import org.alfresco.repo.policy.PolicyComponent;
26 import org.alfresco.repo.policy.PolicyScope;
27 import org.alfresco.service.cmr.repository.ChildAssociationRef;
28 import org.alfresco.service.cmr.repository.NodeRef;
29 import org.alfresco.service.cmr.repository.NodeService;
30 import org.alfresco.service.cmr.repository.StoreRef;
31 import org.alfresco.service.cmr.rule.RuleService;
32 import org.alfresco.service.namespace.NamespaceService;
33 import org.alfresco.service.namespace.QName;
34 import org.alfresco.service.namespace.RegexQNamePattern;
35
36 /**
37  * Class containing behaviour for the actions aspect
38  *
39  * @author Roy Wetherall
40  */

41 public class ActionsAspect
42 {
43     private Behaviour onAddAspectBehaviour;
44     
45     private PolicyComponent policyComponent;
46     
47     private RuleService ruleService;
48     
49     private NodeService nodeService;
50     
51     public void setPolicyComponent(PolicyComponent policyComponent)
52     {
53         this.policyComponent = policyComponent;
54     }
55     
56     public void setNodeService(NodeService nodeService)
57     {
58         this.nodeService = nodeService;
59     }
60    
61     public void setRuleService(RuleService ruleService)
62     {
63         this.ruleService = ruleService;
64     }
65     
66     public void init()
67     {
68         this.policyComponent.bindClassBehaviour(
69                 QName.createQName(NamespaceService.ALFRESCO_URI, "onCopyNode"),
70                 ActionModel.ASPECT_ACTIONS,
71                 new JavaBehaviour(this, "onCopyNode"));
72         this.policyComponent.bindClassBehaviour(
73                 QName.createQName(NamespaceService.ALFRESCO_URI, "onCopyComplete"),
74                 ActionModel.ASPECT_ACTIONS,
75                 new JavaBehaviour(this, "onCopyComplete"));
76         
77         this.onAddAspectBehaviour = new JavaBehaviour(this, "onAddAspect");
78         this.policyComponent.bindClassBehaviour(
79                 QName.createQName(NamespaceService.ALFRESCO_URI, "onAddAspect"),
80                 ActionModel.ASPECT_ACTIONS,
81                 onAddAspectBehaviour);
82     }
83     
84
85     
86     /**
87      * Helper to diable the on add aspect policy behaviour. Helpful when importing,
88      * copying and other bulk respstorative operations.
89      *
90      * TODO will eventually be redundant when policies can be enabled/diabled in the
91      * policy componenet
92      */

93     public void disbleOnAddAspect()
94     {
95         this.onAddAspectBehaviour.disable();
96     }
97     
98     /**
99      * Helper to enable the on add aspect policy behaviour. Helpful when importing,
100      * copying and other bulk respstorative operations.
101      *
102      * TODO will eventually be redundant when policies can be enabled/diabled in the
103      * policy componenet
104      */

105     public void enableOnAddAspect()
106     {
107         this.onAddAspectBehaviour.enable();
108     }
109     
110     /**
111      * On add aspect policy behaviour
112      * @param nodeRef
113      * @param aspectTypeQName
114      */

115     public void onAddAspect(NodeRef nodeRef, QName aspectTypeQName)
116     {
117         this.ruleService.disableRules(nodeRef);
118         try
119         {
120             this.nodeService.createNode(
121                     nodeRef,
122                     ActionModel.ASSOC_ACTION_FOLDER,
123                     ActionModel.ASSOC_ACTION_FOLDER,
124                     ContentModel.TYPE_SYSTEM_FOLDER);
125         }
126         finally
127         {
128             this.ruleService.enableRules(nodeRef);
129         }
130     }
131     
132     public void onCopyNode(
133             QName classRef,
134             NodeRef sourceNodeRef,
135             StoreRef destinationStoreRef,
136             boolean copyToNewNode,
137             PolicyScope copyDetails)
138     {
139         copyDetails.addAspect(ActionModel.ASPECT_ACTIONS);
140         
141         List JavaDoc<ChildAssociationRef> assocs = this.nodeService.getChildAssocs(
142                 sourceNodeRef,
143                 RegexQNamePattern.MATCH_ALL,
144                 ActionModel.ASSOC_ACTION_FOLDER);
145         for (ChildAssociationRef assoc : assocs)
146         {
147             copyDetails.addChildAssociation(classRef, assoc, true);
148         }
149         
150         this.onAddAspectBehaviour.disable();
151     }
152     
153     public void onCopyComplete(
154             QName classRef,
155             NodeRef sourceNodeRef,
156             NodeRef destinationRef,
157             boolean copyToNew,
158             Map JavaDoc<NodeRef, NodeRef> copyMap)
159     {
160         this.onAddAspectBehaviour.enable();
161     }
162 }
163
Popular Tags