1 /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 package org.springframework.security.acls.objectidentity;
16
17 import java.io.Serializable;
18
19
20 /**
21 * Represents the identity of an individual domain object instance.
22 *
23 * <p>
24 * As implementations of <tt>ObjectIdentity</tt> are used as the key to represent
25 * domain objects in the ACL subsystem, it is essential that implementations provide
26 * methods so that object-equality rather than reference-equality can be relied upon
27 * reliably. In other words, the ACL subsystem can consider two
28 * <tt>ObjectIdentity</tt>s equal if <tt>identity1.equals(identity2)</tt>, rather than
29 * reference-equality of <tt>identity1==identity2</tt>.
30 * </p>
31 *
32 * @author Ben Alex
33 * @version $Id: ObjectIdentity.java 2855 2008-04-04 00:49:34Z benalex $
34 */
35 public interface ObjectIdentity extends Serializable {
36 //~ Methods ========================================================================================================
37
38 /**
39 * @param obj to be compared
40 *
41 * @return <tt>true</tt> if the objects are equal, <tt>false</tt> otherwise
42 * @see Object#equals(Object)
43 */
44 boolean equals(Object obj);
45
46 /**
47 * Obtains the actual identifier. This identifier must not be reused to represent other domain objects with
48 * the same <tt>javaType</tt>.
49 *
50 * <p>Because ACLs are largely immutable, it is strongly recommended to use
51 * a synthetic identifier (such as a database sequence number for the primary key). Do not use an identifier with
52 * business meaning, as that business meaning may change in the future such change will cascade to the ACL
53 * subsystem data.</p>
54 *
55 * @return the identifier (unique within this <tt>javaType</tt>; never <tt>null</tt>)
56 */
57 Serializable getIdentifier();
58
59 /**
60 * Obtains the Java type represented by the domain object. The Java type can be an interface or a class, but is
61 * most often the domain object implementation class.
62 *
63 * @return the Java type of the domain object (never <tt>null</tt>)
64 */
65 Class getJavaType();
66
67 /**
68 * @return a hash code representation of the <tt>ObjectIdentity</tt>
69 * @see Object#hashCode()
70 */
71 int hashCode();
72 }