1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.uruma.context.impl;
17
18 import org.seasar.uruma.component.UIComponent;
19 import org.seasar.uruma.context.ContextFactory;
20 import org.seasar.uruma.context.WidgetHandle;
21 import org.seasar.uruma.util.AssertionUtil;
22
23
24
25
26
27
28 public class WidgetHandleImpl implements WidgetHandle {
29 private String id;
30
31 private Object widget;
32
33 private UIComponent uiComponent;
34
35
36
37
38
39
40
41
42
43 public WidgetHandleImpl(final Object widget) {
44 AssertionUtil.assertNotNull("widget", widget);
45
46 this.widget = widget;
47 }
48
49
50
51
52 public String getId() {
53 return this.id;
54 }
55
56
57
58
59 public Object getWidget() {
60 return this.widget;
61 }
62
63
64
65
66 @SuppressWarnings("unchecked")
67 public <T> T getCastWidget() {
68 return (T) this.getWidgetClass().cast(this.getWidget());
69 }
70
71
72
73
74 public Class<?> getWidgetClass() {
75 return widget.getClass();
76 }
77
78
79
80
81 public UIComponent getUiComponent() {
82 return this.uiComponent;
83 }
84
85
86
87
88 public boolean instanceOf(final Class<?> clazz) {
89 if (clazz != null) {
90 return clazz.isAssignableFrom(widget.getClass());
91 } else {
92 throw new IllegalArgumentException();
93 }
94 }
95
96
97
98
99 public void setId(final String id) {
100 AssertionUtil.assertNotEmpty("id", id);
101 this.id = id;
102 }
103
104
105
106
107 public void setUiComponent(final UIComponent uiComponent) {
108 AssertionUtil.assertNotNull("uiComponent", uiComponent);
109 this.uiComponent = uiComponent;
110 }
111
112
113
114
115 @Override
116 public int hashCode() {
117 final int prime = 31;
118 int result = 1;
119 result = prime * result + ((this.id == null) ? 0 : this.id.hashCode());
120 return result;
121 }
122
123
124
125
126 @Override
127 public boolean equals(final Object obj) {
128 if (this == obj)
129 return true;
130 if (obj == null)
131 return false;
132 if (getClass() != obj.getClass())
133 return false;
134 final WidgetHandleImpl other = (WidgetHandleImpl) obj;
135 if (this.id == null) {
136 if (other.id != null)
137 return false;
138 } else if (!this.id.equals(other.id))
139 return false;
140 return true;
141 }
142 }