HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML

"Building Transformational Web Services"
Vol. 7, Issue 7, p. 16


Listing 1: requestShipment method declaration

<requestShipment xmlns="http://openuri.org/">

Listing 2: Acme purchase order

<PurchaseOrder num='123' supplier='444'>
	<PO_Hdr time='10:34:00'>
		<address>123 AnyStreet</address>
		<city>New York</city>

Listing 3: BigRetail purchase order

	<DATE_TIME>MARCH 23 2002 10:12:28</DATE_TIME>
		<SHIP_ADDR1>653 Frontier Blvd.</SHIP_ADDR1>
			<ITEM_NAME>Fetzer Valve</ITEM_NAME>

Listing 4: requestShipment method definition

public void requestShipment( Node doc, String poNumber, int supplier ) throws Exception
     // Store the incoming PO
     OutputFormat    format  = new OutputFormat();
	StringWriter  stringOut = new StringWriter();  
	XMLSerializer    serial = new XMLSerializer( stringOut, format );
	NodeList childs = doc.getChildNodes();
        Element root = (Element) childs.item(1);
	serial.serialize( root );
	String filePath = "/incoming/" + poNumber.trim() + ".xml";
	XMLDatabase.createXMLFile( "Warehouse", filePath, stringOut.toString(), false );
	// Transform the PO into our internal format & store
     String transformXSLT = null;
	switch (supplier)
	{   case 1:
                transformXSLT = "acme.xsl";
            case 2:
                transformXSLT = "bigRetail.xsl";
                throw new Exception("Invalid supplier code " + supplier + " seen.");
     String transformedPO = XMLDatabase.applyTransform
	 ( "Warehouse", filePath, transformXSLT );
     XMLDatabase.createXMLFile( "Warehouse", "/toBeShipped/" 
	 + poNumber.trim() + ".xml", transformedPO, false );
     processOrder( poNumber );
     callback.shipNotice( poNumber );        

Listing 5: Acme purchase order XSLT generated by Stylus Studio

<?xml version="1.0" encoding="ucs-2"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" num="123" supplier="444">
	<xsl:template match="/">
		<xsl:for-each select="PurchaseOrder">
	<xsl:for-each select="PO_Hdr">
		<xsl:value-of select="../@num"/>
		<xsl:value-of select="@time"/>
		<xsl:value-of select="../@supplier"/>
	<xsl:for-each select="customerID">
	<xsl:value-of select="."/>
		<xsl:for-each select="address">
		<xsl:value-of select="."/>
		<xsl:for-each select="city">
		<xsl:value-of select="."/>
		<xsl:for-each select="state">
			<xsl:value-of select="."/>
		<xsl:for-each select="ZIP">
		<xsl:value-of select="."/>
	<xsl:for-each select="country">
		<xsl:value-of select="."/>
	<xsl:for-each select="Line_Items">
	<xsl:for-each select="Item">
	<xsl:for-each select="itemNumber">
	<xsl:value-of select="."/>
		<xsl:for-each select="quantity">
		<xsl:value-of select="."/>
		<xsl:for-each select="unitPrice">
		<xsl:value-of select="."/>


All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.