/** * Creates an instant node, if supported. * * @return The node that was created * @exception XMPPException */ public Node createNode() throws XMPPException { PubSub reply = (PubSub) sendPubsubPacket(Type.SET, new NodeExtension(PubSubElementType.CREATE)); NodeExtension elem = (NodeExtension) reply.getExtension("create", PubSubNamespace.BASIC.getXmlns()); Node newNode = new Node(con, elem.getNode()); newNode.setTo(to); nodeMap.put(newNode.getId(), newNode); return newNode; }
/** * Creates a node with specified configuration. * * @param name The name of the node, which must be unique within the pubsub service * @param config The configuration for the node * @return The node that was created * @exception XMPPException */ public Node createNode(String name, Form config) throws XMPPException { PubSub request = createPubsubPacket(to, Type.SET, new NodeExtension(PubSubElementType.CREATE, name)); if (config != null) request.addExtension(new FormNode(FormNodeType.CONFIGURE, config)); // Errors will cause exceptions in getReply, so it only returns // on success. sendPubsubPacket(con, to, Type.SET, request); Node newNode = new Node(con, name); newNode.setTo(to); nodeMap.put(newNode.getId(), newNode); return newNode; }
/** * Creates a node with specified configuration. * * <p>Note: This is the only way to create a collection node. * * @param name The name of the node, which must be unique within the pubsub service * @param config The configuration for the node * @return The node that was created * @exception XMPPException */ public Node createNode(String name, Form config) throws XMPPException { PubSub request = createPubsubPacket(to, Type.SET, new NodeExtension(PubSubElementType.CREATE, name)); boolean isLeafNode = true; if (config != null) { request.addExtension(new FormNode(FormNodeType.CONFIGURE, config)); FormField nodeTypeField = config.getField(ConfigureNodeFields.node_type.getFieldName()); if (nodeTypeField != null) isLeafNode = nodeTypeField.getValues().next().equals(NodeType.leaf.toString()); } // Errors will cause exceptions in getReply, so it only returns // on success. sendPubsubPacket(con, to, Type.SET, request); Node newNode = isLeafNode ? new LeafNode(con, name) : new CollectionNode(con, name); newNode.setTo(to); nodeMap.put(newNode.getId(), newNode); return newNode; }