View Javadoc

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.server;
20  
21  import java.util.LinkedList;
22  
23  import javax.websocket.DeploymentException;
24  import javax.websocket.server.ServerEndpoint;
25  import javax.websocket.server.ServerEndpointConfig;
26  
27  import org.eclipse.jetty.websocket.api.InvalidWebSocketException;
28  import org.eclipse.jetty.websocket.jsr356.annotations.AnnotatedEndpointMetadata;
29  import org.eclipse.jetty.websocket.jsr356.annotations.IJsrParamId;
30  
31  public class AnnotatedServerEndpointMetadata extends AnnotatedEndpointMetadata<ServerEndpoint,ServerEndpointConfig> implements ServerEndpointMetadata
32  {
33      private final ServerEndpoint endpoint;
34      private final AnnotatedServerEndpointConfig config;
35  
36      protected AnnotatedServerEndpointMetadata(Class<?> websocket, ServerEndpointConfig baseConfig) throws DeploymentException
37      {
38          super(websocket);
39  
40          ServerEndpoint anno = websocket.getAnnotation(ServerEndpoint.class);
41          if (anno == null)
42          {
43              throw new InvalidWebSocketException("Unsupported WebSocket object, missing @" + ServerEndpoint.class + " annotation");
44          }
45  
46          this.endpoint = anno;
47          this.config = new AnnotatedServerEndpointConfig(websocket,anno,baseConfig);
48          
49          getDecoders().addAll(anno.decoders());
50          getEncoders().addAll(anno.encoders());
51      }
52  
53      @Override
54      public void customizeParamsOnClose(LinkedList<IJsrParamId> params)
55      {
56          super.customizeParamsOnClose(params);
57          params.addFirst(JsrPathParamId.INSTANCE);
58      }
59  
60      @Override
61      public void customizeParamsOnError(LinkedList<IJsrParamId> params)
62      {
63          super.customizeParamsOnError(params);
64          params.addFirst(JsrPathParamId.INSTANCE);
65      }
66      
67      @Override
68      public void customizeParamsOnOpen(LinkedList<IJsrParamId> params)
69      {
70          super.customizeParamsOnOpen(params);
71          params.addFirst(JsrPathParamId.INSTANCE);
72      }
73      
74      @Override
75      public void customizeParamsOnMessage(LinkedList<IJsrParamId> params)
76      {
77          super.customizeParamsOnMessage(params);
78          params.addFirst(JsrPathParamId.INSTANCE);
79      }
80  
81      @Override
82      public ServerEndpoint getAnnotation()
83      {
84          return endpoint;
85      }
86  
87      public AnnotatedServerEndpointConfig getConfig()
88      {
89          return config;
90      }
91  
92      public String getPath()
93      {
94          return config.getPath();
95      }
96  
97      @Override
98      public String toString()
99      {
100         StringBuilder builder = new StringBuilder();
101         builder.append("AnnotatedServerEndpointMetadata[endpoint=");
102         builder.append(endpoint);
103         builder.append(",config=");
104         builder.append(config);
105         builder.append("]");
106         return builder.toString();
107     }
108 }