/** * $RCSfile$ * $Revision$ * $Date$ * * Copyright 2003-2004 Jive Software. * * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jivesoftware.smackx.packet; import java.util.*; import org.jivesoftware.smack.packet.IQ; /** * A DiscoverInfo IQ packet, which is used by XMPP clients to request and receive information * to/from other XMPP entities.
* * The received information may contain one or more identities of the requested XMPP entity, and * a list of supported features by the requested XMPP entity. * * @author Gaston Dombiak */ public class DiscoverInfo extends IQ { private List features = new ArrayList(); private List identities = new ArrayList(); private String node; /** * Adds a new feature to the discovered information. * * @param feature the discovered feature */ public void addFeature(String feature) { addFeature(new DiscoverInfo.Feature(feature)); } private void addFeature(Feature feature) { synchronized (features) { features.add(feature); } } /** * Returns the discovered features of an XMPP entity. * * @return an Iterator on the discovered features of an XMPP entity */ Iterator getFeatures() { synchronized (features) { return Collections.unmodifiableList(new ArrayList(features)).iterator(); } } /** * Adds a new identity of the requested entity to the discovered information. * * @param identity the discovered entity's identity */ public void addIdentity(Identity identity) { synchronized (identities) { identities.add(identity); } } /** * Returns the discovered identities of an XMPP entity. * * @return an Iterator on the discoveted identities */ public Iterator getIdentities() { synchronized (identities) { return Collections.unmodifiableList(new ArrayList(identities)).iterator(); } } /** * Returns the node attribute that supplements the 'jid' attribute. A node is merely * something that is associated with a JID and for which the JID can provide information.
* * Node attributes SHOULD be used only when trying to provide or query information which * is not directly addressable. * * @return the node attribute that supplements the 'jid' attribute */ public String getNode() { return node; } /** * Sets the node attribute that supplements the 'jid' attribute. A node is merely * something that is associated with a JID and for which the JID can provide information.
*
* Node attributes SHOULD be used only when trying to provide or query information which
* is not directly addressable.
*
* @param node the node attribute that supplements the 'jid' attribute
*/
public void setNode(String node) {
this.node = node;
}
/**
* Returns true if the specified feature is part of the discovered information.
*
* @param feature the feature to check
* @return true if the requestes feature has been discovered
*/
public boolean containsFeature(String feature) {
for (Iterator it = getFeatures(); it.hasNext();) {
if (feature.equals(((DiscoverInfo.Feature) it.next()).getVar()))
return true;
}
return false;
}
public String getChildElementXML() {
StringBuffer buf = new StringBuffer();
buf.append("
*
* Refer to Jabber::Registrar
* in order to get the official registry of values for the category and type
* attributes.
*
*/
public static class Identity {
private String category;
private String name;
private String type;
/**
* Creates a new identity for an XMPP entity.
*
* @param category the entity's category.
* @param name the entity's name.
*/
public Identity(String category, String name) {
this.category = category;
this.name = name;
}
/**
* Returns the entity's category. To get the official registry of values for the
* 'category' attribute refer to Jabber::Registrar
*
* @return the entity's category.
*/
public String getCategory() {
return category;
}
/**
* Returns the identity's name.
*
* @return the identity's name.
*/
public String getName() {
return name;
}
/**
* Returns the entity's type. To get the official registry of values for the
* 'type' attribute refer to Jabber::Registrar
*
* @return the entity's type.
*/
public String getType() {
return type;
}
/**
* Sets the entity's type. To get the official registry of values for the
* 'type' attribute refer to Jabber::Registrar
*
* @param type the identity's type.
*/
public void setType(String type) {
this.type = type;
}
public String toXML() {
StringBuffer buf = new StringBuffer();
buf.append("