Code Generation
February 11 2004 12:24 PM

Jon Udell writes about code generation ... it's the kind of article that makes me think "Hey, I want to do that too!" and distracts me from whatever I'm working on at the moment. Could be related to an aesthetic I attribute to self-modifying code which was introduced to me in a college course on Assembler programming which also brings to mind the beautiful notion of single instruction set computing.

Tangents leading to tangents. If I keep this up I'll never get back to work.

Since most of my work is done in Java I thought I would see what existed for generating Java code.

First hit was an article at onjava.

This article mostly talks about code generation as a static step that happens before compilation and runtime. I am more interested in generating new Java classes and instantiating them at runtime.

I know the java compiler is available at runtime so I hacked together a little program that takes an SQL query, executes it, generates the source for a JavaBean that matches the returned, compiles the source, then assigns records from the result set into instances of the newly defined class.

Check out the source if you're curious.

Comments (0), Add Comment