Gandalf is the hardest I think. If Christ he is too weak for my understanding, if the Holy Spirit perhaps more directly acting than I envision, if a man led by the Holy Spirit, perhaps, but then what of the resurrection, not of his own power but by Eru, and if the Holy Spirit then what of his sailing away with the elves and leaving men?
Leaving Middle Earth with the elves may be a statement about the free will of men in an environment where evil has been destroyed.