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