View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2014 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.jsr356.annotations;
20  
21  import java.lang.reflect.Method;
22  
23  import javax.websocket.Decoder;
24  
25  import org.eclipse.jetty.websocket.jsr356.JsrSession;
26  
27  /**
28   * Callable for {@link OnError} annotated methods
29   */
30  public class OnErrorCallable extends JsrCallable
31  {
32      private int idxThrowable = -1;
33  
34      public OnErrorCallable(Class<?> pojo, Method method)
35      {
36          super(pojo,method);
37      }
38  
39      public OnErrorCallable(OnErrorCallable copy)
40      {
41          super(copy);
42          this.idxThrowable = copy.idxThrowable;
43      }
44  
45      public void call(Object endpoint, Throwable cause)
46      {
47          if (idxThrowable == (-1))
48          {
49              idxThrowable = findIndexForRole(Param.Role.ERROR_CAUSE);
50              assertRoleRequired(idxThrowable,"Throwable");
51          }
52  
53          if (idxThrowable >= 0)
54          {
55              super.args[idxThrowable] = cause;
56          }
57          super.call(endpoint,super.args);
58      }
59  
60      @Override
61      public void init(JsrSession session)
62      {
63          idxThrowable = findIndexForRole(Param.Role.ERROR_CAUSE);
64          assertRoleRequired(idxThrowable,"Throwable");
65          super.init(session);
66      }
67  
68      @Override
69      public void setDecoderClass(Class<? extends Decoder> decoderClass)
70      {
71          /* ignore, not relevant for onClose */
72      }
73  
74  }