View Javadoc
1   /*
2    * Copyright 2002-2013 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.web.socket.adapter.standard;
18  
19  import java.util.ArrayList;
20  import java.util.List;
21  import javax.websocket.Extension;
22  
23  import org.springframework.web.socket.WebSocketExtension;
24  
25  /**
26   * Adapt an instance of {@link org.springframework.web.socket.WebSocketExtension} to
27   * the {@link javax.websocket.Extension} interface.
28   *
29   * @author Rossen Stoyanchev
30   * @since 4.0
31   */
32  public class WebSocketToStandardExtensionAdapter implements Extension {
33  
34  	private final String name;
35  
36  	private final List<Parameter> parameters = new ArrayList<Parameter>();
37  
38  
39  	public WebSocketToStandardExtensionAdapter(final WebSocketExtension extension) {
40  		this.name = extension.getName();
41  		for (final String paramName : extension.getParameters().keySet()) {
42  			this.parameters.add(new Parameter() {
43  				@Override
44  				public String getName() {
45  					return paramName;
46  				}
47  				@Override
48  				public String getValue() {
49  					return extension.getParameters().get(paramName);
50  				}
51  			});
52  		}
53  	}
54  
55  	@Override
56  	public String getName() {
57  		return this.name;
58  	}
59  
60  	@Override
61  	public List<Parameter> getParameters() {
62  		return this.parameters;
63  	}
64  
65  }