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.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  public class BasicServerEndpointConfig implements ServerEndpointConfig
32  {
33      private final List<Class<? extends Decoder>> decoders;
34      private final List<Class<? extends Encoder>> encoders;
35      private final List<Extension> extensions;
36      private final List<String> subprotocols;
37      private final ServerEndpointConfig.Configurator configurator;
38      private final Class<?> endpointClass;
39      private final String path;
40      private Map<String, Object> userProperties;
41  
42      public BasicServerEndpointConfig(Class<?> endpointClass, String path)
43      {
44          this.endpointClass = endpointClass;
45          this.path = path;
46  
47          this.decoders = new ArrayList<>();
48          this.encoders = new ArrayList<>();
49          this.subprotocols = new ArrayList<>();
50          this.extensions = new ArrayList<>();
51          this.userProperties = new HashMap<>();
52          this.configurator = BasicServerEndpointConfigurator.INSTANCE;
53      }
54  
55      public BasicServerEndpointConfig(ServerEndpointConfig copy)
56      {
57          // immutable concepts
58          this.endpointClass = copy.getEndpointClass();
59          this.path = copy.getPath();
60  
61          this.decoders = copy.getDecoders();
62          this.encoders = copy.getEncoders();
63          this.subprotocols = copy.getSubprotocols();
64          this.extensions = copy.getExtensions();
65          if (copy.getConfigurator() != null)
66          {
67              this.configurator = copy.getConfigurator();
68          }
69          else
70          {
71              this.configurator = BasicServerEndpointConfigurator.INSTANCE;
72          }
73  
74          // mutable concepts
75          this.userProperties = new HashMap<>(copy.getUserProperties());
76      }
77  
78      @Override
79      public List<Class<? extends Encoder>> getEncoders()
80      {
81          return encoders;
82      }
83  
84      @Override
85      public List<Class<? extends Decoder>> getDecoders()
86      {
87          return decoders;
88      }
89  
90      @Override
91      public Map<String, Object> getUserProperties()
92      {
93          return userProperties;
94      }
95  
96      @Override
97      public Class<?> getEndpointClass()
98      {
99          return endpointClass;
100     }
101 
102     @Override
103     public String getPath()
104     {
105         return path;
106     }
107 
108     @Override
109     public List<String> getSubprotocols()
110     {
111         return subprotocols;
112     }
113 
114     @Override
115     public List<Extension> getExtensions()
116     {
117         return extensions;
118     }
119 
120     @Override
121     public ServerEndpointConfig.Configurator getConfigurator()
122     {
123         return configurator;
124     }
125 }