r14 - 13 Feb 2008 - 22:06:34 - DovKatzYou are here: TWiki >  SpringThings Web > WebHome

Spring Bean Catalog Generator and Viewer

View Demo

  • View the bean catalog »

    Purpose

    During the javadoc generation of my APIs, in particular those which are spring-based, it became increasingly difficult to identify the configuration otpions available in the product. Using java reflection, and some standard naming conventions, I sought to produce spring-like configuration xml which could hopefully serve as a quick reference user guide for configuring the app. Maybe this already exists, and I hope it does, but for now, this tactical solution solves my problem, enough so, that it's worth sharing. I wrapped it up into an Ant Task as well so I can automate the generation of these files in a build process....

    How it Works

    When used as an Ant Task, the provided classpath list is initialized inside a classloader, and the provided JAR's classes are programmatically loaded and introspected. Optionally, a package filter can reduce the number of classes being loaded. For each class where setters are detected the class is prepared as a "bean" for display in the output file.

    When all beans have been prepared, the resulting XML is spit out at the provided destination. When not run as an Ant Task, the process's classpath is used as the classpath for the special jar classloader.

    Sample Output

    <bean class="foo.soap.template.DynamicElementTemplate" extends="foo.soap.template.Template" >
             <property name="namespace" type="java.lang.String"/>
             <property name="action" type="java.lang.String"/>
             <possible-constructors>
                <void-constructor visibility="public"/>
                <constructor visibility="public">
                   <constructor-arg index="0" type="java.lang.String"/>
                   <constructor-arg index="1" type="java.lang.String"/>
                </constructor>
             </possible-constructors>
    </bean>
    

    Now for the fun part: The Viewer

    Since I I created a bunch of these XML files for various library JAR's, it then made sense to make a common viewer of them, so I created a "Table of Contents" for all of the files I created. (The file / xml payload can be viewed at BeanCatalogList?skin=xml, and files can be displayed there as well....)

    <?xml version="1.0" ?>
    <catalogs>
       <catalog group="Spring" icon="spring" name="jdbc" file="path/spring_jdbc.xml" />
       <catalog group="Spring" icon="spring" name="web" file="path/spring_web.xml" />
       <catalog group="Spring" icon="spring" name="validation" file="path/spring_validation.xml" />
       <catalog group="Spring" icon="spring" name="context" file="path/spring_context.xml" />
       <catalog group="Spring" icon="spring" name="jmx" file="path/spring_jmx.xml" />
       <catalog group="Spring" icon="spring" name="mail" file="path/spring_mail.xml" />
       <catalog group="Spring" icon="spring" name="core" file="path/spring_core.xml" />
    </catalogs>
    

    Using the above file as a guide, I created a EXT.js based GUI to navigate the "Beans", and dynamically load files for the toc or the catalog from the URL

    Source Code

    Download the source code (as an eclipse IDE project) below:

  • Topic attachments
    I Attachment Action Size Date Who Comment
    zipzip oss_bean_cataloger.zip manage 8.8 K 13 Feb 2008 - 16:17 DovKatz The Eclipse project, and source code

    Edit | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r14 < r13 < r12 < r11 < r10 | More topic actions
     
    Powered by TWiki
    This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
    Ideas, requests, problems regarding TWiki? Send feedback