Many composers in the past (as well as the present) were known to do that. So, are there any ways in order to achieve this? Any exercises and so on?
I agree with Babu that you're really talking about several distinct skills: but they are certainly related and gains with any one of the skills should offer leverage on the others.
You're really training your brain to perform musical "translations" among various inputs and outputs.
Sight-singing. Translation from written (graphical-input) notation to vocal (muscular-output) "notation".
Transcription. Translation from acoustical (audio-input) notation to written (graphical-output).
Sight-Reading. Translation from written notation to audile-imagination (a neural firing-pattern).
Composing. Translation from imagination to written notation.
Improvisation. Translation from imagination to muscular performance.
Each of these has to pass the information through the musical "understanding". So you need the theoretical tools to make sense of what the music means.
For ear-training, one well-kept secret is the use of earplugs and low-volumes in general. Straining to hear is strenuous; thus, exercise.
For learning notation (both reading and writing) you need material for practice (of course) and a Moleskine music-stave notebook (after 20 years of searching, it's the best. hands down.) Jot down every melody that pops into your head. Check it on an instrument to see if what you wrote bears any resemblance to what you imagined (for a long time, it probably won't; don't despair, make corrections and continue). Don't worry about writing "pretty". Don't draw the stems hanging off the notes like printed music: draw the stems straight up or down from the center of the note head, making the entire note in one quick motion. You need speed to get things down before they evaporate.
For sight-singing, solfage is pretty useful for building up your ability to recognize and reproduce diatonic intervals.
It sounds like you're trying to do a bunch of things here. Strictly, audiation is "hearing" music in your head, without any sort of sounds actually happening. As NReilingh says, pretty much everyone can imagine music.
You mixed audiation in with reading music and with transcription. Audiation, transcription, and reading music are skills that are improved solely by practice. I am unaware of any collection of exercises for these skills because they generally develop naturally over the course of learning an instrument. I would be extremely surprised if such exercises did not exist, and I would be even more shocked if they were more useful than practicing on your own. Here's a general road map to guide you in developing these skills. Keep in mind, this may well take years to pick up, depending on your ability to read and write music.
To develop the ability to audiate from a score, sit down with music you know well and imagine what it sounds like as you read through the score. Once you can do this, take simple music that you do not know, try to figure out what it sounds like, and then check yourself by playing through it. As a side note, I find this skill invaluable for sight-reading, because I personally find it easier to play by ear than by notes.
To develop the ability to compose (or, transcribe from an audiated melody), first get comfortable transcribing performances. Take a recording of a simple classical piece and try to write down what the performer is playing, then check what you wrote (either by entering it into a program like Finale and hearing it played back, or by playing it yourself). In the beginning, using a keyboard to "cheat" and identify notes and intervals is fine, but over time try to wean yourself off of it. Once you're comfortable transcribing music without using an instrument to help, you should find that transcribing an audiated melody is not much different.