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