001/*
002 * Copyright 2002-2013 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.web.socket.adapter.standard;
018
019import java.util.ArrayList;
020import java.util.List;
021import javax.websocket.Extension;
022
023import org.springframework.web.socket.WebSocketExtension;
024
025/**
026 * Adapt an instance of {@link org.springframework.web.socket.WebSocketExtension} to
027 * the {@link javax.websocket.Extension} interface.
028 *
029 * @author Rossen Stoyanchev
030 * @since 4.0
031 */
032public class WebSocketToStandardExtensionAdapter implements Extension {
033
034        private final String name;
035
036        private final List<Parameter> parameters = new ArrayList<Parameter>();
037
038
039        public WebSocketToStandardExtensionAdapter(final WebSocketExtension extension) {
040                this.name = extension.getName();
041                for (final String paramName : extension.getParameters().keySet()) {
042                        this.parameters.add(new Parameter() {
043                                @Override
044                                public String getName() {
045                                        return paramName;
046                                }
047                                @Override
048                                public String getValue() {
049                                        return extension.getParameters().get(paramName);
050                                }
051                        });
052                }
053        }
054
055        @Override
056        public String getName() {
057                return this.name;
058        }
059
060        @Override
061        public List<Parameter> getParameters() {
062                return this.parameters;
063        }
064
065}