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.io.InputStream;
22  import java.nio.ByteBuffer;
23  
24  import javax.websocket.OnMessage;
25  
26  import org.eclipse.jetty.websocket.common.events.annotated.InvalidSignatureException;
27  import org.eclipse.jetty.websocket.jsr356.annotations.Param.Role;
28  
29  /**
30   * Param handling for static Binary @{@link javax.websocket.OnMessage} parameters.
31   */
32  public class JsrParamIdBinary extends JsrParamIdOnMessage implements IJsrParamId
33  {
34      public static final IJsrParamId INSTANCE = new JsrParamIdBinary();
35  
36      @Override
37      public boolean process(Param param, JsrCallable callable) throws InvalidSignatureException
38      {
39          if (super.process(param,callable))
40          {
41              // Found common roles
42              return true;
43          }
44  
45          if (param.type.isAssignableFrom(ByteBuffer.class))
46          {
47              param.bind(Role.MESSAGE_BINARY);
48              callable.setDecodingType(ByteBuffer.class);
49              return true;
50          }
51  
52          if (param.type.isAssignableFrom(byte[].class))
53          {
54              param.bind(Role.MESSAGE_BINARY);
55              callable.setDecodingType(byte[].class);
56              return true;
57          }
58  
59          // Streaming
60          if (param.type.isAssignableFrom(InputStream.class))
61          {
62              assertPartialMessageSupportDisabled(param,callable);
63              param.bind(Role.MESSAGE_BINARY_STREAM);
64              callable.setDecodingType(InputStream.class);
65              return true;
66          }
67  
68          return false;
69      }
70  }