class AttachExistingElementRpcHandler extends AbstractRpcInvocationHandler {

    @Override
    protected Optional<Runnable> handleNode(StateNode node, JsonObject invocationJson) {
        assert invocationJson.hasKey(JsonConstants.RPC_ATTACH_REQUESTED_ID);
        assert invocationJson.hasKey(JsonConstants.RPC_ATTACH_ASSIGNED_ID);
        assert invocationJson.hasKey(JsonConstants.RPC_ATTACH_TAG_NAME);
        assert invocationJson.hasKey(JsonConstants.RPC_ATTACH_INDEX);

        int requestedId = (int) invocationJson
                .getNumber(JsonConstants.RPC_ATTACH_REQUESTED_ID);
        int assignedId = (int) invocationJson
                .getNumber(JsonConstants.RPC_ATTACH_ASSIGNED_ID);
        String tag = invocationJson
                .getString(JsonConstants.RPC_ATTACH_TAG_NAME);
        int index = (int) invocationJson
                .getNumber(JsonConstants.RPC_ATTACH_INDEX);

        AttachExistingElementFeature feature = node
                .getFeature(AttachExistingElementFeature.class);

        StateTree tree = (StateTree) node.getOwner();
        StateNode requestedNode = tree.getNodeById(requestedId);
        if (assignedId == -1) {
            // handle an error
            assert index == -1;

            ChildElementConsumer callback = feature.getCallback(requestedNode);
            assert callback != null;
            callback.onError(feature.getParent(requestedNode), tag,
                    feature.getPreviousSibling(requestedNode));

            feature.unregister(requestedNode);
        } else {
            Element element = Element.get(tree.getNodeById(assignedId));

            attachElement(feature, element, index,
                    tree.getNodeById(requestedId), requestedId == assignedId);
        }

        return Optional.empty();
    }

}