Recommended: Sing it, brah! 5 fabulous songs for developers
JW's Top 5
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 7 of 7
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:param name="securityrole">Guest</xsl:param> <xsl:param name="usercurrent"></xsl:param> <xsl:template match="/"> <xsl:choose> <xsl:when test="$usercurrent='start'"> /jsp/application/demographics.jsp </xsl:when> <xsl:when test="$usercurrent='demographics'"> /jsp/application/felonies.jsp </xsl:when> <xsl:when test="$usercurrent='felonies'"> /jsp/application/workhistory.jsp </xsl:when> <xsl:when test="$usercurrent='workhistory'"> /jsp/application/legal.jsp </xsl:when> <xsl:when test="$usercurrent='legal'"> /jsp/application/summary.jsp </xsl:when> <xsl:when test="$usercurrent='summary'"> /complete.html </xsl:when> <xsl:when test="$usercurrent='complete'"> /index.html </xsl:when> <xsl:otherwise>/jsp/application/start.jsp</xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>
When the candidate completes each page, she easily moves to the next page, until, when finished, she submits her application.
Now, imagine that you've delivered the application to the company. Let's say that the HR department desires two changes:
To incorporate those new requirements into the workflow, the new XSL code below checks to see if the candidate possesses any prior felony convictions. It also switches the screen to which the legal and summary pages go:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="securityrole">Guest</xsl:param>
<xsl:param name="usercurrent"></xsl:param>
<xsl:template match="/">
<xsl:choose>
<xsl:when test="$usercurrent='start'">
/jsp/application/demographics.jsp
</xsl:when>
<xsl:when test="$usercurrent='demographics'">
/jsp/application/felonies.jsp
</xsl:when>
<xsl:when test="$usercurrent='felonies'">
<xsl:choose>
<xsl:when test="/application[felonies]">
/jsp/application/summary.jsp
</xsl:when>
<xsl:otherwise>
/jsp/application/workhistory.jsp
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$usercurrent='workhistory'">
/jsp/application/legal.jsp
</xsl:when>
<xsl:when test="$usercurrent='legal'">
/complete.html
</xsl:when>
<xsl:when test="$usercurrent='summary'">
/jsp/application/legal.jsp
</xsl:when>
<xsl:when test="$usercurrent='complete'">
/index.html
</xsl:when>
<xsl:otherwise>/jsp/application/start.jsp</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
The scenario presented above is a simple one, but it includes common problems developers face everyday.
Workflow not only proves difficult to implement; it also is commonly changed. To mitigate such challenges, the simple API presented here encapsulates workflow in a set of objects. Moreover, it represents workflow as XSL so any object represented as XML can be employed.
As good as the API is, it doesn't address such other workflow issues as data validation or error handling. Further, as a stateless API, it requires information about the candidate's location before it determines where to go. A stateful implementation would prove advantageous because the candidate could see a history of her work, as well as an idea of how much remains to be completed. Moreover, the API does not persist the workflow state, so the candidate cannot easily return to her spot in the workflow.
Using XSL to encapsulate business rules provides a strong mechanism for managing workflow. Indeed, it provides a language-independent, extensible solution. As alternatives, you could encapsulate the workflow in a JavaBean or an XML document. However, a JavaBean requires recompilation, and XML doesn't provide such language-level constructs as sequential-, iterative-, or decision-based processing.
Business rules are written and rewritten. Users always want the greatest possible experience. Developers want manageability, modifiability, and extensibility. In order to meet these needs, it is important to build an API that addresses all the varying issues at once, and incorporates them into the design.
Read more about Enterprise Java in JavaWorld's Enterprise Java section.