1 //
2 // ========================================================================
3 // Copyright (c) 1995-2015 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 javax.websocket.OnMessage;
22
23 import org.eclipse.jetty.websocket.common.events.annotated.InvalidSignatureException;
24 import org.eclipse.jetty.websocket.jsr356.annotations.Param.Role;
25 import org.eclipse.jetty.websocket.jsr356.metadata.DecoderMetadata;
26
27 /**
28 * Param handling for Text or Binary @{@link OnMessage} parameters declared as {@link javax.websocket.Decoder}s
29 */
30 public class JsrParamIdDecoder extends JsrParamIdOnMessage implements IJsrParamId
31 {
32 private final DecoderMetadata metadata;
33
34 public JsrParamIdDecoder(DecoderMetadata metadata)
35 {
36 this.metadata = metadata;
37 }
38
39 @Override
40 public boolean process(Param param, JsrCallable callable) throws InvalidSignatureException
41 {
42 if (param.type.isAssignableFrom(metadata.getObjectType()))
43 {
44 assertPartialMessageSupportDisabled(param,callable);
45
46 switch (metadata.getMessageType())
47 {
48 case TEXT:
49 if (metadata.isStreamed())
50 {
51 param.bind(Role.MESSAGE_TEXT_STREAM);
52 }
53 else
54 {
55 param.bind(Role.MESSAGE_TEXT);
56 }
57 break;
58 case BINARY:
59 if (metadata.isStreamed())
60 {
61 param.bind(Role.MESSAGE_BINARY_STREAM);
62 }
63 else
64 {
65 param.bind(Role.MESSAGE_BINARY);
66 }
67 break;
68 case PONG:
69 param.bind(Role.MESSAGE_PONG);
70 break;
71 }
72 callable.setDecoderClass(metadata.getCoderClass());
73 return true;
74 }
75 return false;
76 }
77 }