001/*
002 *  Copyright 2012 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.plugins.repository.jcr;
017
018import javax.jcr.Node;
019
020import org.ametys.core.user.UserIdentity;
021import org.ametys.plugins.repository.AmetysObject;
022import org.ametys.plugins.repository.AmetysRepositoryException;
023import org.ametys.plugins.repository.lock.LockableAmetysObject;
024
025/**
026 * {@link DefaultAmetysObject} which is also a {@link LockableAmetysObject}.
027 * @param <F> the actual type of factory.
028 */
029public class DefaultLockableAmetysObject<F extends DefaultLockableAmetysObjectFactory> extends DefaultAmetysObject<F> implements LockableAmetysObject
030{
031    
032    /**
033     * Creates an {@link DefaultLockableAmetysObject}.
034     * @param node the node backing this {@link AmetysObject}
035     * @param parentPath the parentPath in the Ametys hierarchy
036     * @param factory the DefaultAmetysObjectFactory which created the AmetysObject
037     */
038    public DefaultLockableAmetysObject(Node node, String parentPath, F factory)
039    {
040        super(node, parentPath, factory);
041    }
042    
043    @Override
044    public void lock() throws AmetysRepositoryException
045    {
046        _getFactory().getLockComponent().lock(this);
047    }
048    
049    @Override
050    public void unlock() throws AmetysRepositoryException
051    {
052        _getFactory().getLockComponent().unlock(this);
053    }
054    
055    @Override
056    public boolean isLocked() throws AmetysRepositoryException
057    {
058        return _getFactory().getLockComponent().isLocked(this);
059    }
060    
061    @Override
062    public UserIdentity getLockOwner() throws AmetysRepositoryException
063    {
064        return _getFactory().getLockComponent().getLockOwner(this);
065    }
066        
067}