001/** 002 * 003 * Copyright 2014 Vyacheslav Blinov 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.jivesoftware.smackx.amp; 018 019import org.jivesoftware.smack.SmackException.NoResponseException; 020import org.jivesoftware.smack.SmackException.NotConnectedException; 021import org.jivesoftware.smack.XMPPConnection; 022import org.jivesoftware.smack.XMPPException.XMPPErrorException; 023import org.jivesoftware.smackx.amp.packet.AMPExtension; 024 025public class AMPDeliverCondition implements AMPExtension.Condition { 026 027 public static final String NAME = "deliver"; 028 029 /** 030 * Check if server supports deliver condition 031 * @param connection Smack connection instance 032 * @return true if deliver condition is supported. 033 * @throws XMPPErrorException 034 * @throws NoResponseException 035 * @throws NotConnectedException 036 */ 037 public static boolean isSupported(XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException { 038 return AMPManager.isConditionSupported(connection, NAME); 039 } 040 041 private final Value value; 042 043 /** 044 * Create new amp deliver condition with value setted to one of defined by XEP-0079. 045 * See http://xmpp.org/extensions/xep-0079.html#conditions-def-deliver 046 * @param value AMPDeliveryCondition.Value instance that will be used as value parameter. Can't be null. 047 */ 048 public AMPDeliverCondition(Value value) { 049 if (value == null) 050 throw new NullPointerException("Can't create AMPDeliverCondition with null value"); 051 this.value = value; 052 } 053 054 @Override 055 public String getName() { 056 return NAME; 057 } 058 059 @Override 060 public String getValue() { 061 return value.toString(); 062 } 063 064 /** 065 * Value for amp deliver condition as defined by XEP-0079. 066 * See http://xmpp.org/extensions/xep-0079.html#conditions-def-deliver 067 */ 068 public static enum Value { 069 /** 070 * The message would be immediately delivered to the intended recipient or routed to the next hop. 071 */ 072 direct, 073 /** 074 * The message would be forwarded to another XMPP address or account. 075 */ 076 forward, 077 /** 078 * The message would be sent through a gateway to an address or account on a non-XMPP system. 079 */ 080 gateway, 081 /** 082 * The message would not be delivered at all (e.g., because the intended recipient is offline and message storage is not enabled). 083 */ 084 none, 085 /** 086 * The message would be stored offline for later delivery to the intended recipient. 087 */ 088 stored 089 } 090}