1 /*
2 * ModeShape (http://www.modeshape.org)
3 * See the COPYRIGHT.txt file distributed with this work for information
4 * regarding copyright ownership. Some portions may be licensed
5 * to Red Hat, Inc. under one or more contributor license agreements.
6 * See the AUTHORS.txt file in the distribution for a full listing of
7 * individual contributors.
8 *
9 * ModeShape is free software. Unless otherwise indicated, all code in ModeShape
10 * is licensed to you under the terms of the GNU Lesser General Public License as
11 * published by the Free Software Foundation; either version 2.1 of
12 * the License, or (at your option) any later version.
13 *
14 * ModeShape is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this software; if not, write to the Free
21 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
23 */
24 package org.modeshape.jcr;
25
26 import net.jcip.annotations.Immutable;
27 import org.modeshape.common.util.CheckArg;
28 import org.modeshape.common.util.HashCode;
29 import org.modeshape.graph.property.Path;
30 import org.modeshape.graph.property.basic.BasicPath;
31
32 /**
33 * A correspondence identifier is defined to be the pair of the UUID of the nearest referenceable ancestor and the relative path
34 * from that referenceable ancestor to the node of interest. If any node is a referenceable node, then the correspondence
35 * identifier is just the UUID of the node. Per Section 4.10.2 of JSR-170, version 1.0.1.
36 * <p>
37 * Note that per Section 6.2.8, two non-referenceable nodes are the same if they have the same correspondence identifier.
38 * </p>
39 */
40 @Immutable
41 class CorrespondenceId {
42
43 private static final Path NO_PATH = BasicPath.SELF_PATH;
44
45 private final String referenceableId;
46 private final Path relativePath;
47 private final int hc;
48
49 public CorrespondenceId( String referenceableId ) {
50 this(referenceableId, NO_PATH);
51 }
52
53 public CorrespondenceId( String referenceableId,
54 Path relativePath ) {
55 CheckArg.isNotNull(referenceableId, "referenceableId");
56 CheckArg.isNotNull(relativePath, "relativePath");
57 assert !relativePath.isAbsolute();
58 this.referenceableId = referenceableId;
59 this.relativePath = relativePath;
60 this.hc = HashCode.compute(this.referenceableId, this.relativePath);
61 }
62
63 /**
64 * @return referenceableId
65 */
66 public String getReferenceableId() {
67 return referenceableId;
68 }
69
70 /**
71 * @return relativePath
72 */
73 public Path getRelativePath() {
74 return relativePath;
75 }
76
77 /**
78 * {@inheritDoc}
79 *
80 * @see java.lang.Object#hashCode()
81 */
82 @Override
83 public int hashCode() {
84 return hc;
85 }
86
87 /**
88 * {@inheritDoc}
89 *
90 * @see java.lang.Object#equals(java.lang.Object)
91 */
92 @Override
93 public boolean equals( Object obj ) {
94 if (obj == this) return true;
95 if (obj instanceof CorrespondenceId) {
96 CorrespondenceId that = (CorrespondenceId)obj;
97 return this.referenceableId.equals(that.referenceableId) && this.relativePath.equals(that.relativePath);
98 }
99 return false;
100 }
101
102 }