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 AMPMatchResourceCondition implements AMPExtension.Condition { 026 027 public static final String NAME = "match-resource"; 028 029 /** 030 * Check if server supports match-resource condition. 031 * @param connection Smack connection instance 032 * @return true if match-resource condition is supported. 033 * @throws XMPPErrorException 034 * @throws NoResponseException 035 * @throws NotConnectedException 036 * @throws InterruptedException 037 */ 038 public static boolean isSupported(XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { 039 return AMPManager.isConditionSupported(connection, NAME); 040 } 041 042 private final Value value; 043 044 /** 045 * Create new amp match-resource condition with value setted to one of defined by XEP-0079. 046 * See http://xmpp.org/extensions/xep-0079.html#conditions-def-match 047 * @param value AMPDeliveryCondition.Value instance that will be used as value parameter. Can't be null. 048 */ 049 public AMPMatchResourceCondition(Value value) { 050 if (value == null) 051 throw new NullPointerException("Can't create AMPMatchResourceCondition with null value"); 052 this.value = value; 053 } 054 055 @Override 056 public String getName() { 057 return NAME; 058 } 059 060 @Override 061 public String getValue() { 062 return value.toString(); 063 } 064 065 /** 066 * match-resource amp condition value as defined by XEP-0079. 067 * See http://xmpp.org/extensions/xep-0079.html#conditions-def-match 068 */ 069 public static enum Value { 070 /** 071 * Destination resource matches any value, effectively ignoring the intended resource. 072 * Example: "home/laptop" matches "home", "home/desktop" or "work/desktop" 073 */ 074 any, 075 /** 076 * Destination resource exactly matches the intended resource. 077 * Example: "home/laptop" only matches "home/laptop" and not "home/desktop" or "work/desktop" 078 */ 079 exact, 080 /** 081 * Destination resource matches any value except for the intended resource. 082 * Example: "home/laptop" matches "work/desktop", "home" or "home/desktop", but not "home/laptop" 083 */ 084 other 085 } 086}