View Javadoc

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