120 Patterns: Implementing Self-Service in an SOA Environment
6.3.7 JavaBeans
JavaBeans is an architecture developed by Sun™ Microsystems™, Inc.
describing an API and a set of conventions for reusable, Java-based
components. Code written to Sun’s JavaBeans architecture is called
JavaBeans
or just beans. One of the design criteria for the JavaBeans API was support for
builder tools that can compose solutions incorporating beans. Beans may be
visual or non-visual.
Beans are recommended for use in conjunction with servlets and JSPs in the
following ways:
򐂰 As the client interface to the Model layer
A Controller servlet will use this bean interface.
򐂰 As the client interface to other resources
In some cases, this can be generated for you by a tool.
򐂰 As a component that incorporates a number of property-value pairs for use by
other components or classes
For example, the JavaServer Pages specification includes a set of tags for
accessing JavaBeans properties.
6.3.8 XML
Extensible Markup Language (XML) and XSL stylesheets can be used on the
server side to encode content streams and parse them for different clients,
enabling you to develop applications for both a range of PC browsers and for
emerging pervasive devices. The content is in XML and an XML parser is used to
transform it to output streams based on XSL stylesheets that use CSS.
This general capability is known as
transcoding and is not limited to XML-based
technology. The appropriate design decision here is how much control over the
content transforms you need in your application. You will want to consider when
it is appropriate to use this dynamic content generation and when there are
advantages to having servlets or JSPs specific to certain device types.
XML is also used as a means to specify the content of messages between
servers, whether the two servers are within an enterprise or represent a
business-to-business connection. The critical factor here is the agreement
between parties on the message schema, which is specified as an XML DTD or
Schema. An XML parser is used to extract specific content from the message
stream. Your design will need to consider whether to use an event-based
approach, for which the SAX API is appropriate, or to navigate the tree structure
of the document using the DOM API.
Chapter 6. Technology options 121
IBM’s XML4J XML parser was made available through the Apache open source
organization under the Xerces name. For open source XML frameworks, see:
http://xml.apache.org/
Defining XML documents
XML documents are defined using DTDs or XML Schemas.
DTDs are a basic XML definition language, inherited from the SGML
specification. The DTD specifies what markup tags can be used in the document
along with their structure.
DTDs have two major problems:
򐂰 Poor data typing
In DTDsm elements can only be specified as EMPTY, ANY, element content,
or mixed element-and-text content, and there is no standard way to specify
null values for elements.
Data typing such as date formats, numbers, or other common data types
cannot be specified in the DTD. As a result, an XML document might comply
with the DTD but still have data type errors that can only be detected by the
application.
򐂰 Not defined in XML
DTD uses its own language to define XML syntax that is not compliant to the
XML specification. This makes it difficult to manipulate a DTD.
To solve these problems, the World Wide Web Consortium (W3C) defined a new
standard to define XML documents called
XML Schema. XML Schema provides
the following advantages over DTDs:
򐂰 Strong typing for elements and attributes
򐂰 Standardized way to represent null values for elements
򐂰 Key mechanism that is directly analogous to relational database foreign keys
򐂰 Defined as XML documents, making them programmatically accessible
Even though XML Schema is a more powerful technology to define XML
documents, it is also a lot harder to work with, so DTDs are still widely used to
define XML documents. Additionally, simple, not hard-typified documents can be
easily defined using DTDs with similar results to using XML Schema.
Whether you use one or the other will depend on the complexity of the messages
and the validation requirements of the application. Actually, in many cases both
(a DTD and a XML Schema) are provided, so they can be used by the
application depending on its requirements.

Get Patterns: Implementing Self-Service in an SOA Environment now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.