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.server;
20  
21  import java.util.ArrayList;
22  import java.util.HashMap;
23  import java.util.List;
24  import java.util.Map;
25  
26  import javax.websocket.Decoder;
27  import javax.websocket.Encoder;
28  import javax.websocket.Extension;
29  import javax.websocket.server.ServerEndpointConfig;
30  
31  import org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope;
32  
33  public class BasicServerEndpointConfig implements ServerEndpointConfig
34  {
35      private final List<Class<? extends Decoder>> decoders;
36      private final List<Class<? extends Encoder>> encoders;
37      private final List<Extension> extensions;
38      private final List<String> subprotocols;
39      private final ServerEndpointConfig.Configurator configurator;
40      private final Class<?> endpointClass;
41      private final String path;
42      private Map<String, Object> userProperties;
43  
44      public BasicServerEndpointConfig(WebSocketContainerScope containerScope, Class<?> endpointClass, String path)
45      {
46          this.endpointClass = endpointClass;
47          this.path = path;
48  
49          this.decoders = new ArrayList<>();
50          this.encoders = new ArrayList<>();
51          this.subprotocols = new ArrayList<>();
52          this.extensions = new ArrayList<>();
53          this.userProperties = new HashMap<>();
54          this.configurator = new ContainerDefaultConfigurator();
55      }
56  
57      public BasicServerEndpointConfig(WebSocketContainerScope containerScope, ServerEndpointConfig copy)
58      {
59          // immutable concepts
60          this.endpointClass = copy.getEndpointClass();
61          this.path = copy.getPath();
62  
63          this.decoders = copy.getDecoders();
64          this.encoders = copy.getEncoders();
65          this.subprotocols = copy.getSubprotocols();
66          this.extensions = copy.getExtensions();
67  
68          ServerEndpointConfig.Configurator cfgr;
69  
70          if (copy.getConfigurator() != null)
71          {
72              cfgr = copy.getConfigurator();
73          }
74          else
75          {
76              cfgr = new ContainerDefaultConfigurator();
77          }
78  
79          // Make sure all Configurators obtained are decorated
80          this.configurator = containerScope.getObjectFactory().decorate(cfgr);
81  
82          // mutable concepts
83          this.userProperties = new HashMap<>(copy.getUserProperties());
84      }
85  
86      @Override
87      public List<Class<? extends Encoder>> getEncoders()
88      {
89          return encoders;
90      }
91  
92      @Override
93      public List<Class<? extends Decoder>> getDecoders()
94      {
95          return decoders;
96      }
97  
98      @Override
99      public Map<String, Object> getUserProperties()
100     {
101         return userProperties;
102     }
103 
104     @Override
105     public Class<?> getEndpointClass()
106     {
107         return endpointClass;
108     }
109 
110     @Override
111     public String getPath()
112     {
113         return path;
114     }
115 
116     @Override
117     public List<String> getSubprotocols()
118     {
119         return subprotocols;
120     }
121 
122     @Override
123     public List<Extension> getExtensions()
124     {
125         return extensions;
126     }
127 
128     @Override
129     public ServerEndpointConfig.Configurator getConfigurator()
130     {
131         return configurator;
132     }
133 }