View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
4   //  ------------------------------------------------------------------------
5   //  All rights reserved. This program and the accompanying materials
6   //  are made available under the terms of the Eclipse Public License v1.0
7   //  and Apache License v2.0 which accompanies this distribution.
8   //
9   //      The Eclipse Public License is available at
10  //      http://www.eclipse.org/legal/epl-v10.html
11  //
12  //      The Apache License v2.0 is available at
13  //      http://www.opensource.org/licenses/apache2.0.php
14  //
15  //  You may elect to redistribute this code under either of these licenses.
16  //  ========================================================================
17  //
18  
19  package org.eclipse.jetty.websocket.core.driver;
20  
21  /**
22   * A representation of the methods available to call for a particular class.
23   * <p>
24   * This class used to cache the method lookups via the {@link EventMethodsCache}
25   */
26  public class EventMethods
27  {
28      private Class<?> pojoClass;
29      private boolean isAnnotated = false;
30      public EventMethod onConnect = null;
31      public EventMethod onClose = null;
32      public EventMethod onBinary = null;
33      public EventMethod onBinaryStream = null;
34      public EventMethod onText = null;
35      public EventMethod onTextStream = null;
36      public EventMethod onException = null;
37      public EventMethod onFrame = null;
38  
39      public EventMethods(Class<?> pojoClass, boolean annotated)
40      {
41          this.pojoClass = pojoClass;
42          this.isAnnotated = annotated;
43      }
44  
45      @Override
46      public boolean equals(Object obj)
47      {
48          if (this == obj)
49          {
50              return true;
51          }
52          if (obj == null)
53          {
54              return false;
55          }
56          if (getClass() != obj.getClass())
57          {
58              return false;
59          }
60          EventMethods other = (EventMethods)obj;
61          if (pojoClass == null)
62          {
63              if (other.pojoClass != null)
64              {
65                  return false;
66              }
67          }
68          else if (!pojoClass.getName().equals(other.pojoClass.getName()))
69          {
70              return false;
71          }
72          return true;
73      }
74  
75      public Class<?> getPojoClass()
76      {
77          return pojoClass;
78      }
79  
80      @Override
81      public int hashCode()
82      {
83          final int prime = 31;
84          int result = 1;
85          result = (prime * result) + ((pojoClass == null)?0:pojoClass.getName().hashCode());
86          return result;
87      }
88  
89      public boolean isAnnotated()
90      {
91          return isAnnotated;
92      }
93  
94      @Override
95      public String toString()
96      {
97          StringBuilder builder = new StringBuilder();
98          builder.append("EventMethods [pojoClass=");
99          builder.append(pojoClass);
100         builder.append(", isAnnotated=");
101         builder.append(isAnnotated);
102         builder.append(", onConnect=");
103         builder.append(onConnect);
104         builder.append(", onClose=");
105         builder.append(onClose);
106         builder.append(", onBinary=");
107         builder.append(onBinary);
108         builder.append(", onText=");
109         builder.append(onText);
110         builder.append(", onException=");
111         builder.append(onException);
112         builder.append(", onFrame=");
113         builder.append(onFrame);
114         builder.append("]");
115         return builder.toString();
116     }
117 
118 }