001/* 002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 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 * 016 * Contributors: 017 * Florent Guillaume 018 */ 019package org.nuxeo.ecm.core.api; 020 021import java.io.Serializable; 022import java.util.Calendar; 023import java.util.Objects; 024 025import org.apache.commons.lang3.builder.EqualsBuilder; 026import org.apache.commons.lang3.builder.ToStringBuilder; 027 028/** 029 * Information about a lock set on a document. 030 * <p> 031 * The lock information holds the owner, which is a user id, and the lock creation time. 032 */ 033public class Lock implements Serializable { 034 035 private static final long serialVersionUID = 1L; 036 037 private final String owner; 038 039 private final Calendar created; 040 041 private final boolean failed; 042 043 public Lock(String owner, Calendar created, boolean failed) { 044 this.owner = owner; 045 this.created = created; 046 this.failed = failed; 047 } 048 049 public Lock(String owner, Calendar created) { 050 this(owner, created, false); 051 } 052 053 public Lock(Lock lock, boolean failed) { 054 this(lock.owner, lock.created, failed); 055 } 056 057 /** 058 * The owner of the lock. 059 * 060 * @return the owner, which is a user id 061 */ 062 public String getOwner() { 063 return owner; 064 } 065 066 /** 067 * The creation time of the lock. 068 * 069 * @return the creation time 070 */ 071 public Calendar getCreated() { 072 return created; 073 } 074 075 /** 076 * The failure state, used for removal results. 077 * 078 * @return the failure state 079 */ 080 public boolean getFailed() { 081 return failed; 082 } 083 084 /** 085 * @since 11.1 086 */ 087 @Override 088 public boolean equals(Object obj) { 089 return EqualsBuilder.reflectionEquals(this, obj); 090 } 091 092 /** 093 * @since 11.1 094 */ 095 @Override 096 public int hashCode() { 097 return Objects.hash(owner, created, failed); 098 } 099 100 /** 101 * @since 11.1 102 */ 103 @Override 104 public String toString() { 105 return ToStringBuilder.reflectionToString(this); 106 } 107}