use of org.jivesoftware.smackx.iot.discovery.element.IoTRegister in project Smack by igniterealtime.
the class IoTRegisterProvider method parse.
@Override
public IoTRegister parse(XmlPullParser parser, int initialDepth) throws Exception {
boolean selfOwned = ParserUtils.getBooleanAttribute(parser, "selfOwned", false);
NodeInfo nodeInfo = NodeInfoParser.parse(parser);
List<Tag> tags = new ArrayList<>();
while (parser.getDepth() != initialDepth) {
int event = parser.next();
if (event != XmlPullParser.START_TAG) {
continue;
}
final String element = parser.getName();
Tag.Type type = null;
switch(element) {
case "str":
type = Tag.Type.str;
break;
case "num":
type = Tag.Type.num;
break;
}
if (type == null) {
continue;
}
String name = parser.getAttributeValue(null, "name");
String value = parser.getAttributeValue(null, "value");
tags.add(new Tag(name, type, value));
}
return new IoTRegister(tags, nodeInfo, selfOwned);
}
use of org.jivesoftware.smackx.iot.discovery.element.IoTRegister in project Smack by igniterealtime.
the class IoTDiscoveryManager method registerThing.
public ThingState registerThing(Jid registry, Thing thing) throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException, IoTClaimedException {
final XMPPConnection connection = connection();
IoTRegister iotRegister = new IoTRegister(thing.getMetaTags(), thing.getNodeInfo(), thing.isSelfOwened());
iotRegister.setTo(registry);
IQ result = connection.createStanzaCollectorAndSend(iotRegister).nextResultOrThrow();
if (result instanceof IoTClaimed) {
IoTClaimed iotClaimedResult = (IoTClaimed) result;
throw new IoTClaimedException(iotClaimedResult);
}
ThingState state = getStateFor(thing.getNodeInfo());
state.setRegistry(registry.asBareJid());
interactWithRegistry(registry);
IoTDataManager.getInstanceFor(connection).installThing(thing);
IoTControlManager.getInstanceFor(connection).installThing(thing);
return state;
}
Aggregations