KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > jcr > item > LockImpl


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.jcr.item;
18
19 import javax.jcr.Node;
20 import javax.jcr.RepositoryException;
21 import javax.jcr.lock.Lock;
22 import javax.jcr.lock.LockException;
23
24 import org.alfresco.jcr.util.JCRProxyFactory;
25 import org.alfresco.model.ContentModel;
26 import org.alfresco.service.cmr.lock.LockService;
27 import org.alfresco.service.cmr.lock.LockStatus;
28 import org.alfresco.service.cmr.repository.NodeService;
29
30 /**
31  * Alfresco implementation of a JCR Lock
32  *
33  * @author David Caruana
34  */

35 public class LockImpl implements Lock
36 {
37     
38     private NodeImpl node;
39     private Lock proxy = null;
40
41     
42     /**
43      * Constructor
44      *
45      * @param node node holding lock
46      */

47     public LockImpl(NodeImpl node)
48     {
49         this.node = node;
50     }
51
52     /**
53      * Create proxied JCR Lock
54      *
55      * @return lock
56      */

57     public Lock getProxy()
58     {
59         if (proxy == null)
60         {
61             proxy = (Lock)JCRProxyFactory.create(this, Lock.class, node.session);
62         }
63         return proxy;
64     }
65
66     /*
67      * (non-Javadoc)
68      * @see javax.jcr.lock.Lock#getLockOwner()
69      */

70     public String JavaDoc getLockOwner()
71     {
72         String JavaDoc lockOwner = null;
73         NodeService nodeService = node.session.getRepositoryImpl().getServiceRegistry().getNodeService();
74         if (nodeService.hasAspect(node.getNodeRef(), ContentModel.ASPECT_LOCKABLE))
75         {
76             lockOwner = (String JavaDoc)nodeService.getProperty(node.getNodeRef(), ContentModel.PROP_LOCK_OWNER);
77         }
78         return lockOwner;
79     }
80
81     /*
82      * (non-Javadoc)
83      * @see javax.jcr.lock.Lock#isDeep()
84      */

85     public boolean isDeep()
86     {
87         return false;
88     }
89
90     /*
91      * (non-Javadoc)
92      * @see javax.jcr.lock.Lock#getNode()
93      */

94     public Node getNode()
95     {
96         return node.getProxy();
97     }
98
99     /*
100      * (non-Javadoc)
101      * @see javax.jcr.lock.Lock#getLockToken()
102      */

103     public String JavaDoc getLockToken()
104     {
105         LockService lockService = node.session.getRepositoryImpl().getServiceRegistry().getLockService();
106         LockStatus lockStatus = lockService.getLockStatus(node.getNodeRef());
107         return lockStatus.equals(LockStatus.LOCK_OWNER) ? node.getNodeRef().toString() : null;
108     }
109
110     /*
111      * (non-Javadoc)
112      * @see javax.jcr.lock.Lock#isLive()
113      */

114     public boolean isLive() throws RepositoryException
115     {
116         return getLockToken() == null ? false : true;
117     }
118
119     /*
120      * (non-Javadoc)
121      * @see javax.jcr.lock.Lock#isSessionScoped()
122      */

123     public boolean isSessionScoped()
124     {
125         return false;
126     }
127
128     /*
129      * (non-Javadoc)
130      * @see javax.jcr.lock.Lock#refresh()
131      */

132     public void refresh() throws LockException, RepositoryException
133     {
134         // note: for now, this is a noop
135
}
136
137 }
138
Popular Tags