Java Reference
In-Depth Information
UserService
In this example you'll expose a new
createUser
method on the
UserService
state-
less session bean. But instead of starting with Java objects, you'll start with the WSDL and
XSD files.
The existing
createUser
method on
UserService
takes a
com.actionbazaar
.account.User
object as input. This object is abstract; has subclasses
Bidder
,
Em-
ployee
, and
SellerI
; and also has references to other objects. Auto-generating a web
service from such a complicated object may produce a WSDL with unexpected dependen-
cies and may be incompatible with other programming languages.
To avoid these problems, the new
createUser
method on
UserService
will use a
data transfer object (DTO). A DTO is a simplified version of your domain model objects
created specifically for interoperable data transfer. Because DTOs don't have complicated
object graphs, tools can handle them more easily. In this case, you'll start by creating the
XSD schema for a
UserDTO
object in the following listing.
Listing 8.3. Creating UserDTO.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
version="1.0"
targetNamespace="http://com.actionbazaar/user"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://com.actionbazaar/user"
elementFormDefault="qualified">
<xs:element name="user" type="tns:UserDTO"/>
<xs:element name="createUserResponse" type="tns:CreateUserResponse"/>
<xs:complexType name="UserDTO">
<xs:sequence>
<xs:element id="firstName" name="firstName" type="xs:string"
minOccurs="1" maxOccurs="1" nillable="false"/>
<xs:element id="lastName" name="lastName" type="xs:string"
minOccurs="1" maxOccurs="1" nillable="false"/>
<xs:element id="birthDate" name="birthDate" type="xs:date"
minOccurs="1" maxOccurs="1" nillable="false"/>
<xs:element id="username" name="username" type="xs:string"
minOccurs="1" maxOccurs="1" nillable="false"/>
<xs:element id="password" name="password" type="xs:string"
minOccurs="1" maxOccurs="1" nillable="false"/>
<xs:element id="email" name="email" type="xs:string"
minOccurs="1" maxOccurs="1" nillable="false"/>
</xs:sequence>