View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2013 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 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          this.endpointClass = copy.getEndpointClass();
58          this.path = copy.getPath();
59  
60          this.decoders = new ArrayList<>(copy.getDecoders());
61          this.encoders = new ArrayList<>(copy.getEncoders());
62          this.subprotocols = new ArrayList<>(copy.getSubprotocols());
63          this.extensions = new ArrayList<>(copy.getExtensions());
64          this.userProperties = new HashMap<>(copy.getUserProperties());
65          if (copy.getConfigurator() != null)
66          {
67              this.configurator = copy.getConfigurator();
68          }
69          else
70          {
71              this.configurator = BasicServerEndpointConfigurator.INSTANCE;
72          }
73      }
74  
75      @Override
76      public List<Class<? extends Encoder>> getEncoders()
77      {
78          return encoders;
79      }
80  
81      @Override
82      public List<Class<? extends Decoder>> getDecoders()
83      {
84          return decoders;
85      }
86  
87      @Override
88      public Map<String, Object> getUserProperties()
89      {
90          return userProperties;
91      }
92  
93      @Override
94      public Class<?> getEndpointClass()
95      {
96          return endpointClass;
97      }
98  
99      @Override
100     public String getPath()
101     {
102         return path;
103     }
104 
105     @Override
106     public List<String> getSubprotocols()
107     {
108         return subprotocols;
109     }
110 
111     @Override
112     public List<Extension> getExtensions()
113     {
114         return extensions;
115     }
116 
117     @Override
118     public Configurator getConfigurator()
119     {
120         return configurator;
121     }
122 }