View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2013 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.common.events.annotated;
20  
21  import java.lang.annotation.Annotation;
22  import java.lang.reflect.Method;
23  
24  import org.eclipse.jetty.util.StringUtil;
25  import org.eclipse.jetty.websocket.api.InvalidWebSocketException;
26  import org.eclipse.jetty.websocket.common.events.ParamList;
27  
28  @SuppressWarnings("serial")
29  public class InvalidSignatureException extends InvalidWebSocketException
30  {
31      public static InvalidSignatureException build(Method method, Class<? extends Annotation> annoClass, ParamList... paramlists)
32      {
33          // Build big detailed exception to help the developer
34          StringBuilder err = new StringBuilder();
35          err.append("Invalid declaration of ");
36          err.append(method);
37          err.append(StringUtil.__LINE_SEPARATOR);
38  
39          err.append("Acceptable method declarations for @");
40          err.append(annoClass.getSimpleName());
41          err.append(" are:");
42          for (ParamList validParams : paramlists)
43          {
44              for (Class<?>[] params : validParams)
45              {
46                  err.append(StringUtil.__LINE_SEPARATOR);
47                  err.append("public void ").append(method.getName());
48                  err.append('(');
49                  boolean delim = false;
50                  for (Class<?> type : params)
51                  {
52                      if (delim)
53                      {
54                          err.append(',');
55                      }
56                      err.append(' ');
57                      err.append(type.getName());
58                      if (type.isArray())
59                      {
60                          err.append("[]");
61                      }
62                      delim = true;
63                  }
64                  err.append(')');
65              }
66          }
67          return new InvalidSignatureException(err.toString());
68      }
69  
70      public InvalidSignatureException(String message)
71      {
72          super(message);
73      }
74  
75      public InvalidSignatureException(String message, Throwable cause)
76      {
77          super(message,cause);
78      }
79  }