Entity beans are used to represent persistent data. One common practice is to obtain the data from a relational database. Another is invoking another
application or, for example, a CICS transaction.
The entity beans can be categorized into two groups, namely BMP and CMP.
BMP - Bean Management Persistence
Bean management persistence means that the EJB provider has to ensure the persistence of the EJB. It requires additional logic and code; because of this, BMP is not recommend for large projects with a focus on portability and scalability. There is no guarantee that an BMP EJB can be easily deployed to another Web application server.
CMP - Container Management Persistence
Here, the persistence of the EJB is ensured by the container. No additional code has to be added to the business logic of the EJB. The business logic remains untouched and can be deployed easily on different Web application servers; for example, the IBM WebSphere Application Server provides CMP for EJBs.
An entity bean uses a unique key to identify its home. This unique key can be used to create or find the instance of an EJB. Note that the unique key has to be serializable to match the specifications.
More information on EJBs can be found on the following Sun Web page:
http://java.sun.com/products/ejb/
Chapter 10. Application development 159
10.1.5 XML
XML stands for eXtensible Markup Language. It is a subset of the SGML standard and is also used to define markup languages like WML or SyncML.
XML is an easy to use language for describing any content. Developers can define their own markup language tags or elements. They can ensure that their XML dialect best fits their application needs. In general, XML documents include only data. They do not include any formatting information used to present the content; this information is stored in a separate Extensible StyleSheet Language (XSL) file. Only this XSL file is used to display the data in an appropriate way on the client browser. An XSL file and the XML data document are merged by using the Extensible StyleSheet Language Transformation (XSLT). We will discuss XSL and XSLT later (see 10.1.6, “XSL” on page 160 and 10.1.7, “XSLT” on page 161).
Below is a very basic XML example of the enhanced Trade2 application:
Example 10-1 Enhanced Trade2 application
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE account SYSTEM "/trade/xml/simphtml/res/Trade.dtd">
<account>
<userid>James</userid>
<fullname>James Howart</fullname>
<address>Bakerman street downtown Raleigh</address>
<email>[email protected]</email>
<creditcard>56789-99-1234</creditcard>
</account>
The example shows that an XML document typically consists of three parts. The first part is the XML declaration. It specifies the used XML version as well as the character encoding. Furthermore, the XML declaration may indicate if the document is logically complete; otherwise, a reference to an external entity is included.
The second part is the Document Type Definition (DTD). This element is optional. Normally, it is used to define the grammar for the XML file and to validate the XML data against this grammar. If there is a DTD, the user can reference it internally or externally. In the first case, one DTD is included in the XML file. In the second case, the DTD is referenced by a pointer and stored in the server file directory.
Furthermore, the DTD can be defined by a public or non-public entity. For a public entity, the keyword PUBLIC is used. Non-public entities are referenced by the keyword SYSTEM. For the shown XML example, we built our own DTD file and stored it in the directory of the server. You can find the reference as well as the keyword SYSTEM in the XML data files. Fore more information about the XML Trade2 application, please refer to 15.3, “Universal transcoding (XML source)” on page 293.
The third part is the body of the document, which contains the data described in a structured way. Each piece of information is represented by a tag that can contain elements and attributes. As discussed before, the XML document does not include any formatting information to present the data.
An XML document must obey specific syntax rules. For example, one rule states that every element must consist of a start and end tag. An example for this rule is the tag userid (<userid>James</userid>). If an element is empty, no explicit end tag is needed. Instead, the end sign is included in the first tag (<userid/>).
Nested elements are allowed if the proper order is matched.
The XML documents can be classified into two categories:
Well-formed XML documents:
A well-formed XML document satisfies the strong syntax requirements. No special additional DTD is needed. Therefore, a non validating XML parser is able to read and parse the document
Valid XML documents:
A valid XML documents applies the strong syntax rules and matches the legal structure defined in the DTD. A validating XML parser is able to read the document.
In practice, XML is used widely to share, store and exchange information between applications or computer systems in business settings. An example of an application where XML is becoming more and more popular is EDI (Electronic Data Interchange). Here, XML is used to exchange and share data and
information between different companies.
More information about XML can be found at the following Web address:
http://www.w3.org/XML
10.1.6 XSL
The Extensible Stylesheet Language (XSL) is used for the presentation of an XML document. XSL can produce various output documents, for example HTML, WML, cHTML and VoiceXML.
Chapter 10. Application development 161 XSL is fundamentally based on two existing standards: Cascading StyleSheets (CSS) and Document Style Semantics and Specification Language (DSSL).
By using XML and XSL, data description and data presentation are separated. In this case, it is possible to define clear roles and responsibilities within the Web application development. As a consequence, the XSL developer does not have to deal with the dynamic data and can change or amplify the user interface without touching the business logic. Note that XSL does not require a DTD for either the source or the result document.
Examples of XSL files can be found in the XML Trade2 applications (see 15.3,
“Universal transcoding (XML source)” on page 293).
For more information on XSL, please refer to http://www.w3.org/Style/XSL
10.1.7 XSLT
Extensible Stylesheet Language Transformation (XSLT) is the common language used to translate an XML document into another output format by applying the appropriate StyleSheet for it.
Figure 10-2 gives an overview of the translation process using a XML input source and a XSL file.
Figure 10-2 Interaction between XML, XSL and XSLT
HTML Page
CHTML Page
WML Page
Voice XML Page XSLT
XSL Voice XML XSL
CHTML XSL HTML
XSL WML
XML
In translating an XML document, the following steps are processed by the XSLT:
Parsing and validating the XML document
Parsing and validating the XSL document
Applying appropriate patterns to parts of the source tree
Calling and applying the templates within the matching patterns
As mentioned before, the output format of the XSLT process can be another XML document or, for example, an HTML or WML file. Typically, a control element in the application has to choose the right XSL file. In our Trade2 example, we used the WTP to do the matching (see 15.3.9, “Registering the StyleSheets in WTP”
on page 304).
To develop XML applications, one can use predefined classes from Apache.
These classes cover the whole XML, XSL and XSLT development, giving the developers the whole API. For details, please refer to http://xml.apache.org.
The specification for XSLT can be found at the following Internet address:
http://www.w3.org/TR/xslt
10.1.8 HTML, cHTML, HDML, WML
This section provides an overview of the most common and important visual markup languages for mobile Web applications.
HTML
Hypertext Markup Language (HTML) is the common language for creating and publishing documents for the World Wide Web. It is based on SGML and used to display hypertext information on traditional Web browsers such as Netscape Navigator or Internet Explorer.
The simplest method to create and process an HTML document is to use a text editor. But there is also a wide range of visual programming tools for WYSIWYG development, one of which is included in the offering the IBM WebSphere Studio 3.5. It offers several wizards and the Page Designer as a visual editor to create the HTML files (see 10.2.1, “WebSphere Studio” on page 166).
In addition to the defined tag set, you can use Cascading StyleSheets (CCS), JavaScript and Java Applets to improve the functionality, look and feel of an HTML page.
For more information about HTML, please refer to http://www.w3.org./Markup/
Chapter 10. Application development 163