This one’s a new idea from me. You already know that .Net provides a runtime-based system for accessing attributes (@tags), so you can simply do something like anobj.getClass().getAttribute(“ejb.bean”) for example, whereas in java you read an xml file, and XDoclet is a compile time system which reads attributes. JSR 175 works on a runtime system, but for now what do you think about a simple simulation of a runtime attribute access API? So the idea behind XRAI is a post-proccessor ant task which reads source code and modifies the compiled classes with BCEL and injects some static fields to classes. It injects things like private static final Attribute[] attributes = new Attribute[]{new Attribute(“ejb.bean”, …)} and with a naming convention for method level tags too. You’ll be able to access the tags with an API like this: AClass.getAttribute(“ejb.bean”). Looks very simple and feasible imho. Ideas?


[Memory Dump]

Superb. This was something I was thinking of at the weekend, how to implement .net style attributes in Java. I was thinking XDoclet or QDox would be the way to go as far as processing the attributes, but was stuck on how to weave them into the code. I initially considered extending the class with a dynamic proxy (I seem to be seeing them everywhere I look these days), but that would only work for interfaces. BCEL could well do the job, but how would you go about injecting the methods into the API? I’m curious.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s