Extraction information from the JHeadstart Application Definition file using xslt and a wiki

0

One of the challenges of developing (J2EE) applications is information. It’s very hard to have an overview of the different components, objects, database tables etc. and how they interact. This can make refactoring a difficult task. With ADF BC applications it can be quite difficult to track where and how the ViewObjects are being used in the faces application, especially because they are used via their instance or usage as defined in the application module. The ADF binding framework can make it even more complicated, because it abstracts the underlying business components. So, changing a viewobject, or just adding an extra attribute, is always a tricky business. You’re therefore easily fooled in making a new viewobject instead of re-using an existing one. Which can lead to an abundance of similar viewobjects that nobody actually knows why they are there for and that nobody dares to touch anymore, especially when the original developers have been gone. By the way, this is quite similar to the ‘old EJB era’ when using value or data objects.

Off course, an important part of the solution is documentation. But this requires a good documentation system, discipline and continuous re-documentation. But if you are using JHeadstart for your application generation, you can consider yourself lucky (which you probably already did), because the application definition contains a wealth of information. JHeadstart uses it to generate the ADF Faces application, but we can also use it for documentation purposes.

JHeadstart stores all it’s information in the application definition file and provides an editor to define the application. But neither the editor nor the application definition file is directly suited for documentation purposes. However, since it is in XML format, it provides easy access to all the information and with the use of an XML stylesheet (xslt) we can extract the data and present it in a suitable way. The only drawback is that you have to run the transformation process to get the documentation. This could be a part of the continuous integration process, but other options are available as well. At AMIS we use the confluence WIKI for documentation purposes and that provides us with a very good solution since it contains a built-in xslt parser. It can use the application definition file and the xslt directly from subversion to generate the output right into the wiki :-) and we can define as many transformations as we like, thus producing different reports.

....
So if we’d like to have an overview of all the viewobjects and their usages in an HTML table you only need the following xslt :

<span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br />&lt;xsl:stylesheet version=&quot;2.0&quot; <br />&nbsp;xmlns:xsl=&quot;<a href="http://www.w3.org/1999/XSL/Transform">http://www.w3.org/1999/XSL/Transform</a>&quot; <br />&nbsp;xmlns:fn=&quot;<a href="http://www.w3.org/2005/xpath-functions">http://www.w3.org/2005/xpath-functions</a>&quot; <br />&nbsp;xmlns:jaxb=&quot;<a href="http://java.sun.com/xml/ns/jaxb">http://java.sun.com/xml/ns/jaxb</a>&quot; <br />&nbsp;xmlns:jhs=&quot;<a href="http://www.oracle.com/jheadstart/applicationStructure">http://www.oracle.com/jheadstart/applicationStructure</a>&quot; <br />&nbsp;xmlns:xdt=&quot;<a href="http://www.w3.org/2005/xpath-datatypes">http://www.w3.org/2005/xpath-datatypes</a>&quot; <br />&nbsp;xmlns:xjc=&quot;<a href="http://java.sun.com/xml/ns/jaxb/xjc">http://java.sun.com/xml/ns/jaxb/xjc</a>&quot; <br />&nbsp;xmlns:xs=&quot;<a href="http://www.w3.org/2001/XMLSchema">http://www.w3.org/2001/XMLSchema</a>&quot; <br />&nbsp;xmlns:xsd=&quot;<a href="http://www.w3.org/2001/XMLSchema">http://www.w3.org/2001/XMLSchema</a>&quot;&gt;<br />&nbsp; &lt;xsl:output version=&quot;1.0&quot; method=&quot;html&quot; encoding=&quot;UTF-8&quot;/&gt;<br />&nbsp; &lt;xsl:template match=&quot;/&quot;&gt;<br />&nbsp;&nbsp;&nbsp; &lt;html&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;head&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;title&gt;Viewobjects that are used by the &lt;xsl:value-of select=&quot;/jhs:Service/@name&quot;/&gt;&lt;/title&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/head&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;body&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;h1&gt;Viewobjects that are used by the &lt;xsl:value-of select=&quot;/jhs:Service/@name&quot;/&gt;&lt;/h1&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;table border=&quot;1&quot;&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;thead&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;tr&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;th&gt;Group&lt;/th&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;th&gt;DataCollection&lt;/th&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;th&gt;DataCollectionImpl&lt;/th&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;th&gt;TreeDataCollection&lt;/th&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;th&gt;TreeDataCollectionImpl&lt;/th&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/tr&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/thead&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;tbody&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsl:for-each select=&quot;//jhs:Group&quot;&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsl:apply-templates select=&quot;jhs:Group&quot;/&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/xsl:for-each&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/tbody&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/table&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/body&gt;<br />&nbsp;&nbsp;&nbsp; &lt;/html&gt;<br />&nbsp; &lt;/xsl:template&gt;<br />&nbsp; <br />&nbsp; &lt;xsl:template match=&quot;jhs:Group&quot;&gt;<br />&nbsp;&nbsp;&nbsp; &lt;tr&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td&gt;&lt;xsl:value-of select=&quot;@name&quot;/&gt;&lt;/td&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td&gt;&lt;xsl:value-of select=&quot;@dataCollection&quot;/&gt;&lt;/td&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td&gt;&lt;xsl:value-of select=&quot;@dataCollectionImpl&quot;/&gt;&lt;/td&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td&gt;&lt;xsl:value-of select=&quot;@treeDataCollection&quot;/&gt;&lt;/td&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td&gt;&lt;xsl:value-of select=&quot;@treeDataCollectionImpl&quot;/&gt;&lt;/td&gt;<br />&nbsp;&nbsp;&nbsp; &lt;/tr&gt;<br />&nbsp; &lt;/xsl:template&gt;<br />&lt;/xsl:stylesheet&gt;</span>

