1 /* 2 * Copyright (c) 2006-2007 Creative Sphere Limited. 3 * All rights reserved. This program and the accompanying materials 4 * are made available under the terms of the Eclipse Public License v1.0 5 * which accompanies this distribution, and is available at 6 * http://www.eclipse.org/legal/epl-v10.html 7 * 8 * Contributors: 9 * 10 * Creative Sphere - initial API and implementation 11 * 12 */ 13 package org.abstracthorizon.danube.webdav.lock; 14 15 import org.abstracthorizon.danube.webdav.util.Timeout; 16 17 /** 18 * This interface describes locking mechanism used for WebDAV locking 19 * 20 * @author Daniel Sendula 21 */ 22 public interface LockingMechanism { 23 24 /** No scope defined */ 25 int SCOPE_NONE = 0; 26 27 /** Shared lock */ 28 int SCOPE_SHARED = 1; 29 30 /** Exclusive lock */ 31 int SCOPE_EXCLUSIVE = 2; 32 33 /** Write lock */ 34 int TYPE_WRITE = 0; 35 36 /** 37 * Creates lock 38 * @param type lcok type 39 * @param scope lock scope 40 * @param owner lock owner 41 * @param timeout lock timeout 42 * @param depth lock depth 43 * @return newly created lock 44 */ 45 Lock createLock(int type, int scope, Object owner, Timeout timeout, int depth); 46 47 /** 48 * Finds a lock or returns <code>null</code> 49 * @param token lock token 50 * @return a lock or <code>null</code> 51 */ 52 Lock findLock(String token); 53 54 /** 55 * Locks a resource 56 * @param lock lock 57 * @param resource resource 58 * @return <code>true</code> if locking succeded 59 */ 60 boolean lockResource(Lock lock, Object resource); 61 62 /** 63 * Unlocks all resource defined by this lock 64 * @param lock lock 65 */ 66 void unlockResources(Lock lock); 67 68 /** 69 * Removes a lock form the resource 70 * @param resource resource 71 */ 72 void removeLocks(Object resource); 73 74 /** 75 * Returns all locks on the resource or <code>null</code> 76 * @param resource resource 77 * @return all locks on the resource or <code>null</code> 78 */ 79 Lock[] getLocks(Object resource); 80 81 /** 82 * Returns all resources locked by the given lock 83 * @param lock lock 84 * @return all resources locked by the given lock 85 */ 86 Object[] getResources(Lock lock); 87 88 /** 89 * Checks if the resource is locked 90 * @param resource resource 91 * @return <code>true</code> if the resource is locked 92 */ 93 boolean isLocked(Object resource); 94 95 /** 96 * Checks if resource is accessible if token is supplied 97 * @param resource resource 98 * @param token token, may be <code>null</code> 99 * @return <code>true</code> if not locked or locked by the lock with givne token 100 */ 101 boolean isAccessAllowed(Object resource, String token); 102 103 /** 104 * Returns an array of supported lock scopes on a resource 105 * @param resource resource 106 * @return an array of supported lock scopes 107 */ 108 int[] getSupportedLockScopes(Object resource); 109 110 }