001/*
002 * Copyright 2002-2019 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.messaging.simp;
018
019import org.springframework.lang.Nullable;
020import org.springframework.messaging.Message;
021import org.springframework.messaging.handler.CompositeMessageCondition;
022import org.springframework.messaging.handler.DestinationPatternsMessageCondition;
023import org.springframework.messaging.handler.MessageCondition;
024
025/**
026 * {@link MessageCondition} for SImple Messaging Protocols. Encapsulates the following
027 * request mapping conditions:
028 * <ol>
029 * <li>{@link SimpMessageTypeMessageCondition}
030 * <li>{@link DestinationPatternsMessageCondition}
031 * </ol>
032 *
033 * @author Rossen Stoyanchev
034 * @since 4.0
035 */
036public class SimpMessageMappingInfo implements MessageCondition<SimpMessageMappingInfo> {
037
038        private final CompositeMessageCondition delegate;
039
040
041        public SimpMessageMappingInfo(SimpMessageTypeMessageCondition messageTypeMessageCondition,
042                        DestinationPatternsMessageCondition destinationConditions) {
043
044                this.delegate = new CompositeMessageCondition(messageTypeMessageCondition, destinationConditions);
045        }
046
047        private SimpMessageMappingInfo(CompositeMessageCondition delegate) {
048                this.delegate = delegate;
049        }
050
051
052        public SimpMessageTypeMessageCondition getMessageTypeMessageCondition() {
053                return this.delegate.getCondition(SimpMessageTypeMessageCondition.class);
054        }
055
056        public DestinationPatternsMessageCondition getDestinationConditions() {
057                return this.delegate.getCondition(DestinationPatternsMessageCondition.class);
058        }
059
060
061        @Override
062        public SimpMessageMappingInfo combine(SimpMessageMappingInfo other) {
063                return new SimpMessageMappingInfo(this.delegate.combine(other.delegate));
064        }
065
066        @Override
067        @Nullable
068        public SimpMessageMappingInfo getMatchingCondition(Message<?> message) {
069                CompositeMessageCondition condition = this.delegate.getMatchingCondition(message);
070                return condition != null ? new SimpMessageMappingInfo(condition) : null;
071        }
072
073        @Override
074        public int compareTo(SimpMessageMappingInfo other, Message<?> message) {
075                return this.delegate.compareTo(other.delegate, message);
076        }
077
078
079        @Override
080        public boolean equals(@Nullable Object other) {
081                if (this == other) {
082                        return true;
083                }
084                if (!(other instanceof SimpMessageMappingInfo)) {
085                        return false;
086                }
087                return this.delegate.equals(((SimpMessageMappingInfo) other).delegate);
088        }
089
090        @Override
091        public int hashCode() {
092                return this.delegate.hashCode();
093        }
094
095        @Override
096        public String toString() {
097                return this.delegate.toString();
098        }
099
100}