001/*
002 * Copyright 2002-2016 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;
021
022import javax.websocket.Extension;
023
024import org.springframework.web.socket.WebSocketExtension;
025
026/**
027 * Adapt an instance of {@link org.springframework.web.socket.WebSocketExtension} to
028 * the {@link javax.websocket.Extension} interface.
029 *
030 * @author Rossen Stoyanchev
031 * @since 4.0
032 */
033public class WebSocketToStandardExtensionAdapter implements Extension {
034
035        private final String name;
036
037        private final List<Parameter> parameters = new ArrayList<>();
038
039
040        public WebSocketToStandardExtensionAdapter(final WebSocketExtension extension) {
041                this.name = extension.getName();
042                for (final String paramName : extension.getParameters().keySet()) {
043                        this.parameters.add(new Parameter() {
044                                @Override
045                                public String getName() {
046                                        return paramName;
047                                }
048                                @Override
049                                public String getValue() {
050                                        return extension.getParameters().get(paramName);
051                                }
052                        });
053                }
054        }
055
056        @Override
057        public String getName() {
058                return this.name;
059        }
060
061        @Override
062        public List<Parameter> getParameters() {
063                return this.parameters;
064        }
065
066}