View Javadoc

1   /*
2    * Copyright 2007 Tim Peierls
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, 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  
21  class ConvertingImpl implements Converting 
22  {
23      public ConvertingImpl(String match) 
24      {
25          if (match == null)
26          {
27              throw new NullPointerException("@Converting(match==null)");
28          }
29          this.match = match;
30          this.type = Void.class;
31          this.impl = Void.class;
32      }
33  
34      public ConvertingImpl(Class type) 
35      {
36          if (type == null)
37          {
38              throw new NullPointerException("@Converting(type==null)");
39          }
40          this.match = "";
41          this.type = type;
42          this.impl = Void.class;
43      }
44  
45      public ConvertingImpl(Class type, Class impl) 
46      {
47          if (type == null)
48          {
49              throw new NullPointerException("@Converting(type==null)");
50          }
51          if (impl == null)
52          {
53              throw new NullPointerException("@Converting(impl==null)");
54          }
55          this.match = "";
56          this.type = type;
57          this.impl = impl;
58      }
59  
60      public String match() 
61      {
62          return this.match;
63      }
64      
65      public Class type()
66      {
67          return this.type;
68      }
69      
70      public Class impl()
71      {
72          return this.impl;
73      }
74  
75      public Class<? extends Annotation> annotationType() 
76      {
77          return Converting.class;
78      }
79  
80      public boolean equals(Object t) 
81      {
82          if (!(t instanceof Converting)) 
83          {
84              return false;
85          }
86  
87          Converting that = (Converting) t;
88          return this.match.equals(that.match()) 
89              && this.type.equals(that.type())
90              && this.impl.equals(that.impl());
91      }
92  
93      public int hashCode() 
94      {
95          // Annotation spec sez:
96          return (127 * "match".hashCode() ^ match.hashCode())
97               + (127 * "type".hashCode() ^ type.hashCode())
98               + (127 * "impl".hashCode() ^ impl.hashCode());
99      }
100 
101     public String toString() 
102     {
103         return "@" + Converting.class.getName() + 
104                "(match=" + match + 
105                ",type=" + type.getName() + 
106                ",impl=" + impl.getName() + 
107                ")";
108     }
109 
110     private final String match;
111     private final Class type;
112     private final Class impl;
113 }