Design XML Schemas Using UML Ayesha Malik Design service-oriented architecture frameworks with J2EE technology Naveen Balani Advanced DAO Programming Sean Sullivan catalog2x.xml Adapted from the book Pro XML Development with Java Technology, by Ajay Vohra and Deepak Vohra, Apress, 2006"> Design XML Schemas Using UML Ayesha Malik Design service-oriented architecture frameworks with J2EE technology Naveen Balani Advanced DAO Programming Sean Sullivan catalog2x.xml Adapted from the book Pro XML Development with Java Technology, by Ajay Vohra and Deepak Vohra, Apress, 2006">

Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 157B: Database Management Systems II February 25 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron.

Similar presentations


Presentation on theme: "CS 157B: Database Management Systems II February 25 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron."— Presentation transcript:

1 CS 157B: Database Management Systems II February 25 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak www.cs.sjsu.edu/~mak

2 Department of Computer Science Spring 2013: February 25 CS 157B: Database Management Systems II © R. Mak 2 XSLT  XSL = Extensible Stylesheet Language T = Transformations  Transform an XML document to another form: another XML document HTML plain text  Uses XPath expressions.

3 Department of Computer Science Spring 2013: February 25 CS 157B: Database Management Systems II © R. Mak 3 XML Example <catalog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="catalog2.xsd"> Design XML Schemas Using UML Ayesha Malik Design service-oriented architecture frameworks with J2EE technology Naveen Balani Advanced DAO Programming Sean Sullivan catalog2x.xml Adapted from the book Pro XML Development with Java Technology, by Ajay Vohra and Deepak Vohra, Apress, 2006

4 Department of Computer Science Spring 2013: February 25 CS 157B: Database Management Systems II © R. Mak 4 XML Schema for the Example... catalog2.xsd

5 Department of Computer Science Spring 2013: February 25 CS 157B: Database Management Systems II © R. Mak 5 Revised XML Example <catalog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="catalog2.xsd"> Design XML Schemas Using UML Ayesha Malik Design service-oriented architecture frameworks with J2EE technology Naveen Balani Advanced DAO Programming Sean Sullivan Style sheet reference Adapted from the book Pro XML Development with Java Technology, by Ajay Vohra and Deepak Vohra, Apress, 2006

6 Department of Computer Science Spring 2013: February 25 CS 157B: Database Management Systems II © R. Mak 6 example-1.xsl catalog2.xsl Articles Article Author Make the root node the current node. HTML to output. Demo

7 Department of Computer Science Spring 2013: February 25 CS 157B: Database Management Systems II © R. Mak 7 example-2.xsl...... Articles... Each article node in turn becomes the current node. Here, the current node is the root node. After the for-each loop is done, the current node reverts to the root node. Demo

8 Department of Computer Science Spring 2013: February 25 CS 157B: Database Management Systems II © R. Mak 8 The Current Node  As the XSLT processor works through an XML document, the current node is the node it is processing. XPath expressions can be relative to the current node.  By default, the current node is the node matched by the current template.  While executing an xsl:for-each instruction, the current node changes during each iteration to the next node that matches the select attribute. Upon completion of the xsl:for-each instruction, the current node reverts to what it was before the instruction. _

9 Department of Computer Science Spring 2013: February 25 CS 157B: Database Management Systems II © R. Mak 9 example-3.xsl...... Articles... <xsl:sort select="title" order="ascending" data-type="text"/> Sort by title. Demo

10 Department of Computer Science Spring 2013: February 25 CS 157B: Database Management Systems II © R. Mak 10 example-4.xsl...... Dr. Mr. Ms.... Test the conditions in the given order until the first one evaluates to true. Demo

11 Department of Computer Science Spring 2013: February 25 CS 157B: Database Management Systems II © R. Mak 11 example-5.xsl......... Summary In journal, published by, includes: wrote the article " " dated Within an XSL document, all HTML code must be well-formed. Demo

12 Department of Computer Science Spring 2013: February 25 CS 157B: Database Management Systems II © R. Mak 12 example-6.xsl......... In journal, published by, includes article 1">s wrote the article " " dated No “else” part. Demo

13 Department of Computer Science Spring 2013: February 25 CS 157B: Database Management Systems II © R. Mak 13 example-7.xsl...... Dr. Mr. Ms. In this template, the default current node is an author node. An XSL template is like a procedure that you can “call”. The text content of the current node (i.e, the author’s name).

14 Department of Computer Science Spring 2013: February 25 CS 157B: Database Management Systems II © R. Mak 14 example-7.xsl...... Articles......... “Call” the template that matches the author node.

15 Department of Computer Science Spring 2013: February 25 CS 157B: Database Management Systems II © R. Mak 15 example-7.xsl......... In journal,... wrote the article " " dated... Demo

16 Department of Computer Science Spring 2013: February 25 CS 157B: Database Management Systems II © R. Mak 16 Web Services  A web service is “a software system designed to support interoperable machine-to-machine interaction over a network”. The service is provided by a server machine (the web service provider). Client applications make service requests to the server and get back responses. A popular form of distributed computing.  There are many public web services available. Examples:  http://www.service-repository.com/ http://www.service-repository.com/  http://www.webservicex.net/WS/WSDetails.aspx?CATID=2&WSID=9 http://www.webservicex.net/WS/WSDetails.aspx?CATID=2&WSID=9 You can write a web service client program in Java to connect to a web service and consume its data.

