Oracle9i Case Studies - XML Applications Release 1 (9.0.1) Part Number A88895-01 |
|
This chapter contains the following sections:
Oracle9i Application Server Wireless Edition (Oracle9iAS Wireless Edition) allows carriers, enterprises, and Internet companies to wirelessly enable any new or existing Internet applications or content for any wireless Internet device - including Smartphones, pagers, PDAs, and so on.
OracleMobile, a division of Oracle Corp., is a wireless application service provider (WASP) with a complete service offering for wireless Web site creation and hosting based on Oracle9i Application Server Wireless Edition technology.
Content Adapters convert any content to XML. Transformers convert the XML to any markup language supported by any device (HTML, WML, HDML, VoiceXML, VoxML, SMS, etc.). Oracle9i AS Wireless Edition's open architecture and use of XML technology ensures support of current and emerging standards. Oracle9i AS Wireless Edition provides for location based services, wireless messaging, wireless m-commerce, and extensive personalization for users and devices.
Most Web clients are PCs, but according to the Meta Group, "By 2003, over 50% of internet access will be by non-PCs."
Oracle9iAS Wireless Edition (Portal-to-Go) enables the following services:
Portal-to-Go, a component of the Oracle Internet Platform, is a server product that provides everything you need to deliver Web content to any capable device. It transforms existing content to a device's native format, and provides a portal interface for the end-user.
XML is the key for content providers to reach an audience of mobile users with data delivered in many different formats. XML isolates the source content format from the target device format, enabling content providers to take data from any source and deliver it to any target. Use these XML-based techniques in applications that convert data from one format to another, such as:
Oracle9iAS Wireless Edition portals contain:
This chapter describes how Oracle9iAS Wireless Edition uses XML to make Web content available to any device. It describes a stock quote service and the role XML takes as an intermediate format for the data exchange.
XML Parser for Java v2 is used in Oracle9iAS Wireless Edition Adapters and Transformers. The XSLT package of the XML Parser for Java is also used.
The Oracle9iAS Wireless Edition features include the following support:
See Also:
Oracle9iAS Wireless Edition requires the following:
Oracle9iAS Wireless Edition provides transformers for the latest WAP-compliant devices from the following vendors:
You can also create your own transformers and extend Oracle9iAS Wireless Edition support to other devices.
Oracle9iAS Wireless Edition has been successfully tested with the following WAP gateways:
Figure 3-1 shows how Oracle9iAS Wireless Edition (Portal-to-go) works. When an end-user requests an Oracle9iAS Wireless Edition service, this is what happens:
XML and related technologies are at the core of Oracle9iAS Wireless Edition's functionality, as follows:
A Oracle9iAS Wireless Edition service encapsulates a unit of information requested by, and delivered to, a Oracle9iAS Wireless Edition client. Examples of services include:
You can build services from an existing Web site, a query to any database, or any XML source.
A Master Service is a Oracle9iAS Wireless Edition object that implements a service and invokes a specific adapter. The end-user typically sees a service as a menu item on a handset or a link on a Web page. End-users invoke Master Services by choosing menu items in their device interface. The Master Service returns the following kinds of data:
By mapping an Adapter to device Transformers, master services link Oracle9iAS Wireless Edition content sources to the delivery platforms. Each Master Service is based on one Adapter. A Master Service creates its own instance of the Adapter it uses. Therefore, several services can use the same type of Adapter, and each can pass the Adapter its service-specific argument values.
A Oracle9iAS Wireless Edition Adapter is a Java application that retrieves data from an external source and renders it in Oracle9iAS Wireless Edition XML. When invoked by a Master Service, an Adapter returns an XML document that contains the service content. Adapters provide the interface between the Oracle9iAS Wireless Edition server and the content source.
An Adapter does the following:
Oracle9iAS Wireless Edition provides pre-built Adapters for popular content sources, including Web pages and JDBC-enabled data sources, and adapters you can modify to work with other content sources.
All adapters must generate Oracle9iAS Wireless Edition XML. This is a well-formed, valid XML document that complies with the Oracle9iAS Wireless Edition DTD.
Oracle9iAS Wireless Edition Transformers are Java programs or XSL-T stylesheets that convert an XML document into the target or another Oracle9iAS Wireless Edition format. They can also rearrange, filter, and add text. The Transformers enable you to present content in a format best suited to your target device. Oracle9iAS Wireless Edition supplies transformers for the following markup languages:
Figure 3-3 illustrates these markup languages and their derivation.
Use Transformers to optimize content presentation for any device, and support new device platforms. In most cases, you can simply modify or re-use an existing Transformer.
With XML as an intermediate format, you can take data from any source and deliver it to any device. Suppose you have a Web application that provides stock quotes and headlines, and you want to deliver the information to a mobile phone and a PDA (Personal Digital Assistant, such as a Palm Pilot).
Because each device has specific requirements for formatting content, you cannot send the same data to each device. How would you do it? Oracle9iAS Wireless Edition defines an intermediate data format in XML. It also provides tools that allow content providers to perform the following tasks:
Hand-held devices cannot display as much information as a desktop monitor, so you have to be selective. Figure 3-4 shows two, deliberately undecipherable, Web pages from a Stock Data application.
Both pages are full of ads, buttons, hyperlinks, related articles, and more. Your first step would be to identify the elements of a Web page that you want to make accessible to your service.
You then can use the Web Integration Adapters to convert your content to XML.
A Oracle9iAS Wireless Edition Adapter retrieves content from the source. In the example illustrated here, it pulls specific quotes and headlines from a Web page. Then the Adapter converts the content to XML.
Why not go straight to the target device format? Two reasons: flexibility and extensibility. To go straight from source to target, you must effectively create an adapter and transformer for each source-target pair. With XML as an intermediate format, you only need one adapter for each source, and one transformer for each device. For example if there are, say two content sources and three target devices
Adapter output must be XML to be generic. The key is to define an XML document type that can represent any data type you might want to display on any device. The document type is defined by a Document Type Definition (DTD). A DTD is a file that provides a grammar for a class of XML documents by describing the elements it can contain.
To create a truly universal intermediate data format, Oracle9iAS Wireless Edition uses the Simple Result DTD. Elements in the Simple Result DTD represent the elements of an abstract user interface. These include the following:
Figure 3-5 illustrates the Simple Result DTD content model.
Following is a portion of SimpleResult.dtd that shows the elements used in our Stock Data example.
<!-- Entity: "GENATTR" contains generic attributes for most elements. Attribs: "name" is the name of the element. "title" is the title of the element. ... --> <!ENTITY % GENATTR " name CDATA #IMPLIED title CDATA #IMPLIED ... "> <!-- Element: "SimpleResult" is the result element. Usage: This element contains the result. Children: "SimpleText" is a text result. ... --> <!ELEMENT SimpleResult ((SimpleContainer|SimpleText|SimpleMenu| SimpleForm|SimpleTable|SimpleImage|SimpleBreak)+)> <!ATTLIST SimpleResult %GENATTR;> ... <!-- Element: "SimpleText" for displaying one or more blocks of text. Usage: Used for plain text. Children: "SimpleTextItem" is a block of text. --> <!ELEMENT SimpleText (SimpleTextItem+)> <!ATTLIST SimpleText %GENATTR;> <!-- Element: "SimpleTextItem" is a block of text Usage: Holds one block of text - normally a single paragraph. Children: "#PCDATA" is the actual text. --> <!ELEMENT SimpleTextItem (#PCDATA)> <!ATTLIST SimpleTextItem %GENATTR;> ... <!-- Element: "SimpleForm" for displaying one or more input fields. Usage: As a data-entry form. Children: "SimpleFormItem" for each input field. Attribs: "target" is the link target for this form. "section" is the section identifier
***** A special case for the WIDL adapter *****
--> <!ELEMENT SimpleForm ((SimpleFormItem|SimpleFormSelect)+)> <!ATTLIST SimpleForm %GENATTR; target CDATA #REQUIRED section CDATA #IMPLIED> <!-- Element: "SimpleFormItem" is a single input item in a simple form. Usage: For getting input from a user. Children: "#PCDATA" contains pre-filled input from the server.
****** This overrides the default attribute. *******
Attribs: "default" provides a default value for optional fields.
***** The default value should only be used if the field is empty.
--> <!ELEMENT SimpleFormItem (#PCDATA)> <!ATTLIST SimpleFormItem %GENATTR; default CDATA #IMPLIED mandatory(yes|no) "no" maxLength CDATA #IMPLIED> ...
Oracle9iAS Wireless Edition Adapters map the source content to the appropriate Simple Result element.
For example, Table 3-1 shows the XML for an input form (text label, input field, and submit button) and results page (ticker symbol, stock price, and headlines) generated by a hypothetical StockData Adapter.
The following code example shows how Adapters are implemented in Java. You can it to create your own Adapters for custom content sources.
"Oracle9i AS Wireless Edition Adapter Example 1: Greeting Users by Name" is a simple, but complete, Adapter implementation that greets users by name.
Consider a simple Adapter for a service that greets users by name. It has the following inputs:
Example 2's Adapter uses the invoke
method to build a Simple Result document using methods in the following packages:
The invoke method performs the following tasks:
Here is the Adapter implementation:
import org.w3c.dom.Element; import org.w3c.dom.Text; import oracle.panama.Argument; import oracle.panama.Arguments; import oracle.panama.ServiceRequest; import oracle.panama.adapter.Adapter; import oracle.panama.adapter.AdapterDefinition; import oracle.panama.adapter.AdapterException; import oracle.panama.adapter.AdapterHelper; public class HelloAdapter implements Adapter { private boolean initialized = false; private String greeting = "Hello"; public static final String GREETING = "greeting"; public static final String NAME = "name"; // Called once, when the adapter is instantiated. public void init (Arguments args) throws AdapterException { synchronized (this) { if(!initialized) { initialized = true; greeting = args.getInputValue( GREETING ); } } } public Element invoke (ServiceRequest sr) throws AdapterException { Element result = XML.makeElement("SimpleResult"); Element st = XML.makeElement("SimpleText"); st.setAttribute ("title", "Oracle Portal-to-Go Server HelloAdapter Sample"); result.appendChild (st); Element sti = XML.makeElement("SimpleTextItem"); sti.setAttribute ("name", "message"); sti.setAttribute ("title", "Portal-to-Go says:"); st.appendChild (sti); // ServiceRequest sr contains input parameters (like NAME, below). String name = sr.getArguments().getInputValue(NAME); Text txt = XML.makeText( greeting + " " + name + "!"); sti.appendChild (txt); return result; } // This method enables master services to determine // the initialization parameters used by the adapter. private AdapterDefinition initDef = null; public AdapterDefinition getInitDefinition() { if (initDef == null) { synchronized (this) { if (initDef == null) { initDef = AdapterHelper.createAdapterDefinition(); initDef.createInit( Argument.SINGLE_LINE, GREETING, "Greeting phrase", null ); } } } return initDef; } // This method defines the adapter’s runtime input parameters. private AdapterDefinition adpDef = null; public AdapterDefinition getAdapterDefinition() throws AdapterException { if (adpDef == null ) { synchronized (this) { if (adpDef == null) { if (initDef == null) throw new AdapterException ("Adapter is not properly initialized"); adpDef = initDef; adpDef.createInput( Argument.SINGLE_LINE, NAME, "Name to greet", null ); } } } return adpDef; } }
When invoked with an input parameter of "Dolly", the above Adapter returns the following XML result:
<SimpleResult> <SimpleText title="Oracle Portal-to-Go Server Hello Sample"> <SimpleTextItem name="message" title="Portal-to-Go says:"> Hello Dolly! </SimpleTextItem> </SimpleText> </SimpleResult>
Oracle9iAS Wireless Edition Transformers convert XML documents into the markup language for the target device. By using a generic internal XML format, such as SimpleResult, to represent information, you can take full advantage of each client device's UI capabilities.
The Transformers use the SimpleResult DTD to map abstract UI elements to the target format. You can implement a Transformer using Java or XSL-T, depending on what you need to do:
You can create Java Transformers using either of the following two interfaces:
These two interfaces are illustrated in Figure 3-6.
Oracle9iAS Wireless Edition includes a Java Transformer that converts Simple Result documents to plain text. The Transformer does not create markup tags in the resulting document, but it does apply simple text formatting elements, such as line breaks and tabs.
Though simple, this example shows how you can convert Simple Result elements into another format.
package oracle.panama.core.xform; import org.w3c.dom.NodeList; import org.w3c.dom.Element; import oracle.panama.PanamaException; import oracle.panama.core.LogicalDevice; import oracle.panama.core.Service; import oracle.panama.Arguments; import oracle.panama.core.parm.PanamaRequest; import oracle.panama.core.parm.AbstractRequest; public class SimpleResultToText implements Transform { public SimpleResultToText() {} private String format(Element el) { if (el == null) { return ""; } StringBuffer buf = new StringBuffer(); String name = el.getTagName(); if (name != null && name.length() > 0) { buf.append(name); buf.append(": "); } buf.append(el.getNodeValue()); return buf.toString(); } public String transform(Element element, LogicalDevice device) throws PanamaException { PanamaRequest req = AbstractRequest.getCurrentRequest(); Service service = req.getService(); StringBuffer buf = new StringBuffer((service == null) ? "" : service.getName()); NodeList list = element.getElementsByTagName("*"); Element el; String tag; boolean newRow = false; for (int i = 0; i el = (Element)list.item(i); tag = el.getTagName(); if (tag.equals("SimpleRow")) { newRow = true; buf.append("\n"); } else if (tag.equals("SimpleCol")) { if (!newRow) { buf.append("\t"); } else { newRow = false; } buf.append(format(el)); } else if (tag.equals("SimpleText") || tag.equals("SimpleForm") || tag.equals("SimpleMenu")) { newRow = true; buf.append("\n"); } else if (tag.equals("SimpleTextItem") || tag.equals("SimpleFormItem") || tag.equals("SimpleMenuItem")) { if (!newRow) { buf.append("\n"); } else { newRow = false; } buf.append(format(el)); } } return buf.toString(); } }
XSL stylesheets are XML documents that specify the processing rules for other XML documents. An XSL stylesheet, like a Java Transformer, is specific to a particular DTD, and should handle all elements declared in that DTD. When it finds an element in a source document, it follows the rules defined for the element to format its content.
This XSL Transformer example is included in the Oracle9iAS Wireless Edition initial repository and is the XSL version of the Java Transformer shown above. It converts Simple Result documents to plain text.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0"> <xsl:template match="/"> <xsl:apply-templates></xsl:apply-templates> </xsl:template> <xsl:template match="SimpleTextItem | SimpleFormItem | SimpleMenuItem"> <xsl:text> </xsl:text> <xsl:value-of select="."></xsl:value-of> </xsl:template> <xsl:template match="SimpleRow"> <xsl:text></xsl:text> <xsl:for-each select="./SimpleCol"> <xsl:text></xsl:text> <xsl:value-of select="."></xsl:value-of> </xsl:for-each> </xsl:template> </xsl:stylesheet>
In this example. the XSL stylesheet performs the following tasks:
apply-templates
to process the contents of that element.
value-of
and for-each
, manipulate the content of matching elements.
Each unique markup language requires a unique Transformer. The Stock Data example assumes that the PDA and cell phone use different markup languages (Tiny HTML and WML), so we need two Transformers. Once they're built, though, these Transformers can process content from any Adapter that generates Simple Result XML.
Table 3-2 lists the Adapter's SimpleResult XML code and the markup language generated by two transformers:
Table 3-2 Using Unique Transformers to Transform the Adapter's Simple Result XML
When using the Phone.com browser the navigation model requires you to select the [Link] option before proceeding. You can customize the stylesheet to change this behavior. For example, you can add the following to the WML1.1 Transformer stylesheet:
| The SimpleForm Mapping +--> <xsl:template match="SimpleForm"> <p> <xsl:variable name="theTarget"> <xsl:value-of select="@target"/> <xsl:for-each select="SimpleFormItem | SimpleFormSelect"> <xsl:text>&</xsl:text> <xsl:value-of select="@name"/> <xsl:text>=$(</xsl:text> <xsl:value-of select="@name"/> <xsl:text>)</xsl:text> </xsl:for-each> </xsl:variable> <xsl:apply-templates/> <!-- Ensure [Link] is selected --> <select> <option> <onevent type="onpick"> <go href="{$theTarget}"/> </onevent> <xsl:choose> <xsl:when test="boolean(@submit)"> <xsl:value-of select="@submit"/> </xsl:when> <xsl:otherwise>Submit</xsl:otherwise> </xsl:choose> </option> </select> </p> <!-- Ensure [Link] is selected ends --> <!-- <a href="{$theTarget}"> <xsl:choose> <xsl:when test="boolean(@submit)"> <xsl:value-of select="@submit"/> </xsl:when> <xsl:otherwise>Submit</xsl:otherwise> </xsl:choose> </a> <br/> </p> --> </xsl:template>
The SimpleResult XML has been extended by adding a new element called SimpleDB. This element is used to execute your INSERT, UPDATE, and DELETE statements on any database or your PLSQL on an Oracle database.
For example, you can use this feature for an advanced billing system, where the cost is defined by the content provider. You can also use all the database standard features (UTL_SMTP, UTL_FILE...) to extend the master services capabilities.
To do this, a new Java class has been created called, oracle.panama.core.xform.MyXslExtension,
with a method called processDB()
.
To test this feature, copy MyXslExtension.class
to
%ORACLE_HOME%/panama/server/classes/oracle/panama/core/xform and add onto your device transformer the following header:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:p2g="http://www.oracle.com/XSL/Transform/java/oracle.panama.core.xform.XSL Java" exclude-result-prefixes="p2g" xmlns:myxsl="http://www.oracle.com/XSL/Transform/java/oracle.panama.core.xform.M yXslExtension">
Then add the following statement to your transformer body:
<!-- Execute SimpleDB--> <xsl:template match="SimpleDB"> <xsl:value-of select="p2g:processDB(.)"/> </xsl:template>
or
<!-- Bypass SimpleDB--> <xsl:template match="SimpleDB"> <xsl:apply-template/> </xsl:template> <xsl:template match="SimpleDBItem"/>
Here's an example of SimpleResult, generated by a Result Transformer, with the SimpleDB element:
<SimpleResult> <SimpleContainer> <SimpleText> <SimpleTextItem>Symbol : ORCL</SimpleTextItem> <SimpleTextItem>Value (USD): 76 15/32</SimpleTextItem> <SimpleTextItem>Value (HKD): 592.59</SimpleTextItem> </SimpleText> <SimpleDB jdbc="jdbc:oracle:thin:@hkpsnt3.hk.oracle.com:1521:orcl" user="scott" password="tiger"> <SimpleDBItem type="SQL"> insert into quote values ('orcl','ORCL','76 15/32',null, null) </SimpleDBItem> <SimpleDBItem type="PLSQL"> begin insert into quote values ('orcl','ORCL','76 15/32',null,sysdate); end; </SimpleDBItem> </SimpleDB> </SimpleContainer> </SimpleResult>
This is just an example and of course your can add your own extension by creating other Java methods.
// Allen M.K. YAP - Sales Consultant // Oracle System Hong Kong Ltd. // Email : Manh-Kiet.Yap@oracle.com // File : MyXslExtension.java // Date : 28/09/2000 package oracle.panama.core.xform; import oracle.panama.core.xml.XML; import oracle.panama.core.admin.L; import org.w3c.dom.*; import java.sql.*; public class MyXslExtension { private static String getTextValue(Element element) { Node node = element.getFirstChild(); if(node != null && node.getNodeType() == 3) return node.getNodeValue(); else return ""; } public static String processDB (NodeList nlist) { Element element = (Element) nlist.item(0); String out = new String(); boolean fail = false; String jdbc_conn = element.getAttribute("jdbc"); String jdbc_user = element.getAttribute("user"); String jdbc_pass = element.getAttribute("password"); try { Connection conn = DriverManager.getConnection (jdbc_conn,jdbc_ user,jdbc_pass ); NodeList nodelist = element.getElementsByTagName("SimpleDBItem"); for(int i = 0; i < nodelist.getLength(); i++) { Element st = (Element)nodelist.item(i); if ( (element.getAttribute("type")).equals("SQL")) { //SQL try { PreparedStatement pstmt=null; pstmt = conn.prepareStatement(getTextValue(st)); pstmt.executeUpdate(); pstmt.close(); } catch (SQLException e) { L.e("SQL fails : "+e); out.concat(getTextValue(st)+"\nSQL fails :\n "+e+"\n"); fail=true; } } else { //PLSQL try { CallableStatement plstmt = conn.prepareCall (getTextValue(st)); plstmt.execute(); plstmt.close(); } catch (SQLException e) { fail=true; L.e("PLSQL fails : "+e); out.concat(getTextValue(st)+"\nPLSQL fails :\n "+e+"\n"); } } } conn.commit(); conn.close(); if (fail) return (out); else return ("DB actions successfully completed."); } catch (SQLException e) { L.e(e); return ("DB actions failed"); } } public MyXslExtension() { } }
An online drugstore is using Oracle® Oracle9iAS Wireless Edition wireless Internet software to extend its reach to customers, providing convenience and around-the-clock access to its online drugstore through hand-held devices.
Oracle Oracle9iAS Wireless Edition extends the existing Internet site to hand-held wireless devices. In this case Oracle9iAS Wireless Edition integrates with the online store, which is built on Oracle Internet Platform. The solution allows consumers to purchase the full line of drugstore products from virtually anywhere.
Oracle9iAS Wireless Edition renders any Internet content devices independent, hence allowing existing content designed for PCs to be made accessible from virtually any device connected to the Internet, such as personal digital assistants (PDAs), wireless application protocol (WAP) phones, or even pagers.
A bank is now offering online services to its customers through mobile phones and uses the Oracle wireless Internet server product, Oracle® Oracle9iAS Wireless Edition.
The bank's customers have access to financial quotes, a search facility for finding the nearest branch office, a loan repayment calculator, an events calendar, and weather reports from either their WAP (wireless application protocol)-enabled phones, or standard GSM phones.
The bank is also adding transactional banking services to their wireless Internet offering. With this, the bank's new WAP platform will also allow access to the bank's online information and services through customer mobile phones.
Online auction sites can extend their accessibility and usability to their customers by offering them an option for shopping from cell phone, PDAs, or other mobile devices.
|
Copyright © 1996-2001, Oracle Corporation. All Rights Reserved. |
|