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.client;
20  
21  import javax.websocket.ClientEndpoint;
22  import javax.websocket.ClientEndpointConfig;
23  
24  import org.eclipse.jetty.websocket.api.InvalidWebSocketException;
25  import org.eclipse.jetty.websocket.jsr356.ClientContainer;
26  import org.eclipse.jetty.websocket.jsr356.annotations.AnnotatedEndpointMetadata;
27  
28  public class AnnotatedClientEndpointMetadata extends AnnotatedEndpointMetadata<ClientEndpoint, ClientEndpointConfig>
29  {
30      private final ClientEndpoint endpoint;
31      private final AnnotatedClientEndpointConfig config;
32  
33      public AnnotatedClientEndpointMetadata(ClientContainer container, Class<?> websocket)
34      {
35          super(websocket);
36  
37          ClientEndpoint anno = websocket.getAnnotation(ClientEndpoint.class);
38          if (anno == null)
39          {
40              throw new InvalidWebSocketException(String.format("Unsupported WebSocket object [%s], missing @%s annotation",websocket.getName(),
41                      ClientEndpoint.class.getName()));
42          }
43  
44          this.endpoint = anno;
45          this.config = new AnnotatedClientEndpointConfig(anno);
46  
47          getDecoders().addAll(anno.decoders());
48          getEncoders().addAll(anno.encoders());
49      }
50  
51      @Override
52      public ClientEndpoint getAnnotation()
53      {
54          return endpoint;
55      }
56  
57      @Override
58      public ClientEndpointConfig getConfig()
59      {
60          return config;
61      }
62  }