17 Department of Computer Science Spring 2013: February 25 CS 157B: Database Management Systems II © R. Mak 17 Web Services  A web service is described by a service contract written in the Web Services Description Language (WSDL). The WSDL document is an XML document. The WSDL document and the request and response messages are transmitted over HTTP. Messages use the Service Oriented Architecture Protocol (SOAP), an XML format.  Web services are programming language agnostic. The web service provider code can be written in any language. The web service requester (client) code can be written in any language. XML is the intermediary  WSDL document  SOAP messages

18 Department of Computer Science Spring 2013: February 25 CS 157B: Database Management Systems II © R. Mak 18 Web Service Example: Time Server  A simple web service provider written in Java. Provide the current time as a string. Provide the elapsed Unix time in milliseconds as a long. The required JAXB and JAX-WS packages are part of standard Java 6 and beyond. _

19 Department of Computer Science Spring 2013: February 25 CS 157B: Database Management Systems II © R. Mak 19 Time Server Provider  Time service interface: package wsdemo.timeservice; import javax.jws.soap.SOAPBinding; import javax.jws.soap.SOAPBinding.Style; import javax.jws.WebMethod; import javax.jws.WebService; @WebService @SOAPBinding(style = Style.RPC) public interface TimeServer { @WebMethod String getTimeAsString(); @WebMethod long getTimeAsElapsed(); } Service Endpoint Interface (SEI). How to construct the WSDL document Service operations Adopted from Java Web Services: Up and Running by Martin Kalin O’Reilly, 2009

20 Department of Computer Science Spring 2013: February 25 CS 157B: Database Management Systems II © R. Mak 20 Time Server Provider  Time service implementation: package wsdemo.timeservice; import java.util.Date; import javax.jws.WebService; @WebService(endpointInterface = "wsdemo.timeservice.TimeServer") public class TimeServerImpl implements TimeServer { public String getTimeAsString() { return String.format("The current server time is %s", new Date().toString()); } public long getTimeAsElapsed() { return new Date().getTime(); } Link this Service Implementation Bean (SIB) to the TimeServer SEI. Current time operation Elapsed time operation Adopted from Java Web Services: Up and Running by Martin Kalin O’Reilly, 2009

21 Department of Computer Science Spring 2013: February 25 CS 157B: Database Management Systems II © R. Mak 21 Time Server Publisher  Publish the time service: package wsdemo.timeservice; import javax.xml.ws.Endpoint; public class TimeServerPublisher { public static void main(String args[]) { TimeServer ts = new TimeServerImpl(); String url = String.format("http://localhost:%s/ts", args[0]); System.out.printf("Publishing service %s to %s...\n", ts.getClass().getName(), url); // 1st argument is the publication URL // 2nd argument is an SIB instance Endpoint.publish(url, ts); } Pass in the server port number as a runtime argument. Run forever until terminated. Construct the service. Adopted from Java Web Services: Up and Running by Martin Kalin O’Reilly, 2009 ts is an arbitrary name. Demo

22 Department of Computer Science Spring 2013: February 25 CS 157B: Database Management Systems II © R. Mak 22 Time Service WSDL  Download the WSDL document (the service contract) at http://localhost:9876/ts?wsdlhttp://localhost:9876/ts?wsdl...... The portType is similar to a Java interface: It groups the operations provided by the web service. The service endpoint.

23 Department of Computer Science Spring 2013: February 25 CS 157B: Database Management Systems II © R. Mak 23 Time Service Client  The client program makes the time service requests: package wsdemo.timeservice; import java.net.MalformedURLException; import java.net.URL; import javax.xml.namespace.QName; import javax.xml.ws.Service; class TimeClient { public static void main(String args[]) throws MalformedURLException { URL url = new URL(String.format("http://localhost:%s/ts?wsdl", args[0])); QName qname = new QName("http://timeservice.wsdemo/", "TimeServerImplService"); Service service = Service.create(url, qname); TimeServer eif = service.getPort(TimeServer.class); System.out.println(eif.getTimeAsString()); System.out.println(eif.getTimeAsElapsed()); } Pass in the server port number as a runtime argument. Create the qualified service name. Factory to get the service port (endpoint interface). Request services. Get the WSDL. Adopted from Java Web Services: Up and Running by Martin Kalin O’Reilly, 2009 Demo

24 Department of Computer Science Spring 2013: February 25 CS 157B: Database Management Systems II © R. Mak 24 Monitor Network Traffic  Track HTTP and SOAP messages with tcpmon. Download from http://code.google.com/p/tcpmon/http://code.google.com/p/tcpmon/  Intercept requests. Display each request. Forward the request to the service provider.  Display results. _ Demo

25 Department of Computer Science Spring 2013: February 25 CS 157B: Database Management Systems II © R. Mak 25 NetBeans Support for Web Services  Tutorial: http://netbeans.org/kb/docs/websvc/jax-ws.htmlhttp://netbeans.org/kb/docs/websvc/jax-ws.html


Download ppt "CS 157B: Database Management Systems II February 25 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron."

Similar presentations


Ads by Google