Beware of the fact that the application definition file has a namespace attached to it (at the Service element) and that you therefore have to include that namespace in your xslt file, as you can see by the definition and the use of the jhs prefix.

Another nice piece of information is for which groups the pagedef generation has been disabled :

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:fn="http://www.w3.org/2005/xpath-functions"
 xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
 xmlns:jhs="http://www.oracle.com/jheadstart/applicationStructure"
 xmlns:xdt="http://www.w3.org/2005/xpath-datatypes"
 xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
 xmlns:xs="http://www.w3.org/2001/XMLSchema"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsl:output method="html" version="1.0" encoding="UTF-8" />
    <xsl:template match="/">
    <html>
      <head>
        <title>About generation of the pagedefinitions</title>
      </head>
      <body>
        <h1>NO generation of pagedefinition?</h1>
        <xsl:for-each select="//jhs:Group">
          <xsl:call-template name="pagedefgeneration"/>
        </xsl:for-each>
      </body>
    </html>
  </xsl:template>
  <xsl:template name="pagedefgeneration">
    <input type="checkbox" >
      <xsl:if test="@generateBindings=’false’">
        <xsl:attribute name="checked">1</xsl:attribute>
      </xsl:if>
      <xsl:value-of select="@name"/>
    </input>
    <br/>
  </xsl:template>
</xsl:stylesheet>

 

Off course the options are endless: the list of the user-defined templates, insert/update/delete mode of a group, items that are updatable or disabled, all the labels or hints etc. etc, probably only limited by your xslt knowledgde. And you know what… all of the faces configuration files, the web.xml and all of the Business Components and the application modules are XML files too and even the jsf pages :-).

Take care, this is a bit trickier, because the generateBindings attribute can have the value ‘false’, ‘true’ or be totally absent, in which case the JHeadstart application generator (jag) uses its default value ‘true’.

Share.

About Author

Aino Andriessen is a consultant on Enterprise Java, ADF, PL/SQL, XML, and SOA development and is Expertise Lead on Application Lifecycle Management (ALM). He has a strong interest in ADF, SOA, Maven, architecture, quality management, delivery and application lifecycle management. Aino publishes on the AMIS technology blog and has been a presenter at the ODTUG Kaleidoscope, Oracle Open World and UKOUG TechEbs.

Comments are closed.