Leverage legacy systems
with a blend of XML, XSL, and Java - JavaWorld October 2000
Tutorial Details:
Leverage legacy systems with a blend of XML, XSL, and Java
Leverage legacy systems with a blend of XML, XSL, and Java
By: By Michael Koch
Combine XML, XSL, and Java to interface with mainframe systems
o matter which way you try it, interfacing a mainframe from an application server or servlet is never fun. Among other hurdles to overcome, the mainframe could exist on a different platform or use a different character set. Think you can simply access the data directly and rebuild your business logic? Perhaps, if your database is not hierarchical and you enjoy reinventing the wheel. However, a few tricks using XML, XSL, and Java can make it easier than you think.
XML describes the structure of the data you are sending. Add XSL to complete some simple transformations. Use Java to encapsulate it with a few simple classes. You will then leverage a host of legacy system transactions written decades ago and format them into an XML document. Once your data is in an XML format, manipulating it becomes a much less daunting task, and development becomes easier. In addition, the solution you employ is realtime, which circumvents the frustrations and problems that arise from working with an extract file or batch interface.
Note: the complete source code for this article can be downloaded as a zip file from Resources .
The versatile XML
While many may only think of XML in terms of marking up structured documents, you can use XML to describe anything that has a particular structure. For the purposes of this article, we shall assume that our legacy system stores data in a hierarchical database that may be accessed through COBOL programs residing on the system. Why not access the database directly to retrieve the information? While the hierarchical database offers some advantages for the mainframe system, directly accessing it requires extensive knowledge of the database. Usually, the underlying database features significant complexity, which makes traversing it exceedingly difficult, if not downright impossible. Since the COBOL programs are already available for that purpose, there remains no reason to undertake such a complicated task.
You must know the structure of the transaction you will interface in order to invoke the COBOL program. To obtain that knowledge, refer to the program copybook, which contains the directions for use. Those directions include information about the length of the field, name, left or right justification, etc. Think of those descriptors as a set of fields that are described by attributes. Those descriptors provide directions on how to format the request and how to parse the returning data from the subsequent call.
Using XML, you can now implement that copybook metadata to generate your copybook markup language. Below, this short, simplistic example of an XML document containing our COBOL program's metadata retrieves a name when given a social security number:
CobolNameProgram
30
200
The name describes the name of the COBOL program you invoke, and the lengths of the corresponding request and reply messages. The attributes of each field you will encounter describe the name, field length, justification, or any item you need to know to process this request.
The Java engine
Referencing the structure above, you can write the code to hook up your values into your request's structure and parse the incoming reply with another document containing the name/value pairs that correspond to the field identifiers. That sample incoming document may look like this after some initial processing:
To format the request, the code simply needs to search for and match the identifier for each element, and write the value according to the attributes' rules by iterating through the fields.
XSL style
Developers use the XSL language for manipulating XML from one structure into another. It can be implemented for transforming XML into HTML or other XML document structures (for more information on how to manipulate XML documents with XSL, see Resources ).
You will use XSL to format an incoming document structure to the name/value-pair structure described above, which the Java code processes into the COBOL structure. XSL will also format the data returned from the legacy system -- once the Java code transforms it back into XML -- into a usable structure for the function or application using this API. XSL allows you to build Java code that will be insulated from changes to the external format of both the calling application and the legacy system. I will describe more on that advantage later.
The Xerces parser allows for easy XML manipulation within Java (for more information regarding the Xerces parser, see Resources ). Assume that an application using your API will pass the data your request needs as an XML document. It will feature whatever structure that the application requires. We need not concern ourselves with it since our application can apply XSL to style the structure into our usable name/value-pair configuration described above. That resulting name/value-pair structure can then be passed to the Java code for manipulation into the COBOL structure.
After you obtain the name/values pairs containing the data necessary for the request, and the metadata describing the structure of the COBOL transaction, you can write the Java code that manipulates the request:
package JavaWorldExample;
import org.apache.xerces.parsers.*;
import org.xml.sax.*;
import java.io.*;
import org.w3c.dom.*;
import com.lotus.xsl.*;
public class TransformMessage {
public TransformMessage() {
}
byte [] formatMessage(Document doc) {
int txFieldLength = 0;
byte [] txFieldLengthBytes;
int txFieldIndex = 0;
byte [] txField;
StringBuffer txInputBuffer = new StringBuffer();
String value = "";
String szLen = "";
try {
// Apply XSL to document to style into name/value format
StringWriter writer = new StringWriter();
XSLProcessor processor = new XSLProcessor();
processor.reset();
processor.process( new XSLTInputSource(doc),
new XSLTInputSource(new FileReader("c://input//CommonFormat.xsl")),
new XSLTResultTarget(writer) );
String formattedxml = writer.toString();
//Get the element list and root node
DOMParser lparser = new DOMParser();
lparser.parse(new InputSource(new StringReader(writer.toString())));
doc = lparser.getDocument();
NodeList transNlist = doc.getElementsByTagName("GetName");
Element dataNode = (Element) transNlist.item(0);
// Get the transaction metadata
DOMParser parser = new DOMParser();
parser.parse(new InputSource(new FileReader("c://input//Samplemetadata.xml")));
Document metadoc = parser.getDocument();
// Apply the metadata and rules to the message
NodeList nlist = metadoc.getElementsByTagName("FIELD");
for (int i = 0; i < nlist.getLength(); i++) {
txFieldIndex = 0;
//get the field length from the meta data
if ( nlist.item(i).getAttributes().getNamedItem("LTH") == null)
szLen="0";
else
szLen = nlist.item(i).getAttributes().getNamedItem("LTH").getNodeValue().trim();
//calculate the length of current field
txFieldLength = Integer.parseInt(szLen);
//create transaction-field byte array
txField = new byte [txFieldLength];
// find the field in the application XML Document & get the attributes
NodeList dataNlist = dataNode.getElementsByTagName(nlist.item(i).getAttributes().getNamedItem("NAME").getNodeValue().trim());
if (dataNlist.getLength() > 0) {
value = new String (dataNlist.item(0).getAttributes().getNamedItem("VALUE").getNodeValue().trim());
}
//add the actual value of field
txFieldIndex = CommonUtilities.buildRI(txField, value.getBytes(), txFieldIndex, value.length());
//Determine the justification of the field
if ( nlist.item(i).getAttributes().getNamedItem("JUST").getNodeValue().equals("L")) {
//Left Justify
for(int k=0; k < (txFieldLength-txFieldIndex); k++) {
txField[k+txFieldIndex]=(byte)(' ');
}
}
else { //Right Justify
CommonUtilities.rightJustify(txField);
}
//add field to input buffer
txInputBuffer.append(new String(txField));
}// end for all fields
}
catch (Exception e) {
e.printStackTrace();
}
return txInputBuffer.toString().getBytes();
} // End function
} //End class TransformMessage
I've described all that you need to accomplish to set up your outgoing structure. To format the return, a like strategy is utilized. Data manipulation transforms the response from a byte array or similar structure into an XML document. Essentially, the code matches the fields with the value from the array and creates name/value pairs that are suitable for a simplistic XML document. Once that is complete, XSL styles the information in any way desired. It is also important that you set up some sort of transmission method to the environment in which you execute the COBOL program. As the focus of this article is the server-side application, I do not delve into that discussion here.
Framework advantages
It may be helpful at this point to provide an illustration of the process as it has evolved to this point.
Figure 1. Legacy transaction framework
While it may not be readily apparent, this layout offers several distinct advantages:
Since XSL is applied to the incoming document as well as the outgoing document, the Java engine, once written, is insulated from changes in the incoming message structure. The entire DTD, or schema, of the incoming message could be changed completely. A programmer would only have to modify the XSL within this framework that
Read
Tutorial at: Click here to view the tutorial
Rate Tutorial: Leverage legacy systems
with a blend of XML, XSL, and Java - JavaWorld October 2000
View Tutorial: Leverage legacy systems
with a blend of XML, XSL, and Java - JavaWorld October 2000
Related
Tutorials:
|
Displaying 1 - 50 of about 3170 Related Tutorials.
|
Transforming an XML File with XSL
to transform an XML File with XSL in a DOM document. JAXP (Java
API for XML...
XML,XML Tutorials,Online XML Tutorial,XML Help Tutorials
Transforming an XML File with XSL
  |
Introduction to XSL
(W3C) started to develop XSL because there was a need for an XML-based Stylesheet... to access or refer specific parts of an XML document
XSLT: XSL Transformations...://www.w3.org/1999/XSL/Transform">
Since an XSL style sheet is an XML |
XML Books
;
Processing XML with Java
Welcome to Processing XML with Java, a complete tutorial about writing Java programs that read and write XML... how to write XML documents, validate them with DTDs, design CSS and XSL style |
Parasoft Jtest
;
Parasoft Jtest is a comprehensive Java testing product
for development teams building Java EE, SOA, Web, and other Java applications.
Whether a team is trying to build quality into new code or extend a legacy code
base without |
XML: An Introduction
standard, XSL
(an advance feature of XML), lets you dictate over...
XML
XML: An Introduction
 ... is XML?
"XML is a cross-platform, software and
hardware independent tool |
XML Tutorials
shift a beginner to XML-Java programming. In these tutorials we have
developed example programs using Java XML processing APIs. Tutorial starts.... Here we are providing many examples to help you master using XML
with Java |
XML Tutorials
shift a beginner to XML-Java programming. In these tutorials we have
developed example programs using Java XML processing APIs. Tutorial starts.... Here we are providing many examples to help you master using XML
with Java |
Create a Java program using XSLT APIs
both XML and XSL file as an input and transforms them to generate a formatted...] is for XML file, arg[1] is for XSL file, and arg[2] is for taking the name...
Create a Java program using XSLT APIs
Create a Java |
Transforming XML with XSLT
shows you how to Transform XML with the XSLT in a DOM document. JAXP (Java
API...
Transforming XML with XSLT, XML,XML Tutorials,Online XML Tutorial,XML Help Tutorials
Transforming XML with XSLT
  |
Open Source XML Editor
Open Source XML Editor
Open Source XML Editor
Open
source Extensible XML Editor
The Xerlin Project is a Java? based XML... for XQL, XSL, Xlink, and
Xpointer. An in-depth look at making XML work |
XML Interviews Question page10
XSL and CSS where they can be added to generated HTML. XML itself provides... Java to create or manage XML files? Yes, any programming language can be used... is muddied by XSL (both XSLT and XSL:FO) which use XML syntax to implement |
JFreeChart - An Introduction
java chart library.
David Gilbert founded the JFreeChart project in February 2000... layout managers
serialization utilities
a date chooser panel
XML parser |
XML Interviews Question page9
to convert XML math markup to LATEX for print (PDF) rendering, or to use XSL:FO...?
A: The linking abilities of XML systems are potentially much more powerful than...
XML Interviews Question page9,xml Interviews Guide,xml Interviews |
Eclipse Plunging/XML
;
XMLEspresso
Built in catalog for creating XML Schema, WSDL, XSL, Java EE...
development environment providing many great enhancements for XSL/XML
editing...
Eclipse Plunging/XML
Eclipse Plunging/XML |
XML Transformation in JSP
where the XML data is coming. Likewise xsltUrl also
specifies XSL file URL from... is shown into
XML-XSL Transform JSP page by transforming and checking the data...;/xsl:transform>
3. XML-XSL Transform
<%@ taglib uri="http |
Eclipse Plunging/Systems Development
Eclipse Plunging/Systems Development
Eclipse Plunging/Systems Development
 ...
jACOB is a Java based rapid application development tool (RAD) with a run |
XML Related Technologies: An overview
) - XSL consists of three parts: XSLT -
a language for transforming XML documents, XPath - a language for navigating in
XML documents, and XSL-FO - a language for formatting XML documents.
XSLT
(XSL Transformations) is used to transform XML |
Java get XML File
Java get XML File
Java get XML File...;
In this section, you will study how the java application read the XML file.
For this, you need to create a XML file.
Here is the employee.xml file |
XML Interviews Question page3
the appropriate XML element, xsl:value-of to select the attribute value....
Extract Attributes from XML Data
Example 1.
<xsl:template match="element...
XML Interviews Question page1,xml Interviews Guide,xml Interviews |
Xcarecrows 4 XML
comparator ;
a built-in checker against XML Schemas ;
an XSL transformations tool... of the XSL stylesheets
themselves, thus empowering the user with a coherent XML...
Xcarecrows 4 XML
Xcarecrows 4 XML |
Java XML Books
Java XML Books
Java XML Books
 ...;
