Search in sources :

Example 1 with IoTRegister

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);
}
Also used : NodeInfo(org.jivesoftware.smackx.iot.element.NodeInfo) ArrayList(java.util.ArrayList) Tag(org.jivesoftware.smackx.iot.discovery.element.Tag) IoTRegister(org.jivesoftware.smackx.iot.discovery.element.IoTRegister)

Example 2 with IoTRegister

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;
}
Also used : IQ(org.jivesoftware.smack.packet.IQ) IoTClaimed(org.jivesoftware.smackx.iot.discovery.element.IoTClaimed) XMPPConnection(org.jivesoftware.smack.XMPPConnection) IoTRegister(org.jivesoftware.smackx.iot.discovery.element.IoTRegister)

Aggregations

IoTRegister (org.jivesoftware.smackx.iot.discovery.element.IoTRegister)2 ArrayList (java.util.ArrayList)1 XMPPConnection (org.jivesoftware.smack.XMPPConnection)1 IQ (org.jivesoftware.smack.packet.IQ)1 IoTClaimed (org.jivesoftware.smackx.iot.discovery.element.IoTClaimed)1 Tag (org.jivesoftware.smackx.iot.discovery.element.Tag)1 NodeInfo (org.jivesoftware.smackx.iot.element.NodeInfo)1