Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
WidgetHandleImpl |
|
| 0.0;0 |
1 | /* | |
2 | * Copyright 2004-2008 the Seasar Foundation and the Others. | |
3 | * | |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | |
13 | * either express or implied. See the License for the specific language | |
14 | * governing permissions and limitations under the License. | |
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 | * {@link WidgetHandle} の実装クラスです。<br /> | |
25 | * | |
26 | * @author y-komori | |
27 | */ | |
28 | public class WidgetHandleImpl implements WidgetHandle { | |
29 | private String id; | |
30 | ||
31 | private Object widget; | |
32 | ||
33 | private UIComponent uiComponent; | |
34 | ||
35 | /** | |
36 | * {@link WidgetHandleImpl} を構築します。<br /> | |
37 | * 本クラスのインスタンスを生成するには、{@link ContextFactory#createWidgetHandle(Object)} | |
38 | * メソッドを利用してください。<br /> | |
39 | * | |
40 | * @param widget | |
41 | * ウィジットオブジェクト | |
42 | */ | |
43 | 2060 | public WidgetHandleImpl(final Object widget) { |
44 | 2060 | AssertionUtil.assertNotNull("widget", widget); |
45 | ||
46 | 2060 | this.widget = widget; |
47 | 2060 | } |
48 | ||
49 | /* | |
50 | * @see org.seasar.uruma.context.WidgetHandle#getId() | |
51 | */ | |
52 | public String getId() { | |
53 | 6060 | return this.id; |
54 | } | |
55 | ||
56 | /* | |
57 | * @see org.seasar.uruma.context.WidgetHandle#getWidget() | |
58 | */ | |
59 | public Object getWidget() { | |
60 | 4772 | return this.widget; |
61 | } | |
62 | ||
63 | /* | |
64 | * @see org.seasar.uruma.context.WidgetHandle#getCastWidget() | |
65 | */ | |
66 | @SuppressWarnings("unchecked") | |
67 | public <T> T getCastWidget() { | |
68 | 1160 | return (T) this.getWidgetClass().cast(this.getWidget()); |
69 | } | |
70 | ||
71 | /* | |
72 | * @see org.seasar.uruma.context.WidgetHandle#getWidgetClass() | |
73 | */ | |
74 | public Class<?> getWidgetClass() { | |
75 | 5832 | return widget.getClass(); |
76 | } | |
77 | ||
78 | /* | |
79 | * @see org.seasar.uruma.context.WidgetHandle#getUiComponent() | |
80 | */ | |
81 | public UIComponent getUiComponent() { | |
82 | 68 | return this.uiComponent; |
83 | } | |
84 | ||
85 | /* | |
86 | * @see org.seasar.uruma.context.WidgetHandle#instanceOf(java.lang.Class) | |
87 | */ | |
88 | public boolean instanceOf(final Class<?> clazz) { | |
89 | 168 | if (clazz != null) { |
90 | 168 | return clazz.isAssignableFrom(widget.getClass()); |
91 | } else { | |
92 | 0 | throw new IllegalArgumentException(); |
93 | } | |
94 | } | |
95 | ||
96 | /* | |
97 | * @see org.seasar.uruma.context.WidgetHandle#setId(java.lang.String) | |
98 | */ | |
99 | public void setId(final String id) { | |
100 | 2100 | AssertionUtil.assertNotEmpty("id", id); |
101 | 2100 | this.id = id; |
102 | 2100 | } |
103 | ||
104 | /* | |
105 | * @see org.seasar.uruma.context.WidgetHandle#setUiComponent(org.seasar.uruma.component.UIComponent) | |
106 | */ | |
107 | public void setUiComponent(final UIComponent uiComponent) { | |
108 | 1832 | AssertionUtil.assertNotNull("uiComponent", uiComponent); |
109 | 1832 | this.uiComponent = uiComponent; |
110 | 1832 | } |
111 | ||
112 | /* | |
113 | * @see java.lang.Object#hashCode() | |
114 | */ | |
115 | @Override | |
116 | public int hashCode() { | |
117 | 476 | final int prime = 31; |
118 | 476 | int result = 1; |
119 | 476 | result = prime * result + ((this.id == null) ? 0 : this.id.hashCode()); |
120 | 476 | return result; |
121 | } | |
122 | ||
123 | /* | |
124 | * @see java.lang.Object#equals(java.lang.Object) | |
125 | */ | |
126 | @Override | |
127 | public boolean equals(final Object obj) { | |
128 | 0 | if (this == obj) |
129 | 0 | return true; |
130 | 0 | if (obj == null) |
131 | 0 | return false; |
132 | 0 | if (getClass() != obj.getClass()) |
133 | 0 | return false; |
134 | 0 | final WidgetHandleImpl other = (WidgetHandleImpl) obj; |
135 | 0 | if (this.id == null) { |
136 | 0 | if (other.id != null) |
137 | 0 | return false; |
138 | 0 | } else if (!this.id.equals(other.id)) |
139 | 0 | return false; |
140 | 0 | return true; |
141 | } | |
142 | } |