Java
and XML Books
One night five...;
Java and XML, Second Edition
While the XML "buzz" still |
Open Source Agent Systems written in Java
|
An Overview of the XML-APIs
.
JAXP: Java API for XML Processing
This API provides a common interface...
Java objects as XML (marshalling) and for creating Java objects
from... XML-based data.
JAXM: Java API for XML Messaging
The JAXM API |
oXygen XML Editor
oXygen XML Editor
oXygen XML Editor...;
The simple and elegant look of the <oXygen/>
XML Editor combined with the complete coverage of the XML editing features have
made it popular |
Testing EntityReferences in Xml
;
This Example gives you the way to test EntityReferences in an XML file. JAXP (Java...
Testing EntityReferences in Xml,XML,XML Tutorials,Online XML Tutorial,XML Help Tutorials
Testing EntityReferences in Xml |
Transforming XML with SAXFilters
;
This Example shows you how to Transform XML with
SAXFilters. JAXP (Java API...
Transforming XML with SAXFilters, XML,XML Tutorials,Online XML Tutorial,XML Help Tutorials
Transforming XML with SAXFilters |
XML Well-Formed Verifier
Java XML Parsing,Java XML Parser Sax,Sax Parser Example in Java,Well Formed... a java file (SAXParserCheck.java)
that uses a xml file to parse and check... SAXParserCheck.java
C:\vinod\xml\comXML>java SAXParserCheck
Enter |
Get XML Elements
Java XML Parsing,Java XML Parser Sax,Get XML Element,XML Elements
Get XML Elements
 ...\xml\comXML>java XMLElements Employee-Detail.xml
XML Elements |
XPath Explorer
;
XPath is a syntax for navigating inside XML documents,
in order to extract specific little pieces of content. It's sort of like SQL for
XML. It may be better known as "the stuff inside the quotes in XSL,"
but it has a life |
Create - XML File (Document)
Java Create XML File,Java Create XML Document,Create XML Java,Create XML Files
Create - XML File (Document)
 ...\xml>java CreatXMLFile
Enter number to add elements in your XML file: 3 |
Storing properties in XML file
;
This Example shows you how Store properties in a new
XML File. JAXP (Java API...
Storing properties in XML file,XML,XML Tutorials,Online XML Tutorial,XML Help Tutorials
Storing properties in XML file
  |
Open Source Screen Scraping Tools written in Java
|
Remove Element from XML Document
:
C:\vinod\xml>javac RemoveElement.java
C:\vinod\xml>java...
Remove Element DOM,Remove Element from DOM,Delete Element,Delete XML Node
Remove Element from XML Document
  |
Query XML with an XPath expression
(Java API for XML Processing) is an interface which provides
parsing of xml...
Query XML with an XPath expression, XML,XML Tutorials,Online XML Tutorial,XML Help Tutorials
Query XML with an XPath expression |
Vehicle Tracking Systems - Overview
Vehicle Tracking Systems,Tracking Vehicles,Tracking Systems
Vehicle Tracking Systems - Overview
 ...
Vehicle tracking systems are devices used for tracking location of vehicles in real |
Getting The XML Root Element
Java XML Example,XML Root Node,Java XML Node,Java XML Parser...; The JAXP (Java APIs for XML
Processing) provides a common interface for creating...
document (file). Both Java and the XML file are kept in the same directory |
Convert Object To XML
Convert Object To XML
Convert Object To XML...
into xml file with the help of an example. We are taking ten strings from console... into xml file as child node values. Convert Object To XMLTo create a xml file |
XML Well-Formed-ness
XML Well Formedness,XML Well Formed,XML Well Formed Checker,Java XML DOM Parser,Java XML DOM Parser Example,Java XML DOM Example... DOMParserCheck.java
C:\vinod\xml>java DOMParserCheck
Enter File |
Database books Page20
;
Introduction of Oracle XML
Cheatsheet
Oracle posesses a variety of powerful XML features. A tremendous amount of documentation exists regarding Oracle's XML features. This resource is intended to be a cheatsheet for those |
Java Releases
Year
Java 1.5.0_09
October
2006
Java 1.5.0_08... 1.5.0_05
October
2005
Java 1_5_0_04
July
2005...,
Standard Edition 1.3 (J2SE 1.3)
May
2000
Java 2 Platform |
Retrieving Data From the XML file
is only geared towards showing how to construct a Java object
from an XML document...
Retrieving Data From the XML file
Retrieving Data From the XML file
  |
To Count The Elements in a XML File
XML Count Elements,Java XML Node,Java XML Nodelist,XML Examples,XML Example
To Count The Elements in a XML File
 ...\xml>javac CountNodes.java
C:\vinod\xml>java CountNodes
Enter |
To Count XML Element
XML Count Elements,Java XML Node,Java XML Nodelist
To Count XML Element
 ... DOMCountElement.java
C:\vinod\xml>java DOMCountElement
Enter |
XML Error Checking and Locating
:\vinod\xml>javac LocateError.java
C:\vinod\xml>java LocateError...
XML Error Checking,XML Error Codes
XML Error... and locate
an error in the XML document and error position.
Description |
Use of tag of JSTL
" />
<x:transform xml="${xml}" xslt="${xsl}" />... will learn how to use <x:parse>
tag of Xml tag library of Jstl. This tag is used to transform the specified
xml document. With the use of this tag we can |
Oracle Books
;
Building Oracle XML Applications
This rich and detailed look at the many Oracle tools that support XML development shows Java and PL/SQL developers how to combine the power of XML and XSLT with the speed |
Getting all XML Elements
Java XML Example,Java XML Element,XML Elements,Get XML Element
Getting all XML Elements
 ...\xml>javac DOMElements.java
C:\vinod\xml>java DOMElements |
Windows Web Hosting
on
the Microsoft Windows Operating Systems. IIS server is used to serve the web pages...%
uptime. Windows Web Hosting are mostly provided on Winodws NT, Winodws 2000
&...
MS FrontPage 2000,
2002 support
Yes
Yes
Flash |
Loading properties from a XML file
to Load properties from a
XML file. JAXP (Java API for XML Processing...
XML,XML Tutorials,Online XML Tutorial,XML Help Tutorials
Loading properties from a XML file
  |
Adding DOCTYPE to a XML File
Java XML DocType,XML DocType,XML DocType Public System,XML DocType Public,XML DocType System
Adding DOCTYPE to a XML File...
C:\vinod\xml>java AddDocType
Enter XML file name: Employee |
|
|
|