001/** 002 * 003 * Copyright © 2014-2020 Florian Schmaus 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.smack.packet; 018 019import java.util.Collection; 020import java.util.Collections; 021import java.util.LinkedList; 022import java.util.List; 023 024import javax.xml.namespace.QName; 025 026import org.jivesoftware.smack.util.XmlStringBuilder; 027 028public class Mechanisms implements ExtensionElement { 029 030 public static final String ELEMENT = "mechanisms"; 031 public static final String NAMESPACE = "urn:ietf:params:xml:ns:xmpp-sasl"; 032 public static final QName QNAME = new QName(NAMESPACE, ELEMENT); 033 034 public final List<String> mechanisms = new LinkedList<String>(); 035 036 public Mechanisms(String mechanism) { 037 mechanisms.add(mechanism); 038 } 039 040 public Mechanisms(Collection<String> mechanisms) { 041 this.mechanisms.addAll(mechanisms); 042 } 043 044 @Override 045 public String getElementName() { 046 return ELEMENT; 047 } 048 049 @Override 050 public String getNamespace() { 051 return NAMESPACE; 052 } 053 054 public List<String> getMechanisms() { 055 return Collections.unmodifiableList(mechanisms); 056 } 057 058 @Override 059 public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) { 060 XmlStringBuilder xml = new XmlStringBuilder(this); 061 xml.rightAngleBracket(); 062 for (String mechanism : mechanisms) { 063 xml.element("mechanism", mechanism); 064 } 065 xml.closeElement(this); 066 return xml; 067 } 068 069}