001    //$HeadURL: svn+ssh://mschneider@svn.wald.intevation.org/deegree/base/trunk/resources/eclipse/svn_classfile_header_template.xml $
002    /*----------------------------------------------------------------------------
003     This file is part of deegree, http://deegree.org/
004     Copyright (C) 2001-2009 by:
005       Department of Geography, University of Bonn
006     and
007       lat/lon GmbH
008    
009     This library is free software; you can redistribute it and/or modify it under
010     the terms of the GNU Lesser General Public License as published by the Free
011     Software Foundation; either version 2.1 of the License, or (at your option)
012     any later version.
013     This library is distributed in the hope that it will be useful, but WITHOUT
014     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
015     FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
016     details.
017     You should have received a copy of the GNU Lesser General Public License
018     along with this library; if not, write to the Free Software Foundation, Inc.,
019     59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020    
021     Contact information:
022    
023     lat/lon GmbH
024     Aennchenstr. 19, 53177 Bonn
025     Germany
026     http://lat-lon.de/
027    
028     Department of Geography, University of Bonn
029     Prof. Dr. Klaus Greve
030     Postfach 1147, 53001 Bonn
031     Germany
032     http://www.geographie.uni-bonn.de/deegree/
033    
034     e-mail: info@deegree.org
035    ----------------------------------------------------------------------------*/
036    
037    package org.deegree.io.datastore;
038    
039    import java.io.Serializable;
040    import java.util.Set;
041    
042    import org.deegree.ogcwebservices.wfs.operation.GetFeatureWithLock;
043    import org.deegree.ogcwebservices.wfs.operation.LockFeature;
044    
045    /**
046     * Represents a lock that has been acquired by a {@link LockFeature} or a {@link GetFeatureWithLock}
047     * request.
048     *
049     * @author <a href="mailto:schneider@lat-lon.de">Markus Schneider </a>
050     * @author last edited by: $Author:$
051     *
052     * @version $Revision:$, $Date:$
053     */
054    public class Lock implements Serializable {
055    
056        private static final long serialVersionUID = 9140063407823707226L;
057    
058        private String lockId;
059    
060        private Set<String> lockedFids;
061    
062        private long expiryTime;
063    
064        /**
065         * Creates a new <code>Lock</code> from the given parameters.
066         *
067         * @param lockId
068         *            id of the lock (must be unique)
069         * @param lockedFids
070         *            locked feature ids
071         * @param expiryTime
072         *            point in time when the <code>Lock</code> expires automatically
073         */
074        Lock( String lockId, Set<String> lockedFids, long expiryTime ) {
075            this.lockId = lockId;
076            this.lockedFids = lockedFids;
077            this.expiryTime = expiryTime;
078        }
079    
080        /**
081         * Returns the unique lock identifier.
082         *
083         * @return the unique lock identifier
084         */
085        public String getId() {
086            return this.lockId;
087        }
088    
089        /**
090         * Returns the ids of the features that are locked by this lock.
091         *
092         * @return the ids of the locked features
093         */
094        public Set<String> getLockedFids() {
095            return this.lockedFids;
096        }
097    
098        /**
099         * Returns the point in time when this lock will automatically expire.
100         *
101         * @return the point in time when this lock will automatically expire
102         */
103        long getExpiryTime() {
104            return this.expiryTime;
105        }
106    
107        @Override
108        public String toString() {
109            StringBuffer sb = new StringBuffer();
110            sb.append( "lock " + lockId + ": " );
111            int i = this.lockedFids.size();
112            for ( String fid : this.lockedFids ) {
113                sb.append( fid );
114                if ( --i != 0 ) {
115                    sb.append( ", " );
116                }
117            }
118            return sb.toString();
119        }
120    }