KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > coci > WorkingCopyAspect


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
18 package org.alfresco.repo.coci;
19
20 import org.alfresco.model.ContentModel;
21 import org.alfresco.repo.policy.JavaBehaviour;
22 import org.alfresco.repo.policy.PolicyComponent;
23 import org.alfresco.repo.policy.PolicyScope;
24 import org.alfresco.service.cmr.lock.LockService;
25 import org.alfresco.service.cmr.repository.NodeRef;
26 import org.alfresco.service.cmr.repository.NodeService;
27 import org.alfresco.service.cmr.repository.StoreRef;
28 import org.alfresco.service.namespace.NamespaceService;
29 import org.alfresco.service.namespace.QName;
30
31 public class WorkingCopyAspect
32 {
33     /**
34      * Policy component
35      */

36     private PolicyComponent policyComponent;
37     
38     /**
39      * The node service
40      */

41     private NodeService nodeService;
42     
43     /**
44      * The lock service
45      */

46     private LockService lockService;
47     
48     /**
49      * Sets the policy component
50      *
51      * @param policyComponent the policy component
52      */

53     public void setPolicyComponent(PolicyComponent policyComponent)
54     {
55         this.policyComponent = policyComponent;
56     }
57     
58     /**
59      * Set the node service
60      *
61      * @param nodeService the node service
62      */

63     public void setNodeService(NodeService nodeService)
64     {
65         this.nodeService = nodeService;
66     }
67     
68     /**
69      * Set the lock service
70      *
71      * @param lockService the lock service
72      */

73     public void setLockService(LockService lockService)
74     {
75         this.lockService = lockService;
76     }
77     
78     /**
79      * Initialise method
80      */

81     public void init()
82     {
83         // Register copy behaviour for the working copy aspect
84
this.policyComponent.bindClassBehaviour(
85                 QName.createQName(NamespaceService.ALFRESCO_URI, "onCopyNode"),
86                 ContentModel.ASPECT_WORKING_COPY,
87                 new JavaBehaviour(this, "onCopy"));
88         
89         // register onBeforeDelete class behaviour for the working copy aspect
90
this.policyComponent.bindClassBehaviour(
91                 QName.createQName(NamespaceService.ALFRESCO_URI, "beforeDeleteNode"),
92                 ContentModel.ASPECT_WORKING_COPY,
93                 new JavaBehaviour(this, "beforeDeleteNode"));
94     }
95     
96     /**
97      * onCopy policy behaviour
98      *
99      * @see org.alfresco.repo.copy.CopyServicePolicies.OnCopyNodePolicy#onCopyNode(QName, NodeRef, StoreRef, boolean, PolicyScope)
100      */

101     public void onCopy(
102             QName sourceClassRef,
103             NodeRef sourceNodeRef,
104             StoreRef destinationStoreRef,
105             boolean copyToNewNode,
106             PolicyScope copyDetails)
107     {
108         if (copyToNewNode == false)
109         {
110             // Make sure that the name of the node is not updated with the working copy name
111
copyDetails.removeProperty(ContentModel.PROP_NAME);
112         }
113         
114         // NOTE: the working copy aspect is not added since it should not be copyied
115
}
116     
117     /**
118      * beforeDeleteNode policy behaviour
119      *
120      * @param nodeRef the node reference about to be deleted
121      */

122     public void beforeDeleteNode(NodeRef nodeRef)
123     {
124         // Prior to deleting a working copy the lock on the origional node should be released
125
// Note: we do not call cancelCheckOut since this will also attempt to delete the node is question
126
if (this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_WORKING_COPY) == true &&
127             this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_COPIEDFROM) == true)
128         {
129             // Get the origional node
130
NodeRef origNodeRef = (NodeRef)this.nodeService.getProperty(nodeRef, ContentModel.PROP_COPY_REFERENCE);
131             if (origNodeRef != null)
132             {
133                // Release the lock on the origional node
134
this.lockService.unlock(origNodeRef);
135             }
136         }
137     }
138
139 }
140
Popular Tags