1:
31: package ;
32:
33: import ;
34: import ;
35: import ;
36: import ;
37: import ;
38:
39:
50: public final class ResourceKey implements Serializable
51: {
52: private static final Map EMPTY_MAP =
53: Collections.unmodifiableMap(new HashMap());
54:
55: private Map factoryParameters;
56: private Integer hashCode;
57: private Object schema;
58: private Object identifier;
59: private ResourceKey parent;
60:
61: public ResourceKey(final Object schema,
62: final Object identifier,
63: final Map factoryParameters)
64: {
65: if (schema == null)
66: {
67: throw new NullPointerException();
68: }
69: if (identifier == null)
70: {
71: throw new NullPointerException();
72: }
73:
74: this.schema = schema;
75: this.identifier = identifier;
76: if (factoryParameters != null)
77: {
78: this.factoryParameters =
79: Collections.unmodifiableMap(new HashMap(factoryParameters));
80: }
81: else
82: {
83: this.factoryParameters = EMPTY_MAP;
84: }
85: }
86:
87: public ResourceKey(final ResourceKey parent,
88: final Object schema,
89: final Object identifier,
90: final Map factoryParameters)
91: {
92: this(schema, identifier, factoryParameters);
93: this.parent = parent;
94: }
95:
96: public ResourceKey getParent()
97: {
98: return parent;
99: }
100:
101: public Map getFactoryParameters ()
102: {
103: return factoryParameters;
104: }
105:
106: public boolean equals(final Object o)
107: {
108: if (this == o)
109: {
110: return true;
111: }
112: if (o == null || getClass() != o.getClass())
113: {
114: return false;
115: }
116:
117: final ResourceKey that = (ResourceKey) o;
118:
119: if (!schema.equals(that.schema))
120: {
121: return false;
122: }
123: if (!factoryParameters.equals(that.factoryParameters))
124: {
125: return false;
126: }
127: if (!identifier.equals(that.identifier))
128: {
129: if (identifier instanceof byte[] && that.identifier instanceof byte[])
130: {
131: final byte[] me = (byte[]) identifier;
132: final byte[] he = (byte[]) that.identifier;
133: Arrays.equals(me, he);
134: }
135: return false;
136: }
137:
138: return true;
139: }
140:
141: public int hashCode()
142: {
143: if (hashCode == null)
144: {
145: int result;
146: result = factoryParameters.hashCode();
147: result = 29 * result + schema.hashCode();
148: result = 29 * result + identifier.hashCode();
149: hashCode = new Integer(result);
150: }
151: return hashCode.intValue();
152: }
153:
154: public Object getIdentifier()
155: {
156: return identifier;
157: }
158:
159:
168: public Object getSchema ()
169: {
170: return schema;
171: }
172:
173:
174: public String toString()
175: {
176: return "ResourceKey{" +
177: "schema=" + schema +
178: ", identifier=" + identifier +
179: ", factoryParameters=" + factoryParameters +
180: ", parent=" + parent +
181: '}';
182: }
183: }
184: