Java Reference
In-Depth Information
Next, the code iterates through all the
CustomerEntity
objects returned by the executed
query and creates
Customer
JAXB object instances.
// next link
// If the size returned is equal then assume there is a next
iif
(
customerEntities
.
size
() ==
size
)
{
int
int
next
=
start
+
size
;
URI nextUri
=
builder
.
clone
().
build
(
next
,
size
);
Link nextLink
=
Link
.
fromUri
(
nextUri
)
.
rel
(
"next"
)
.
type
(
"application/xml"
).
build
();
links
.
add
(
nextLink
);
}
// previous link
iif
(
start
>
0
)
{
int
int
previous
=
start
-
size
;
iif
(
previous
<
0
)
previous
=
0
;
URI previousUri
=
builder
.
clone
().
build
(
previous
,
size
);
Link previousLink
=
Link
.
fromUri
(
previousUri
)
.
rel
(
"previous"
)
.
type
(
"application/xml"
).
build
();
links
.
add
(
previousLink
);
}
Customers customers
=
new
new
Customers
();
customers
.
setCustomers
(
list
);
customers
.
setLinks
(
links
);
return
return
customers
;
}
}
Finally, the method calculates whether the
next
and
previous
Atom links should be added
to the
Customers
JAXB object returned. This code is very similar to the examples described
in
Chapter 24
.
The other EJB classes defined in the example are pretty much extrapolated from the
ex10_2
example and modified to work with JPA. I don't want to rehash old code, so I won't get into
detail on how these work.
The Remaining Server Code
There's a few more server-side classes we need to go over.