AMPDeliverCondition.java

  1. /**
  2.  *
  3.  * Copyright 2014 Vyacheslav Blinov
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.jivesoftware.smackx.amp;

  18. import org.jivesoftware.smack.SmackException.NoResponseException;
  19. import org.jivesoftware.smack.SmackException.NotConnectedException;
  20. import org.jivesoftware.smack.XMPPConnection;
  21. import org.jivesoftware.smack.XMPPException.XMPPErrorException;

  22. import org.jivesoftware.smackx.amp.packet.AMPExtension;

  23. public class AMPDeliverCondition implements AMPExtension.Condition {

  24.     public static final String NAME = "deliver";

  25.     /**
  26.      * Check if server supports deliver condition.
  27.      * @param connection Smack connection instance
  28.      * @return true if deliver condition is supported.
  29.      * @throws XMPPErrorException if there was an XMPP error returned.
  30.      * @throws NoResponseException if there was no response from the remote entity.
  31.      * @throws NotConnectedException if the XMPP connection is not connected.
  32.      * @throws InterruptedException if the calling thread was interrupted.
  33.      */
  34.     public static boolean isSupported(XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
  35.         return AMPManager.isConditionSupported(connection, NAME);
  36.     }

  37.     private final Value value;

  38.     /**
  39.      * Create new amp deliver condition with value set to one of defined by XEP-0079.
  40.      * See http://xmpp.org/extensions/xep-0079.html#conditions-def-deliver
  41.      * @param value AMPDeliveryCondition.Value instance that will be used as value parameter. Can't be null.
  42.      */
  43.     public AMPDeliverCondition(Value value) {
  44.         if (value == null)
  45.             throw new NullPointerException("Can't create AMPDeliverCondition with null value");
  46.         this.value = value;
  47.     }

  48.     @Override
  49.     public String getName() {
  50.         return NAME;
  51.     }

  52.     @Override
  53.     public String getValue() {
  54.         return value.toString();
  55.     }

  56.     /**
  57.      * Value for amp deliver condition as defined by XEP-0079.
  58.      * See http://xmpp.org/extensions/xep-0079.html#conditions-def-deliver
  59.      */
  60.     public enum Value {
  61.         /**
  62.          * The message would be immediately delivered to the intended recipient or routed to the next hop.
  63.          */
  64.         direct,
  65.         /**
  66.          * The message would be forwarded to another XMPP address or account.
  67.          */
  68.         forward,
  69.         /**
  70.          * The message would be sent through a gateway to an address or account on a non-XMPP system.
  71.          */
  72.         gateway,
  73.         /**
  74.          * The message would not be delivered at all (e.g., because the intended recipient is offline and message storage is not enabled).
  75.          */
  76.         none,
  77.         /**
  78.          * The message would be stored offline for later delivery to the intended recipient.
  79.          */
  80.         stored
  81.     }
  82. }