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/">
   <doc>{doc}</doc>
   <poNumber>{poNumber}</poNumber>
   <supplier>{supplier}</supplier>
</requestShipment>

Listing 2: Acme purchase order

<PurchaseOrder num='123' supplier='444'>
	<PO_Hdr time='10:34:00'>
		<customerID>JONES</customerID>
		<address>123 AnyStreet</address>
		<city>New York</city>
		<state>NY</state>
		<ZIP>10036</ZIP>
		<country>USA</country>
	</PO_Hdr>
	<Line_Items>
		<Item>
			<itemNumber>4183</itemNumber>
			<quantity>44</quantity>
			<unitPrice>12.34</unitPrice>
		</Item>
	</Line_Items>
</PurchaseOrder>

Listing 3: BigRetail purchase order

<PURCHASE_ORDER>
	<SUPP_ID>38203928</SUPP_ID>
	<IDENTIFIER>765_832</IDENTIFIER>
	<DATE_TIME>MARCH 23 2002 10:12:28</DATE_TIME>
	<SUB_TOT>190.47</SUB_TOT>
	<SHIP_INFO>
		<SHIP_ADDR1>653 Frontier Blvd.</SHIP_ADDR1>
		<SHIP_CITY>New York</SHIP_CITY>
		<SHIP_STATE>NY</SHIP_STATE>
		<SHIP_CODE>10036</SHIP_CODE>
		<SHIP_COUNTRY>USA</SHIP_COUNTRY>
	</SHIP_INFO>
	<LINE_COUNT>1</LINE_COUNT>
	<ITEM_DETAIL>
		<LINE_ITEM>
			<LINE_NO>1</LINE_NO>
			<ITEM_NAME>Fetzer Valve</ITEM_NAME>
			<ITEM_NO>3829</ITEM_NO>
			<QUANTITY>3</QUANTITY>
			<MEASURE>EACH</MEASURE>
			<COST>63.49</COST>
			<TOTAL>190.47</TOTAL>
		</LINE_ITEM>
	</ITEM_DETAIL>
	<NOTES>
		CONTACT PHIL UPON ARRIVAL
	</NOTES>
</PURCHASE_ORDER>

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 );
	serial.asDOMSerializer();
	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";
                break;
            case 2:
                transformXSLT = "bigRetail.xsl";
                break;
            default:
                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">
	<PO>
	<xsl:for-each select="PO_Hdr">
	<POHeader>
	<PONumber>
		<xsl:value-of select="../@num"/>
		</PONumber>
		<timestamp>
		<xsl:value-of select="@time"/>
		</timestamp>
		<supplierID>
		<xsl:value-of select="../@supplier"/>
	</supplierID>
	<xsl:for-each select="customerID">
	<customerID>
	<xsl:value-of select="."/>
	</customerID>
		</xsl:for-each>
		<xsl:for-each select="address">
		<shipToLine1>
		<xsl:value-of select="."/>
		</shipToLine1>
		</xsl:for-each>
		<xsl:for-each select="city">
		<shipToCity>
		<xsl:value-of select="."/>
			</shipToCity>
			</xsl:for-each>
		<xsl:for-each select="state">
			<shipToState>
			<xsl:value-of select="."/>
			</shipToState>
			</xsl:for-each>
		<xsl:for-each select="ZIP">
		<shipToPostalCode>
		<xsl:value-of select="."/>
		</shipToPostalCode>
	</xsl:for-each>
	<xsl:for-each select="country">
	<shipToCountry>
		<xsl:value-of select="."/>
		</shipToCountry>
		</xsl:for-each>
		</POHeader>
	</xsl:for-each>
	<xsl:for-each select="Line_Items">
	<ArrayOfPOLine>
	<xsl:for-each select="Item">
	<POLine>
	<xsl:for-each select="itemNumber">
	<lineNumber>
	<xsl:value-of select="."/>
		</lineNumber>
		</xsl:for-each>
		<xsl:for-each select="quantity">
		<quantity>
		<xsl:value-of select="."/>
		</quantity>
		</xsl:for-each>
		<xsl:for-each select="unitPrice">
		<unitPrice>
		<xsl:value-of select="."/>
		</unitPrice>
		</xsl:for-each>
		</POLine>
		</xsl:for-each>
		</ArrayOfPOLine>
		</xsl:for-each>
		</PO>
		</xsl:for-each>
	</xsl:template>
</xsl:stylesheet>

 
 

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.