01: package com.completex.objective.components.persistency.mapper.impl;
02:
03: import com.completex.objective.components.persistency.mapper.OdalMappingRuntimeException;
04:
05: /**
06: * @author Gennady Krizhevsky
07: */
08: public class MapperKey {
09:
10: public static final String CLASS_SEP = "#";
11:
12: private String className;
13: private Object token;
14:
15: public MapperKey(String valuePath) {
16: parse(valuePath);
17: }
18:
19: protected void parse(String valuePath) {
20: if (valuePath == null) {
21: return;
22: }
23:
24: int classSepPos = valuePath.indexOf(CLASS_SEP);
25: if (classSepPos < 0) {
26: throw new OdalMappingRuntimeException(
27: "Cannot find class separator " + CLASS_SEP
28: + " in valuePath " + valuePath);
29: }
30:
31: if (classSepPos == 0) {
32: throw new OdalMappingRuntimeException(
33: "Value path starts with class separator "
34: + CLASS_SEP + " in valuePath " + valuePath);
35: }
36:
37: className = valuePath.substring(0, classSepPos);
38: String tokensString = valuePath.substring(classSepPos + 1);
39: if (tokensString != null) {
40: token = new MapperToken(tokensString);
41: }
42: }
43:
44: public boolean equals(Object value) {
45: if (this == value)
46: return true;
47: if (value == null || getClass() != value.getClass())
48: return false;
49:
50: final MapperKey mapperKey = (MapperKey) value;
51:
52: if (className != null ? !className.equals(mapperKey.className)
53: : mapperKey.className != null)
54: return false;
55:
56: if ((token == null && mapperKey.token != null)
57: || (token != null && mapperKey.token == null)) {
58: return false;
59: } else if (token != null) {
60: if (!token.equals(mapperKey.token)
61: && !mapperKey.token.equals(token)) {
62: return false;
63: }
64: }
65:
66: return true;
67: }
68:
69: public int hashCode() {
70: return (className != null ? className.hashCode() : 0);
71: }
72: }
|