The code you see above isn't working code, as such. It's code I pasted from working code and then altered to make it "read better". Being an idiot I've made a few typos while doing that. If you want to better understand the code then you'll need to download the NSF demo file and see the Java in there. It should make more sense. I also left out things I thought it safe to assume - like that the "doc" is the DocumentContext etc. Although I can see the confusion with the "document" object which is the PDF document and not a Notes one. My variable naming has never been that clear really.
Truth is I don't really understand the interplay between all the objects you mentioned enough to feel qualified to document it that well. All I'm good at is getting stuff to work. You don't always need to understand it to do that ;o)