本文整理汇总了Java中org.jivesoftware.smackx.packet.AdHocCommandData类的典型用法代码示例。如果您正苦于以下问题:Java AdHocCommandData类的具体用法?Java AdHocCommandData怎么用?Java AdHocCommandData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AdHocCommandData类属于org.jivesoftware.smackx.packet包,在下文中一共展示了AdHocCommandData类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeAction
import org.jivesoftware.smackx.packet.AdHocCommandData; //导入依赖的package包/类
/**
* Executes the <code>action</codo> with the <code>form</code>.
* The action could be any of the available actions. The form must
* be the anwser of the previous stage. It can be <tt>null</tt> if it is the first stage.
*
* @param action the action to execute.
* @param form the form with the information.
* @param timeout the amount of time to wait for a reply.
* @throws XMPPException if there is a problem executing the command.
*/
private void executeAction(Action action, Form form, long timeout) throws XMPPException {
// TODO: Check that all the required fields of the form were filled, if
// TODO: not throw the corresponding exeption. This will make a faster response,
// TODO: since the request is stoped before it's sent.
AdHocCommandData data = new AdHocCommandData();
data.setType(IQ.Type.SET);
data.setTo(getOwnerJID());
data.setNode(getNode());
data.setSessionID(sessionID);
data.setAction(action);
if (form != null) {
data.setForm(form.getDataFormToSend());
}
PacketCollector collector = connection.createPacketCollector(
new PacketIDFilter(data.getPacketID()));
connection.sendPacket(data);
Packet response = collector.nextResult(timeout);
// Cancel the collector.
collector.cancel();
if (response == null) {
throw new XMPPException("No response from server on status set.");
}
if (response.getError() != null) {
throw new XMPPException(response.getError());
}
AdHocCommandData responseData = (AdHocCommandData) response;
this.sessionID = responseData.getSessionID();
super.setData(responseData);
}
示例2: respondError
import org.jivesoftware.smackx.packet.AdHocCommandData; //导入依赖的package包/类
/**
* Responds an error with an specific condition.
*
* @param response the response to send.
* @param condition the condition of the error.
* @param specificCondition the adhoc command error condition.
*/
private void respondError(AdHocCommandData response, XMPPError.Condition condition,
AdHocCommand.SpecificErrorCondition specificCondition)
{
XMPPError error = new XMPPError(condition);
error.addExtension(new AdHocCommandData.SpecificError(specificCondition));
respondError(response, error);
}
示例3: getSpecificErrorCondition
import org.jivesoftware.smackx.packet.AdHocCommandData; //导入依赖的package包/类
/**
* Returns the specific condition of the <code>error</code> or <tt>null</tt> if the
* error doesn't have any.
*
* @param error the error the get the specific condition from.
* @return the specific condition of this error, or null if it doesn't have
* any.
*/
public static SpecificErrorCondition getSpecificErrorCondition(XMPPError error) {
// This method is implemented to provide an easy way of getting a packet
// extension of the XMPPError.
for (SpecificErrorCondition condition : SpecificErrorCondition.values()) {
if (error.getExtension(condition.toString(),
AdHocCommandData.SpecificError.namespace) != null) {
return condition;
}
}
return null;
}
示例4: executeAction
import org.jivesoftware.smackx.packet.AdHocCommandData; //导入依赖的package包/类
/**
* Executes the <code>action</codo> with the <code>form</code>. The action
* could be any of the available actions. The form must be the anwser of the
* previous stage. It can be <tt>null</tt> if it is the first stage.
*
* @param action
* the action to execute.
* @param form
* the form with the information.
* @param timeout
* the amount of time to wait for a reply.
* @throws XMPPException
* if there is a problem executing the command.
*/
private void executeAction(Action action, Form form, long timeout)
throws XMPPException {
// TODO: Check that all the required fields of the form were filled, if
// TODO: not throw the corresponding exeption. This will make a faster
// response,
// TODO: since the request is stoped before it's sent.
AdHocCommandData data = new AdHocCommandData();
data.setType(IQ.Type.SET);
data.setTo(getOwnerJID());
data.setNode(getNode());
data.setSessionID(sessionID);
data.setAction(action);
if (form != null) {
data.setForm(form.getDataFormToSend());
}
PacketCollector collector = connection
.createPacketCollector(new PacketIDFilter(data.getPacketID()));
connection.sendPacket(data);
Packet response = collector.nextResult(timeout);
// Cancel the collector.
collector.cancel();
if (response == null) {
throw new XMPPException("No response from server on status set.");
}
if (response.getError() != null) {
throw new XMPPException(response.getError());
}
AdHocCommandData responseData = (AdHocCommandData) response;
this.sessionID = responseData.getSessionID();
super.setData(responseData);
}
示例5: getSpecificErrorCondition
import org.jivesoftware.smackx.packet.AdHocCommandData; //导入依赖的package包/类
/**
* Returns the specific condition of the <code>error</code> or <tt>null</tt>
* if the error doesn't have any.
*
* @param error
* the error the get the specific condition from.
* @return the specific condition of this error, or null if it doesn't have
* any.
*/
public static SpecificErrorCondition getSpecificErrorCondition(
XMPPError error) {
// This method is implemented to provide an easy way of getting a packet
// extension of the XMPPError.
for (SpecificErrorCondition condition : SpecificErrorCondition.values()) {
if (error.getExtension(condition.toString(),
AdHocCommandData.SpecificError.namespace) != null) {
return condition;
}
}
return null;
}
示例6: AdHocCommand
import org.jivesoftware.smackx.packet.AdHocCommandData; //导入依赖的package包/类
public AdHocCommand() {
super();
data = new AdHocCommandData();
}
示例7: setData
import org.jivesoftware.smackx.packet.AdHocCommandData; //导入依赖的package包/类
@Override
void setData(AdHocCommandData data) {
data.setSessionID(sessionID);
super.setData(data);
}
示例8: parseIQ
import org.jivesoftware.smackx.packet.AdHocCommandData; //导入依赖的package包/类
public IQ parseIQ(XmlPullParser parser) throws Exception {
boolean done = false;
AdHocCommandData adHocCommandData = new AdHocCommandData();
DataFormProvider dataFormProvider = new DataFormProvider();
int eventType;
String elementName;
String namespace;
adHocCommandData.setSessionID(parser.getAttributeValue("", "sessionid"));
adHocCommandData.setNode(parser.getAttributeValue("", "node"));
// Status
String status = parser.getAttributeValue("", "status");
if (AdHocCommand.Status.executing.toString().equalsIgnoreCase(status)) {
adHocCommandData.setStatus(AdHocCommand.Status.executing);
}
else if (AdHocCommand.Status.completed.toString().equalsIgnoreCase(status)) {
adHocCommandData.setStatus(AdHocCommand.Status.completed);
}
else if (AdHocCommand.Status.canceled.toString().equalsIgnoreCase(status)) {
adHocCommandData.setStatus(AdHocCommand.Status.canceled);
}
// Action
String action = parser.getAttributeValue("", "action");
if (action != null) {
Action realAction = AdHocCommand.Action.valueOf(action);
if (realAction == null || realAction.equals(Action.unknown)) {
adHocCommandData.setAction(Action.unknown);
}
else {
adHocCommandData.setAction(realAction);
}
}
while (!done) {
eventType = parser.next();
elementName = parser.getName();
namespace = parser.getNamespace();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("actions")) {
String execute = parser.getAttributeValue("", "execute");
if (execute != null) {
adHocCommandData.setExecuteAction(AdHocCommand.Action.valueOf(execute));
}
}
else if (parser.getName().equals("next")) {
adHocCommandData.addAction(AdHocCommand.Action.next);
}
else if (parser.getName().equals("complete")) {
adHocCommandData.addAction(AdHocCommand.Action.complete);
}
else if (parser.getName().equals("prev")) {
adHocCommandData.addAction(AdHocCommand.Action.prev);
}
else if (elementName.equals("x") && namespace.equals("jabber:x:data")) {
adHocCommandData.setForm((DataForm) dataFormProvider.parseExtension(parser));
}
else if (parser.getName().equals("note")) {
AdHocCommandNote.Type type = AdHocCommandNote.Type.valueOf(
parser.getAttributeValue("", "type"));
String value = parser.nextText();
adHocCommandData.addNote(new AdHocCommandNote(type, value));
}
else if (parser.getName().equals("error")) {
XMPPError error = PacketParserUtils.parseError(parser);
adHocCommandData.setError(error);
}
}
else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("command")) {
done = true;
}
}
}
return adHocCommandData;
}
示例9: parseExtension
import org.jivesoftware.smackx.packet.AdHocCommandData; //导入依赖的package包/类
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
return new AdHocCommandData.SpecificError(AdHocCommand.SpecificErrorCondition.badAction);
}
示例10: AdHocCommandManager
import org.jivesoftware.smackx.packet.AdHocCommandData; //导入依赖的package包/类
private AdHocCommandManager(Connection connection) {
this.connection = new WeakReference<Connection>(connection);
this.serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection);
// Register the new instance and associate it with the connection
instances.put(connection, this);
// Add the feature to the service discovery manage to show that this
// connection supports the AdHoc-Commands protocol.
// This information will be used when another client tries to
// discover whether this client supports AdHoc-Commands or not.
ServiceDiscoveryManager.getInstanceFor(connection).addFeature(
DISCO_NAMESPACE);
// Set the NodeInformationProvider that will provide information about
// which AdHoc-Commands are registered, whenever a disco request is
// received
ServiceDiscoveryManager.getInstanceFor(connection)
.setNodeInformationProvider(discoNode,
new NodeInformationProvider() {
public List<DiscoverItems.Item> getNodeItems() {
List<DiscoverItems.Item> answer = new ArrayList<DiscoverItems.Item>();
Collection<AdHocCommandInfo> commandsList = getRegisteredCommands();
for (AdHocCommandInfo info : commandsList) {
DiscoverItems.Item item = new DiscoverItems.Item(
info.getOwnerJID());
item.setName(info.getName());
item.setNode(info.getNode());
answer.add(item);
}
return answer;
}
public List<String> getNodeFeatures() {
return null;
}
public List<Identity> getNodeIdentities() {
return null;
}
@Override
public List<PacketExtension> getNodePacketExtensions() {
return null;
}
});
// The packet listener and the filter for processing some AdHoc Commands
// Packets
PacketListener listener = new PacketListener() {
public void processPacket(Packet packet) {
AdHocCommandData requestData = (AdHocCommandData) packet;
processAdHocCommand(requestData);
}
};
PacketFilter filter = new PacketTypeFilter(AdHocCommandData.class);
connection.addPacketListener(listener, filter);
sessionsSweeper = null;
}
示例11: AdHocCommand
import org.jivesoftware.smackx.packet.AdHocCommandData; //导入依赖的package包/类
public AdHocCommand() {
super();
data = new AdHocCommandData();
}
示例12: setData
import org.jivesoftware.smackx.packet.AdHocCommandData; //导入依赖的package包/类
@Override
void setData(AdHocCommandData data) {
data.setSessionID(sessionID);
super.setData(data);
}
示例13: parseIQ
import org.jivesoftware.smackx.packet.AdHocCommandData; //导入依赖的package包/类
public IQ parseIQ(XmlPullParser parser) throws Exception {
boolean done = false;
AdHocCommandData adHocCommandData = new AdHocCommandData();
DataFormProvider dataFormProvider = new DataFormProvider();
int eventType;
String elementName;
String namespace;
adHocCommandData
.setSessionID(parser.getAttributeValue("", "sessionid"));
adHocCommandData.setNode(parser.getAttributeValue("", "node"));
// Status
String status = parser.getAttributeValue("", "status");
if (AdHocCommand.Status.executing.toString().equalsIgnoreCase(status)) {
adHocCommandData.setStatus(AdHocCommand.Status.executing);
} else if (AdHocCommand.Status.completed.toString().equalsIgnoreCase(
status)) {
adHocCommandData.setStatus(AdHocCommand.Status.completed);
} else if (AdHocCommand.Status.canceled.toString().equalsIgnoreCase(
status)) {
adHocCommandData.setStatus(AdHocCommand.Status.canceled);
}
// Action
String action = parser.getAttributeValue("", "action");
if (action != null) {
Action realAction = AdHocCommand.Action.valueOf(action);
if (realAction == null || realAction.equals(Action.unknown)) {
adHocCommandData.setAction(Action.unknown);
} else {
adHocCommandData.setAction(realAction);
}
}
while (!done) {
eventType = parser.next();
elementName = parser.getName();
namespace = parser.getNamespace();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("actions")) {
String execute = parser.getAttributeValue("", "execute");
if (execute != null) {
adHocCommandData.setExecuteAction(AdHocCommand.Action
.valueOf(execute));
}
} else if (parser.getName().equals("next")) {
adHocCommandData.addAction(AdHocCommand.Action.next);
} else if (parser.getName().equals("complete")) {
adHocCommandData.addAction(AdHocCommand.Action.complete);
} else if (parser.getName().equals("prev")) {
adHocCommandData.addAction(AdHocCommand.Action.prev);
} else if (elementName.equals("x")
&& namespace.equals("jabber:x:data")) {
adHocCommandData.setForm((DataForm) dataFormProvider
.parseExtension(parser));
} else if (parser.getName().equals("note")) {
AdHocCommandNote.Type type = AdHocCommandNote.Type
.valueOf(parser.getAttributeValue("", "type"));
String value = parser.nextText();
adHocCommandData.addNote(new AdHocCommandNote(type, value));
} else if (parser.getName().equals("error")) {
XMPPError error = PacketParserUtils.parseError(parser);
adHocCommandData.setError(error);
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("command")) {
done = true;
}
}
}
return adHocCommandData;
}
示例14: parseExtension
import org.jivesoftware.smackx.packet.AdHocCommandData; //导入依赖的package包/类
public PacketExtension parseExtension(XmlPullParser parser)
throws Exception {
return new AdHocCommandData.SpecificError(
AdHocCommand.SpecificErrorCondition.badAction);
}