P. Martin 2001 EJB1 - PowerPoint PPT Presentation

1 / 83
About This Presentation
Title:

P. Martin 2001 EJB1

Description:

request name, address and credit card number. request final confirmation from user ... They have finder methods. They contain attributes and corresponding ... – PowerPoint PPT presentation

Number of Views:55
Avg rating:3.0/5.0
Slides: 84
Provided by: petem7
Category:
Tags: address | ejb1 | finder | martin | uk

less

Transcript and Presenter's Notes

Title: P. Martin 2001 EJB1


1
E-business E-commerce
Enterprise Java Beans (EJB)
Enterprise Java Beans are software components
which interact with other company IT resources to
provide support for both e-commerce (B2C)
and e-business (B2B) and are managed by an
EJB-container -
e-commerce
e-business on web
e-business on private nets (VAN's)
client net server
P. Martin 2001 - EJB-1
2
E-business E-commerce
Enterprise Java Beans (EJB)
In developing and deploying distributed object
systems, a number of issues need to be addressed
- Persistence Object state must be
retained between runs of application
programs. Concurrency Server objects
frequently have to serve multiple clients
concurrently. Transactions In a
multi-tasking environment, large grain atomic
operations require transaction commit and
rollback capabilities.
Security Authorisation of access and enactment
of security policies is essential for data
integrity. Activation Automatic
activation/de-activation along the lines of
CORBA is an essential requirement.
P. Martin 2001 - EJB-2
3
E-business E-commerce
EJB Container services
In developing and deploying distributed object
systems, a number of issues need to be addressed
- Persistence Object state must be
retained between runs of application
programs. Concurrency Server objects
frequently have to serve multiple clients
concurrently. Transactions In a
multi-tasking environment, large grain atomic
operations require transaction comit and
rollback capabilities.
Security Authorisation of access and enactment
of security policies is essential for data
integrity. Activation Automatic
activation/de-activation along the lines of
CORBA is an essential requirement.
P. Martin 2001 - EJB-3
4
E-business E-commerce
Types of EJB
These universal requirements are provided for in
EJB by means of an EJB Container or EJB
Server. Developers create and deploy Beans
within such a Container which manages these
aspects automatically, allowing developers to
concentrate on the business logic. Three types
of Bean can be identified - Entity
Bean Model application domain objects and
have persistent state. Uniquely identified by
a primary key. Session
Bean Represent server side processes - may
have state (e.g. shopping cart) but are short
lived. Message Bean More recent
development - used in conjunction with JMS to
support messaging.
P. Martin 2001 - EJB-4
5
E-business E-commerce
Characteristics of EJBs
Enterprise Java Beans have two interfaces with
which they can be manipulated - Remote
interface This provide the interface which
clients use to interact with the Bean and
provides the business application functio
nality. Home interface Accessed only by the
EJB container, this provides for
- creation removal activation
passivation and location
P. Martin 2001 - EJB-5
6
E-business E-commerce
Session Beans
Session beans model user interaction sessions
rather than persistent objects, they have a
remote and a home interface and they have
the following features - They represent a
process rather than an object They have no
primary key They are not persistence (and are
not backed up by a database) They do persist
for a limited time, but it may be no more than
duration of the client interaction. They can
be stateless or stateful. Stateless session
beans may be pooled by the container to optimize
performance.
P. Martin 2001 - EJB-6
7
E-business E-commerce
Session Bean Example
An example application which would require a
Session Bean is an Airline Booking System. The
Booking Session Bean which allowed users to first
browse and then book a flight could provide
these two methods and the Bean would access a
collection of Entity Beans representing Flight
instances. The book method would carry out the
following operations - allow user to select
origin and destination and date/time confirm
availability of different seat prices and allow
selection request name, address and credit card
number request final confirmation from
user confirm booking
P. Martin 2001 - EJB-7
8
E-business E-commerce
Stateless Session Bean Example - 1
As a simple example, we will look at the
development of a Session bean which will compute
the factorial of a number - First the
Remote Interface which identifies methods which
clients can call -
Then, the Home Interface providing a way of
creating a bean instance-
P. Martin 2001 - EJB-8
9
E-business E-commerce
Stateless Session Bean Example - 2
Finally, the Bean Implementation class -
P. Martin 2001 - EJB-9
10
E-business E-commerce
Stateless Session Bean Example - 3
The following xml files are needed in the
META-INF directory -
First, an ejb-jar.xml file -
P. Martin 2001 - EJB-10
11
E-business E-commerce
Stateless Session Bean Example - 4
Then, a jboss.xml file -
An example1.jar file can then be created
containing the following - example1/ Ex1.class
Ex1Home.class Ex1Bean.class META-INF/ ejb-jar
.xml jboss.xml
P. Martin 2001 - EJB-11
12
E-business E-commerce
Stateless Session Bean Example - 5
Developing a servlet client to access the bean -
first the servlet class -
P. Martin 2001 - EJB-12
13
E-business E-commerce
Stateless Session Bean Example - 6
P. Martin 2001 - EJB-13
14
E-business E-commerce
Stateless Session Bean Example - 7
Then, a web.xml file -
P. Martin 2001 - EJB-14
15
E-business E-commerce
Stateless Session Bean Example - 8
a jboss-web.xml file -
and a welcome page -
P. Martin 2001 - EJB-15
16
E-business E-commerce
Stateless Session Bean Example - 9
An example1.war file can then be created
containing the following - example1/
home.html WEB-INF/ web.xml
jboss-web.xml classes/
example1/ Ex1Serv.class
An application.xml file is then used to package
the whole -
P. Martin 2001 - EJB-16
17
E-business E-commerce
Stateless Session Bean Example - 10
And finally an example1.ear file created using
the following directory structure
- example1.war example1.jar META-INF/ applicatio
n.xml The application is deployed by dropping
the ear file into the jboss/deploy directory. It
can then be run by navigating to
localhost8080/example1
P. Martin 2001 - EJB-17
18
E-business E-commerce
Entity Beans
Entity beans model persistent objects usually
representing domain objects. They also have a
remote and a home interface and additionally
- They have Container Managed persistence
(CMP) or Bean Managed
persistence (BMP). They have a primary
key. They have Container Managed Transactions
or Bean Managed
Transactions. They have finder
methods. They contain attributes and
corresponding getter and setter
metheds.
P. Martin 2001 - EJB-18
19
E-business E-commerce
Example CD Store - 1
As a final example, consider the development of a
CD Store web-site. From an object oriented
design viewpoint, such a system would contain CD
and CDStore classes as main components. These
would be in the following relationship -
CDStore

CD
Here, the CDStore exists as a Facade object and
to accommodate the collection of CD objects. In
developing an EJB solution, the CDStore is
strictly unnecessary as the EJB Container,
through its database, provides the collection of
CD's. It does however provide a useful
abstraction and somewhere to locate the required
user functionality. We thus have a CD Entity
Bean and a CDStore Session Bean.
P. Martin 2001 - EJB-19
20
E-business E-commerce
CD Store 2 The CD Bean
First we have the remote and home interfaces for
the CD Entity Bean -
The Remote Interface
The Home Interface
P. Martin 2001 - EJB-20
21
E-business E-commerce
CD Store 3 The CD Bean
Finally, the CD Entity Bean implementation -
P. Martin 2001 - EJB-21
22
E-business E-commerce
CD Store 4 The CDStore Bean
Now we have the remote and home interfaces for
the CDStore Session Bean -
The Remote Interface
The Home Interface
P. Martin 2001 - EJB-22
23
E-business E-commerce
CD Store 5 The CDStore Bean
Finally, the CDStore Session Bean implementation
-
P. Martin 2001 - EJB-23
24
E-business E-commerce
CD Store 6 The CDStore Bean
P. Martin 2001 - EJB-24
25
E-business E-commerce
CD Store 7 The Servlet Interface
In this example, the CDStore Bean is accessed
over the web using a Servlet to act as an
intermediary as follows -
package example3 import java.io.,
java.util.Hashtable, javax.naming.InitialContext
import javax.rmi.PortableRemoteObject,
javax.servlet., javax.servlet.http. public
class Ex3Serv extends HttpServlet private
CDStoreHome home null public void init()
throws ServletException try
InitialContext jndiContext new
InitialContext() Object ref
jndiContext.lookup("javacomp/env/CDStore")
home (CDStoreHome)
PortableRemoteObject.narrow(ref,

CDStoreHome.class)
catch(Exception e) throw new
ServletException("Failed to lookup
javacomp/env/ejb/CD", e)
P. Martin 2001 - EJB-25
26
E-business E-commerce
CD Store 8 The Servlet (continued)
P. Martin 2001 - EJB-26
27
E-business E-commerce
CD Store 9 Bean xml files
ejb-jar.xml
P. Martin 2001 - EJB-27
28
E-business E-commerce
CD Store 10 Bean xml files
jboss.xml
P. Martin 2001 - EJB-28
29
E-business E-commerce
CD Store 11 Servlet xml files
web.xml
jboss-web.xml
P. Martin 2001 - EJB-29
30
E-business E-commerce
CD Store 12 Application xml file
web.xml
The deployment of the application involves the
creation of - example3.jar file
containing Bean class files, ejb-jar.xml and
jboss.xml. example3.war file
containing home.html, web.xml, jboss-web.xml and
Ex3Serv.class. example3.ear file
containing example3.jar, example3.war and
application.xml. The example3.ear file is then
copied to the JBoss deploy directory.
P. Martin 2001 - EJB-30
31
E-business E-commerce
Transaction Handling
The Airline Booking System book method raises an
important issue. As the system handles multiple
clients simultaneously - Seats selected by a
client must be held until credit-card
authorisation and client confirmation has
occurred. Such seats must be released if
authorisation fails or client changes their
mind. This requires transactions with commit or
rollback capability. EJB provides the following
designations for methods -
NotSupported Transactions not supported in
method Supports Method can be called as
part of a transaction or independently.
Required Method must be called as part of a
transaction. RequiresNew Method Requires
a new transaction to be started.
Mandatory Method must be called as part of a
transaction. Never Method cannot be
called as part of a transaction.
P. Martin 2001 - EJB-31
32
E-business E-commerce
Transaction Handling (continued)
The designation of methods for transaction
handling is contained within the XML descriptor
for a Bean as follows -
Note - The transaction handling can be defined
as container (EJB container) managed or Bean
(user) managed. Similarly, persistence can
also be container or bean managed.
P. Martin 2001 - EJB-32
33
E-business E-commerce
Electronic Data Interchange (EDI)
EDI provides for the interchange of structured
business data between companies and is
essentially a computer to computer dialog with
a minimum of human intervention. It has been in
existence for a long time but has a very slow
take up. Introduced originally to
support the Berlin airlift in 1948.
Developed in the 1960s to support
shipment/transportation systems. Used
in the 1970s to provide electronic funds
transfer (EFT) systems between banking
systems over private networks. Structured
documents EDI messages consist of structured
business documents such as invoices, orders etc.
Each transaction set consists of a number of
documents each with a number of mandatory or
optional data segments, each segment in
turn comprising a number of mandatory or optional
data elements.

P. Martin - 2001 - EDI - 1
34
E-business E-commerce
Actors involved in EDI

The participants in an EDI venture can be
categorised as follows - Supplier or
sponsor Party (individual or firm) who
organises the EDI service and defines
protocols and standards for provided
transactions. Service normally provided for a
fee. Participant Firms making use of
the service - may include the sponsor.
Agent Network provider - usually a value
added network (VAN). Indirect
customer Does business with participants but
not included in EDI system.
P. Martin - 2001 - EDI - 2
35
E-business E-commerce
Partnerships in EDI

Participating with other firms in an EDI venture
requires closer cooperation between firms. The
types of partnerships that can result from this
are - Joint marketing
partnerships co-operating with rivals where
benefits to all can accrue -
e.g. Airlines, hotels, rental car
firms. Bank cards and ATM systems.
Customer-supplier partnerships Providing
potential for supply chain management (SCM)
improvements. EDI systems are characterised
by - direction of flow one or two way
scope range of transactions
handled intensity proportion
of EDI transactions functionality access
or update of information reach
degree of integration with firms
systems mass number of trading partners
P. Martin - 2001 - EDI - 3
36
E-business E-commerce
Benefits of EDI

Major benefits accrue from the elimination of
- repeated keying of information manual
reconciliation of documents correction of
errors from incorrect data entry sorting,
distributing and filing of documents Other more
strategic benefits are - Implementation of
EDI forces a review reorganisation
of business practices and information
flow. Implementation of Just-In-Time
manufacture (JIT) and
quick-response (QR) systems. Better
management information. Improved responsiveness
- enabling the implementation of pull Supply
Chain Management (SCM). Stronger links with
trading partners in SCM. Global market opened
up. May be a requirement if partners use EDI.
P. Martin - 2001 - EDI - 4
37
E-business E-commerce
Problems with EDI


EDI has has a very slow uptake because of
numerous problems it poses, e.g. High costs to
develop and operate a scheme. Limited
accessibility - need to subscribe to a
VAN. Rigid requirements - highly structured
protocols. Only partial solutions - not all
partners or transactions covered. Closed world
- narrow in scope - limited number of
participants. Two different emerging standards
- X12 (USA) and EDIFACT (EU) Need to convert
internal formats into form suitable for
transmission.
P. Martin - 2001 - EDI - 5
38
E-business E-commerce
Supply chain management (SCM)


The following example from Kalakota illustrates a
typical supply chain -
Eucalyptus leaves
Gas
Grower
Union carbide
Grown corn
Bundled leaves
Alcohol
Transport Company
Shipping company
Corn farmer
Packed leaves
Bundled corn
Distributor
Manufacturing company
Transport company
Packed leaves
Bundled corn
Boxed Listerene
Wholesaler
Chemists
P. Martin - 2001 - EDI - 6
39
E-business E-commerce
Supply chain management (SCM)
There are numerous uncertainties in the supply
chain such as - global supply
variations unpredictable demand fluctuating
prices shorter product life cycles decreasing
brand loyalty To counter this there is need for
more rapid response - I.e. pull rather than push
SCM -


Push SCM
Pull SCM
P. Martin - 2001 - EDI - 7
40
E-business E-commerce
Quick-response (QR) systems


On of the major benefits, especially to the
retailer, is the possibility of greater
responsiveness to consumer demand through the use
of EDI -
Product on store shelf
Consumer purchases
Purchase information recorded by POS
Info collated by store computer
Vendors computer received order
Orders sent to closest warehouse
Store receives replenishment
Vendors manufacturing dept ordered to produce
more product
A good example of the application of EDI is that
of WalMart who in the 1980s invested 1/2 billion
dollars in satellite coms, bar-code POS etc and
as a result managed to increase sales whilst
reducing inventory to 1/4 of previous level. Re-st
ock time was reduced from 6 weeks to 36 hours.
P. Martin - 2001 - EDI - 8
41
E-business E-commerce
Developments in EDI


EDI is going through a period of regeneration and
by adopting new technology is likely to assume
more widespread adoption and hence become more
crucial to business success. Old
EDI Refers to the current practice of developing
rigid standards for EDI documents (X12 and
EDIFACT) making the further development of new
initiatives very slow - and involving costly
restructuring of data into agreed formats both by
the sender and receiver. New EDI By
adopting the use of XML both to encode the
documents and to provide meta-level
descriptions of content (by means of
XML-schemas), the whole process of
inter-organisation communication can be more
responsive to change, easier and cheaper -
allowing smaller firms to be involved.
P. Martin - 2001 - EDI - 9
42
E-business E-commerce
XML


XML is based on SGML the Standard Generalised
Markup Language and like SGML is concerned with
content rather than presentation. XML is fast
becoming the basis for data storage and
communication on the web and a number of
specialised markup languages have been
developed, based on the XML standard such as -
XHTML - HTML in XML format with a more
strict definition. WML -
Wireless markup language for use inmobile devices
using WAP. SMIL - Synchronized
Multimedia Integration Language. MathML
Mathematics Markup Language. CML
Chemical Markup Language.
P. Martin - 2001 - XML - 1
43
E-business E-commerce
XML - Validation
Unlike HTML, XML demands that - Tags
and attributes in correct case. Tags
properly terminated. Tags properly
nested. Attribute values enclosed in
quotes. An XML document is said to be -
Well formed - if it follows the above rules.
Valid - if it conforms to a document-type
definition (DTD) A DTD is defined in the DOCTYPE
entry of an XML document, e.g.


SYSTEM refers to a local definition, PUBLIC to a
DTD published on the web, in which case the URL
is preceeded by a 'well known URI'.
P. Martin - 2001 - XML - 2
44
E-business E-commerce
XML - Content Namespaces
The special characters - lt, gt, , ' and " can be
embedded in XML documents by inclusion in a CDATA
(character data) section as follows -


As users can define their own tags, there is the
possibility of naming clashes when using xml from
different sources. To prevent this, one or more
namespaces are defined in the top-level tag as
follows -
A namespace definition without a prefix defines
the default namespace for the document.
P. Martin - 2001 - XML - 3
45
E-business E-commerce
Document Type Definition
DTD's are essentially based on EBNF (extended
backus-naur form). They can be defined in-line in
an XML document -


or, in an external document, e.g. for XHTML -
They consist essentially of ELEMENT and ATTRIBUTE
definitions which define the allowed structure of
the document in terms of the ordering of elements
(tags), the content of element bodies and the
allowed attributes within tags.
P. Martin - 2001 - XML - 4
46
E-business E-commerce
Element Definition
lt!ELEMENT name (composition) gt With element
names a, b, c, and d - An empty element
a - lt!ELEMENT
a EMPTYgt Element a containing sequence
b, c, d - lt!ELEMENT a (b,c,d) gt
Element a containing either b, c or d -
lt!ELEMENT a (b c d) gt Element a
containing a repetiton of one or more b's
followed by c or d - lt!ELEMENT a (
b,(c d)) gt Element a containing
parseable character data (containing xml
markup)-

lt!ELEMENT a (PCDATA) gt Element a
containing character data (not including lt,gt,,'
or ") -
lt!ELEMENT
a (CDATA) gt Nested elements described by
bracketed expressions and repetition indicated by
- zero or more, one or more, ?
zero or one.

P. Martin - 2001 - XML - 5
47
E-business E-commerce
Attribute Definitions
lt!ATTLIST element-name attribute-name att-type
att-qualifiers gt Attribute types (att-type) can
be one of - CDATA - general character data
excluding special characters. ID - a unique
element identifier. IDREF - reference to an ID
defined elsewhere in the document. ENTITY -
defined using an ENTITY tag (see below)
ENTITIES - a space separated list of
entity-names. NMTOKEN - a character string
consisting of alphanumerics, colons,
periods, hyphens and
underscores only. enumerated - a list of values
e.g. (v1 v2 v3 ) followed by a
default. Attribute qualifiers (att-qualifiers)-
REQUIRED - an attribute must be supplied with
the tag. IMPLIED - can be omitted, value may be
deduced. FIXED - followed by the constant value.

P. Martin - 2001 - XML - 6
48
E-business E-commerce
Entity Definitions
lt!ENTITY entity-name "entity value" gt or
lt!ENTITY entity-name SYSTEM "file-name"
gt allows for the definition of XML entities.
These are similar to html entities and can be
referenced within a document by referring to them
as - entity-name Parameter entities
which allow document content to be parameterised
are defined using - lt!ENTITY entity-name
"entity-value" gt Useful in conditional sections
within DTD's e.g. -

P. Martin - 2001 - XML - 7
49
E-business E-commerce
XML/DTD example
In-line DTD
XML document
P. Martin - 2001 - XML - 8
50
E-business E-commerce
XML Schemas
DTD's do not allow accurate definition of xml
content - the main content types being CDATA and
PCDATA. Differentiating between text and
different numeric types is not possible. A more
recent development is to use XML Schemas to
provide document type definitions. These, as well
as providing a rich set of data types
are themselves XML documents. Two major schema
models have been developed - W3C XML
Schema - still under development.
Microsoft XML Schema - more advanced at this
time. Whilst XML Schema definitions are at an
early stage of evolution, we will take a brief
look at Microsoft's Schema model.
P. Martin - 2001 - XML - 9
51
E-business E-commerce
Microsoft XML Schema
The principle tags in the Microsoft model are
Schema and ElementType e.g. -
myMessage contains (optionally) a greeting,
consisting of text and/or messages any number of
times followed by a number of messages.
P. Martin - 2001 - XML - 10
52
E-business E-commerce
ElementType tag
ElementType tag attributes - content - values
can be empty, eltOnly, textOnly or mixed
(default) dttype - defines the data type - many
different types supported. name - name of the
element. model - closed (only elements defined
in schema are allowed) or open
(default). order - order of child elements -
one, seq (default for eltOnly) or
many (default for mixed). ElementType allowed
child elements - description -
documentation. datatype - specifies a data type
for the ElementType element. element - child
element name. group - defines a child element
group, order and frequency. AttributeType -
defines an attribute attribute - specifies an
attribute for an element.
P. Martin - 2001 - XML - 11
53
E-business E-commerce
element and group tags
element tag attributes - type - name of child
element minOccurs - minimum number of
occurrences - 0 or 1 - default 1 maxOccurs -
1 or - default 1 unless ElementType content
is mixed. group tag attributes - order -
one, seq or many. minOccurs - 0 or 1 - default
1. maxOccurs - 1 or - default 1 unless
ElementType content is mixed
P. Martin - 2001 - XML - 12
54
E-business E-commerce
AttributeType and attribute tags
AttributeType tag attributes - default -
attributes default value. dttype - attributes
data type. dtvalue - values for an enumeration
data type. name - attribute name. required -
yes or no - default is no. attribute tag
attributes - default - default value which
overrides any defined in AttributeType. type -
name of the AttributeType for the
attribute. required - yes or no - default is no.
P. Martin - 2001 - XML - 13
55
E-business E-commerce
Schema data types
The following is a sample of a few of the Schema
data types defined by Microsoft - boolean -
value 0(false) or 1(true) char - single
character string - series of characters float -
a real number int - an integer value date -
date in format YYYY-MM-DD time - time in format
HHMMSS id - text uniquely defining an element
or attribute idref - a reference to an
id enumeration - a series of values defining a
type.
P. Martin - 2001 - XML - 14
56
E-business E-commerce
Bookstore DTD as an XML Schema
P. Martin - 2001 - XML - 15
57
E-business E-commerce
Parseing XML documents
Two techniques are used for parseing XML
documents - DOM (document object model)
based parser These build a tree structure in
memory as the document is parsed and provide an
API to manipulate the tree. Two examples of such
parsers are Microsoft's msxml and Sun's JAXP.
SAX (simple API for xml) parsers SAX
based parsers generate events as tags are
encountered but do not build a tree. The
document is processed as it is read rather than
afterwards. Suitable more when document is not
to be modified.
P. Martin - 2001 - XML - 16
58
E-business E-commerce
Using a DOM XML Parser
Using Javascript within a web page and making use
of the Mcrosoft xml parser provides a simple way
of processing XML content. The following example
illustrates a program to extract structural
information from the DOM tree.
P. Martin - 2001 - XML - 17
59
E-business E-commerce
Javascript DOM API Nodes Types
DOM Parsers construct a tree containing nodes.
The node types are as shown in this list of
defined constants -
Some of the document methods return a Nodelist
object which has the methods and properties shown
here -
P. Martin - 2001 - XML - 18
60
E-business E-commerce
Javascript DOM API - Nodes
Node methods and properties are as follows-
P. Martin - 2001 - XML - 19
61
E-business E-commerce
Javascript DOM API - Document
At the top-level, the document object has the
following properties and methods -
P. Martin - 2001 - XML - 20
62
E-business E-commerce
Javascript DOM API - Element
Element objects have the following properties and
methods -
P. Martin - 2001 - XML - 21
63
E-business E-commerce
Javascript DOM API - Attribute
Finally, attributes have the following properties
and text has a split method -
This API allows xml documents to be loaded from
the server, parsed, transformed (e.g. into HTML)
modified and possibly returned to the server.
P. Martin - 2001 - XML - 22
64
E-business E-commerce
Processing a DOM tree in JAXP -1
P. Martin - 2001 - XML - 23
65
E-business E-commerce
Processing a DOM tree in JAXP -2
P. Martin - 2001 - XML - 24
66
E-business E-commerce
XPath trees
To refer to nodes within an xml DOM tree, the
simple string manipulation language XPath is
used. This provides notation and functions to
refer to subsets of the DOM tree. Although in
the DOM API, attributes of element nodes and
values of attributes or tag body content (e.g.
text) are themselves represented by nodes, this
is not true of the XPath view of the tree, e.g. -
an XPath tree
as a DOM tree
P. Martin - 2001 - XML - 25
67
E-business E-commerce
XPath expressions
All node path expressions are relative to a
context or current node. It is possible to refer
backwards or forwards from the context node to
other nodes, if they exist. Hence for the xml
given here, with the context node as reference-
self reference parent library child book anc
estor library ancestor-or-self library
reference descendant book, author,
title descendant-or-self reference, book,
author,title following loan following-siblin
g loan preceding none preceeding-sibling none
attribute type namespace none
P. Martin - 2001 - XML - 26
68
E-business E-commerce
XPath expressions
Nodes are of type element, attribute or namespace
and the path selector just given is followed by a
node test with the following meanings -
select all nodes of the same
type node() select all nodes text() select
all text nodes comment() select all comment
nodes processing-instruction() select all
processing instruction nodes ltnode namegt select
all nodes with ltnode namegt These node tests are
appended to the selector by a symbol, e.g.
child e.g. child/childtext() selects
all text node grandchildren of current node Some
common abbreviations are - child assumed
if no selector given attribute _at_ /descendant
-or-selfnode()/ // selfnode() . parentn
ode() ..
P. Martin - 2001 - XML - 27
69
E-business E-commerce
Node Sets
The path expressions seen so far produce sets on
nodes, which can be manipulated by functions and
operators as follows - Operators - union
of two nodesets / specifies the root of the xml
document Functions - last() returns the
number of nodes in the set position() returns
position number of current node in
nodeset count(nodeset) returns the number of
nodes in the nodeset id(string) returns element
node with matching ID etc String functions
- concat( ) concatenates two or more string
arguments starts-with() returns true if the
second (character) arg starts the first
(string) one. Predicates can be included in path
expressions enclosed in square brackets .
P. Martin - 2001 - XML - 28
70
E-business E-commerce
Example use of XPath
With the following xml -
These path expressions when used as an
argument to - doc.selectNodes(".....")
produce - Expression Result /catalog/cd/p
rice all price nodes /catalog/cd all cd
nodes /catalog/cd0 first cd node /catalog/cd/pr
ice/text() text from price nodes /catalog/cdprice
gt 10.80 cd's with price gt10.80 /catalog/cdprice
gt10.80/price price nodes for cd's with
price gt 10.80
P. Martin - 2001 - XML - 29
71
E-business E-commerce
XSL(T) XML Stylesheets
XSL and XSLT are xml standards which allow for
the creation of stylesheets - which behave very
much like cascading stylesheets (CSS) with html,
for transforming and formatting xml
documents. XSLT XML transformation stylesheets
allow (for example) an xml document to be
presented as an html document, with at the same
time performing some processing on the document
such as selecting only certain nodes and sorting
them into a required order. The following
example takes a cd collection database held as an
XML file and generates an html table containing
cetain selected items in sorted order, with
specific one of interest highlighted -
P. Martin - 2001 - XSL - 1
72
E-business E-commerce
CD database example - 1
First, an extract from the database -
P. Martin - 2001 - XSL - 2
73
E-business E-commerce
CD database example - 2
Then the stylesheet -
P. Martin - 2001 - XSL - 3
74
E-business E-commerce
CD database example - 3
Finally, using ActiveX objects to transform the
xml using the stylesheet-
P. Martin - 2001 - XSL - 4
75
E-business E-commerce
Sports XML transform - 1
XSLT can also be used to alter an XML document as
the following example illustrates -
lt?xml version "1.0"?gt ltsportsgt ltgame title
"cricket"gt ltidgt243lt/idgt ltparagt
More popular among commonwealth nations
lt/paragt lt/gamegt ltgame title "baseball"gt
ltidgt431lt/idgt ltparagt More
popular in America lt/paragt lt/gamegt
ltgame title "soccer"gt ltidgt123lt/idgt
ltparagt Most popular sport in the world
lt/paragt lt/gamegt lt/sportsgt
P. Martin - 2001 - XSL - 5
76
E-business E-commerce
Sports XML transform - 2
The following stylesheet transforms the structure
of the XML document -
lt?xml version "1.0" ?gt ltxslstylesheet version
"1.0" xmlnsxsl "http//www/w3.org/1999/XSL/Tra
nsform"gt ltxsltemplate match "/"gt
ltxslapply-templates/gt lt/xsltemplategt ltxsltempl
ate match "sports"gt ltsportsgt
ltxslapply-templates/gt lt/sportsgt lt/xsltemplate
gt ltxsltemplate match "game"gt ltxslelement
name "_at_title"gt ltxslattribute name
"id"gt ltxslvalue-of-select "id"/gt
lt/xslattributegt ltcommentgt
ltxslvalue-of select "para"/gt lt/commentgt
lt/xslelementgt lt/xslstylesheetgt
P. Martin - 2001 - XSL - 6
77
E-business E-commerce
Sports XML transform - 3
The resulting XML document then becomes -
P. Martin - 2001 - XSL - 7
78
E-business E-commerce
Importing including stylesheets
Stylesheets cascade rather like CSS ones. If an
XML document includes or imports a stylesheet,
the stylesheet controls the transformation of the
xml. If the stylesheet itself imports or
includes other stylesheets, the templates defined
in each complement (or override) each
other. Importing and Including differ as follows
- import - imported templates have a higher
precedence than locally defined
ones. include - included templates have the
same level of precedence the one defined
latest in sequence is the one used.
P. Martin - 2001 - XSL - 8
79
E-business E-commerce
Example of importing stylesheet
The following example illustrates the use of
import - First the stylesheet
intro.xsl - Then the xml
document - Finally the
resulting html -
P. Martin - 2001 - XSL - 9
80
E-business E-commerce
Stylesheet elements
Element
Description xslappl
y-imports Applies a template from an imported
stylesheet xslapply-templates Applies a template
to the current element xslattribute Adds an
attribute to the nearest containing
element xslattribute-set Defines a named set of
attributes xslcall-template Provides a way to
call a named template xslchoose Provides a way
to choose between a number of alternatives based
on conditions xslcomment Creates an XML
comment xslcopy Copies the current node without
childnodes and attributes to the
output xslcopy-of Copies the current node with
childnodes and attributes to the
output xsldecimal-format Defines
character/string to be used in converting numbers
to strings xslelement Adds a new element node
to the output xslfallback Provides a way to
define an alternative for not implemented
instructions xslfor-each Provides a way to
create a loop in the output stream. xslif Provid
es a way to write a conditional
statement xslimport Imports a
stylesheet xslinclude Includes a
stylesheet xslkey Provides a way to define a
key xslmessage Writes a message to the
output xslnamespace-alias Provides a way to map
a namespace to another namespace xslnumber Write
s a formatted number to the output xslotherwise I
ndicates what happens when no ltxslwhengt element
is satisfied xsloutput Provides a way to
control the transformed output xslparam Provides
a way to define parameters xslpreserve-space Pro
vides a way to define the handling of
white-space xslprocessing-instruction Writes a
processing instruction to the output xslsort Pro
vides a way to define sorting xslstrip-space Prov
ides a way to define the handling of
white-space xslstylesheet Defines the root
element of the style sheet xsltemplate Defines
a template for output xsltext Writes text to
the output xsltransform Defines the root element
of the style sheet xslvalue-of Creates a text
node and inserts a value into the result
tree xslvariable Provides a way to declare a
variable xslwhen Defines a condition to be
tested and performs an action if the condition is
true. xslwith-param Provides a way to pass
parameters to templates
P. Martin - 2001 - XSL - 10
81
E-business E-commerce
Simple Object Access Protocol - SOAP
Based on the use of XML, SOAP uses HTTP for
communication of XML messages using messaging
systems which facilitate synchronous and
asynchronous B2B communications. SOAP also
supports RPC, making distributed processing easy
and avoiding problems with coporate firewalls. A
SOAP message is encoded in a SOAP envelope e.g. -
P. Martin - 2001 - XSL - 11
82
E-business E-commerce
SOAP Simple example
The following simple example allows a client to
obtain a stock quote from a server -
The SOAP request -
The SOAP response -
P. Martin - 2001 - XSL - 12
83
E-business E-commerce
Microsoft's BizTalk
BizTalk is a system developed by Microsoft to
enable companies (particularly SME's) to develop
B2B systems over the web. Uses the SOAP
protocol for transmitting XML documents over
HTTP Provides a messaging service to support
synchronous and asynchronous communication. Su
pports RPC. Provides a user extensible Schema
library of standard ducument types. Publishes
a framework of guidelines for developing new
schemas. Provides a BizTalk server. XML
messages are transformed to client formats using
XSLT.
P. Martin - 2001 - XSL - 12
Write a Comment
User Comments (0)
About PowerShow.com