01: /*
02: * Created on 11-May-2005
03: */
04: package com.jofti.cache.adapter;
05:
06: import com.jofti.core.INameSpace;
07:
08: /**
09: * Provides a unified mechanism for dealing with different namspace objects in
10: * the JBossCacheAdapter.
11: *
12: * @author Steve Woodcock
13: *
14: */
15: public class NameSpaceWrapper implements Comparable, INameSpace {
16:
17: protected Object nameSpace = null;
18: protected Class nameSpaceClass = null;
19: int hashCode = 0;
20:
21: public NameSpaceWrapper(Object nameSpace) {
22: this .nameSpace = nameSpace;
23: nameSpaceClass = nameSpace.getClass();
24: this .hashCode = nameSpace.hashCode();
25:
26: }
27:
28: /* (non-Javadoc)
29: * @see java.lang.Comparable#compareTo(java.lang.Object)
30: */
31: public int compareTo(Object o) {
32:
33: if (o != null && o instanceof NameSpaceWrapper) {
34: NameSpaceWrapper temp = (NameSpaceWrapper) o;
35:
36: if (nameSpaceClass.equals(temp.nameSpaceClass)
37: && nameSpace instanceof Comparable) {
38: return ((Comparable) nameSpace)
39: .compareTo((Comparable) temp.nameSpace);
40: } else {
41: return nameSpace.toString().compareTo(
42: temp.nameSpace.toString());
43: }
44: }
45: throw new IllegalArgumentException("variable " + o
46: + " is not a NameSpaceWrapper or is null");
47:
48: }
49:
50: public boolean equals(Object o) {
51:
52: if (o != null
53: && nameSpaceClass
54: .equals(((NameSpaceWrapper) o).nameSpaceClass)) {
55: return nameSpace.equals(((NameSpaceWrapper) o).nameSpace);
56:
57: } else {
58: return false;
59: }
60: }
61:
62: public int hashCode() {
63: return hashCode;
64: }
65:
66: public String toString() {
67: return nameSpace.toString();
68: }
69:
70: /* (non-Javadoc)
71: * @see com.jofti.core.INameSpace#getDelegate()
72: */
73: public Object getDelegate() {
74: return nameSpace;
75: }
76: }
|