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