01: /*
02: * Copyright 2007 Tim Peierls
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.directwebremoting.guice;
17:
18: import java.lang.annotation.Annotation;
19:
20: class ConvertingImpl implements Converting {
21: public ConvertingImpl(String match) {
22: if (match == null) {
23: throw new NullPointerException("@Converting(match==null)");
24: }
25: this .match = match;
26: this .type = Void.class;
27: this .impl = Void.class;
28: }
29:
30: public ConvertingImpl(Class<?> type) {
31: if (type == null) {
32: throw new NullPointerException("@Converting(type==null)");
33: }
34: this .match = "";
35: this .type = type;
36: this .impl = Void.class;
37: }
38:
39: public ConvertingImpl(Class<?> type, Class<?> impl) {
40: if (type == null) {
41: throw new NullPointerException("@Converting(type==null)");
42: }
43: if (impl == null) {
44: throw new NullPointerException("@Converting(impl==null)");
45: }
46: this .match = "";
47: this .type = type;
48: this .impl = impl;
49: }
50:
51: public String match() {
52: return this .match;
53: }
54:
55: public Class<?> type() {
56: return this .type;
57: }
58:
59: public Class<?> impl() {
60: return this .impl;
61: }
62:
63: public Class<? extends Annotation> annotationType() {
64: return Converting.class;
65: }
66:
67: @Override
68: public boolean equals(Object t) {
69: if (!(t instanceof Converting)) {
70: return false;
71: }
72:
73: Converting that = (Converting) t;
74: return this .match.equals(that.match())
75: && this .type.equals(that.type())
76: && this .impl.equals(that.impl());
77: }
78:
79: @Override
80: public int hashCode() {
81: // Annotation spec sez:
82: return (127 * "match".hashCode() ^ match.hashCode())
83: + (127 * "type".hashCode() ^ type.hashCode())
84: + (127 * "impl".hashCode() ^ impl.hashCode());
85: }
86:
87: @Override
88: public String toString() {
89: return "@" + Converting.class.getName() + "(match=" + match
90: + ",type=" + type.getName() + ",impl=" + impl.getName()
91: + ")";
92: }
93:
94: private final String match;
95: private final Class<?> type;
96: private final Class<?> impl;
97: }
|