Tomek OsiĆski | 7a1db18 | 2018-02-03 17:15:06 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 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.onosproject.xmpp.pubsub.model; |
| 18 | |
| 19 | import org.xmpp.packet.PacketError; |
| 20 | import static org.onosproject.xmpp.pubsub.XmppPubSubConstants.APP_BASE_CONDITION_MAP; |
| 21 | import static org.onosproject.xmpp.pubsub.XmppPubSubConstants.PUBSUB_ERROR_NS; |
| 22 | import static org.onosproject.xmpp.pubsub.XmppPubSubConstants.PubSubApplicationCondition; |
| 23 | |
| 24 | /** |
| 25 | * Abstracts Publish/Subscribe error message of XMPP PubSub protocol. |
| 26 | */ |
| 27 | public class XmppPubSubError { |
| 28 | |
| 29 | private PacketError.Condition baseCondition; |
| 30 | private PubSubApplicationCondition applicationCondition; |
| 31 | |
| 32 | public XmppPubSubError(PubSubApplicationCondition applicationCondition) { |
| 33 | this.applicationCondition = applicationCondition; |
| 34 | this.baseCondition = setBasedOnAppCondition(); |
| 35 | } |
| 36 | |
| 37 | private PacketError.Condition setBasedOnAppCondition() { |
| 38 | return APP_BASE_CONDITION_MAP.getOrDefault(this.applicationCondition, |
| 39 | PacketError.Condition.undefined_condition); |
| 40 | } |
| 41 | |
| 42 | public PacketError asPacketError() { |
| 43 | PacketError packetError = new PacketError(this.baseCondition); |
| 44 | if (applicationCondition != null) { |
| 45 | packetError.setApplicationCondition(applicationCondition.toString().toLowerCase(), |
| 46 | PUBSUB_ERROR_NS); |
| 47 | } |
| 48 | return packetError; |
| 49 | } |
| 50 | |
| 51 | } |