The Artima Developer Community
Sponsored Link

Agile Buzz Forum
A simple way to access JavaDoc attributes at runtime

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Joe Walnes

Posts: 151
Nickname: jwalnes1
Registered: Aug, 2003

Joe Walnes, "The Developers' Coach" from ThoughtWorks
A simple way to access JavaDoc attributes at runtime Posted: Aug 7, 2004 7:20 PM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by Joe Walnes.
Original Post: A simple way to access JavaDoc attributes at runtime
Feed Title: Joe's New Jelly
Feed URL: http://joe.truemesh.com/blog/index.rdf
Feed Description: The musings of a ThoughtWorker obsessed with Agile, XP, maintainability, Java, .NET, Ruby and OpenSource. Mmm'kay?
Latest Agile Buzz Posts
Latest Agile Buzz Posts by Joe Walnes
Latest Posts From Joe's New Jelly

Advertisement

It's easy to gain access to JavaDoc attributes using QDox, however this requires you to have the source available. At runtime this isn't always possible, unless you're happy giving your source away.

A workaround to this is to use QDox to parse the source code at development time and serialize the resulting structures to make them available at runtime. This will work, but it's a bit nasty as big binary files aren't the most stable of things.

A more open approach is to bundle the source of your classes with the application, making them available at runtime, however without the method body implementations.

Class with method body implementations:

package stuff;

public class CheeseSlicer {

  /** @transaction mode=isolated */
  public Slice feedMe() {
    // some implementation specific stuff here.. don't waste your time reading it.
    if (System.currentTimeMillisMillis() % 2 == 0) {
      return new CheddarSlice();
    } else {
      return new BrieSlice();
    }
  }

}

Class WITHOUT method body implementations:

package stuff;

public class CheeseSlicer {

  /** @transaction mode=isolated */
  public Slice feedMe();

}

To do this is simple. First, QDox can be used to parse the source of a class into a JavaClass. Calling JavaClass.toString() will print out the class without the body implementations (as above). This is something done at development time and the result should be written to a file that is available at runtime.

At runtime, QDox can read this file just as if it were a full-blown Java source file, making the attributes available.

JDK 1.5, of course, makes this redundant, but in the mean time...

Read: A simple way to access JavaDoc attributes at runtime

Topic: Still Whistling Previous Topic   Next Topic Topic: RubyCocoa TestRunner on RubyForge

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use