public static CorbaRoutingTable serializeRoutingTable(RoutingTable routingTable) {
        if (routingTable == null) {
            throw new NullPointerException("Cannot transform a null value to a CORBA object");
        }
        if (routingTable.getLocalhost() == null) {
            throw new IllegalStateException("RoutingTable is not in a legal state. Its host owner reference is null.");
        }
        if (routingTable.levelNumber() == 0) {
            return new CorbaRoutingTable(
                    new PeerReference[0][0],
                    serializeHost(routingTable.getLocalhost()));
        }

        Collection<Collection<Host>> refs = routingTable.getAllHostsByLevels();
        PeerReference[][] peerRefs = new PeerReference[refs.size()][];

        int levelIndex = 0;
        for (Collection<Host> level : refs) {
            PeerReference[] levelRefs = new PeerReference[level.size()];
            int hostIndex = 0;
            for (Host host : level) {
                levelRefs[hostIndex] = serializeHost(host);
                hostIndex++;
            }
            peerRefs[levelIndex] = levelRefs;
            levelIndex++;
        }

        PeerReference localhost = serializeHost(routingTable.getLocalhost());
        return new CorbaRoutingTable(peerRefs, localhost);
    }