Google
 

 

up previous next contents
Up: 3. Day 3: Standard Previous: 3.13 JavaServer Pages Next: 4. Day 4: Databases,   Contents

Subsections

3.14 Survey of other server-side Java technologies

  • XML
  • XSLT
  • Enterprise Java Beans
  • Java Messaging Service

3.14.1 XML

  • eXtensible Markup Language
  • Derived from SGML, which is also the original parent language of HTML.
  • XML is a "meta" language, that can be used to defined an unlimited number of custom hierarchical data formats.
  • Example:
      <?xml version="1.0" ?>
      <sandwich price="2.00">
        <meat>Pastrami</meat>
        <bread>Rye</bread>
        <cheese slices="1">Swiss</cheese>
        <condiments>
          <condiment>mustard</condiment>
          <condiment>pepper</condiment>
        </condiments>
      </sandwich>
    
  • In the example above <sandwich>, <condiment>, and all tags within <> are elements.
  • Elements can be nested within each other infinitely deep.
  • "price" and "slices" are attributes of their respective elements.
  • XML must be well formed to be porcessed:
    • All tags are closed: <bread>Rye</bread>,
      or <bread/> which denotes an empty element.
    • Elements must be closed on the same level they start.
      <sandwich><meat></sandwich></meat> is not well formed.
    • All attributes are within single or double quotes.
  • The structure of a particular XML document can be described with Document Type Definitions (DTD) or schemas. Instances of that document can then be validated against the corresponding DTD or schema.
  • Why use XML?
    • Flexible hierarchical data formatting language that can easily be read by humans as well as programs.
    • Readily available tools for document creation, parsing, and validation.
    • Plaform and programming language neutral.
  • The Java API for XML Processing (JAXP) defines a standard interface for using XML in Java programs. There are several implementations of this API, including Xerces from the Apache Group and Crimson from Sun.

3.14.2 XSLT

  • eXtensible Stylesheet Language: Transformation
  • XSLT documents are instructions that describe how to transform one XML document into another type of XML document.
  • Example uses:
    • Converting the XML for an order into HTML that displays the order to the user.
    • Converting an XML invoice from a vendor's system into XML that your internal system understands.
  • This sample shows how to transform the sandwich XML from the previous section into HTML.
    Input XML:
    <?xml version="1.0" encoding="UTF-8"?>
    <sandwich price="2.00">
      <meat>Pastrami</meat>
      <bread>Rye</bread>
      <cheese slices="1">Swiss</cheese>
    </sandwich>
    
    XSLT:
    <!-- XSLT is itself XML -->
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/sandwich">
      <!-- the HTML tags are embedded directly in the template -->
      <html>
      <head><title>My Sandwich</title></head>
        <body>
        <!-- when executed, the value-of element is replaced 
             with the actual value -->
        <b>Meat:</b> <xsl:value-of select="meat" /><br />
        <b>Bread:</b> <xsl:value-of select="bread" /><br />
        <b>Cheese:</b> <xsl:value-of select="cheese/@slices" /> 
            slice(s) of <xsl:value-of select="cheese" />
        <br /><br />
        <b>Cost:<xsl:value-of select="@price" /></b>
        </body>
      </html>
    </xsl:template>
    </xsl:stylesheet>
    Output:
    <html>
    <head>
      <title>My Sandwich</title>
    </head>
    <body>
      <b>Meat:</b>Pastrami<br />
      <b>Bread:</b>Rye<br />
      <b>Cheese:</b>1 slice(s) of Swiss
      <br /><br />
      <b>Cost: 2.00</b>
     </body>
    </html>
    

  • The JAXP defines the API for executing XSLT transformations.

3.14.3 Enterprise Java Beans

  • Allows the developer to write components without explicitly coding for database storage, transactions, thread safety, or remote invocation.
  • XML configuration files are used to mark how components are mapped to databases, which methods require transactions, and how the components can be accessed.
  • The EJB specification is implemented by many vendors including IBM, Borland, BEA, Oracle, and Macromedia. There are also a few open source implementations.

3.14.4 Java Messaging Service

  • Provides asynchronous message based communication to Java applications.
  • There are two styles of JMS:
    • Queues - Messages are stored in queues where they can be processed in the order received.
    • Publish and Subscribe - Multiple subscribers are notified when messages are published.
  • JMS can guarantee message delivery
  • Messages can be processed as part of a transaction. If the transaction is rolled back, the message activity is also rolled back.