@Loggable(value=1) public final class PageBuilder extends Object
First, you should create a base class, which will be used by all pages. (they all will inherit it). The base class should be JAXB annotated, for example:
@XmlRootElement(name = "page")
public class MyPage extends BasePage {
public String title;
public BasePage title(String text) {
this.title = text;
}
@XmlElement
public String getTitle() {
return this.title;
}
}
Then, in JAX-RS resource you instantiate and extend this class with
application/request specific content (we think that suffix Rs
is a good notation for all JAX-RS resources):
@Path("/")
public class MainRs {
@GET
@Produces(MediaTypes.APPLICATION_XML)
public MyPage front() {
return new PageBuilder()
.stylesheet("/xsl/front.xsl")
.build(MyPage.class)
.append(new JaxbBundle("score", 2))
.title("Hello, world!");
}
}
That's it. The XML produced by JAX-RS and JAXB will look like:
<?xml version="1.0" ?> <?xml-stylesheet type='text/xsl' href='/xsl/front.xsl'?> <page> <score>2</score> <title>Hello, world!</title> </page>
We recommend to extend BasePage, since it already implements
a few most popular and necessary methods and properties.
The class is mutable and thread-safe.
BasePage,
JaxbGroup,
JaxbBundle| Constructor and Description |
|---|
PageBuilder() |
| Modifier and Type | Method and Description |
|---|---|
<T> T |
build(Class<T> base)
Create new class.
|
PageBuilder |
schema(String name)
Configure the schema to be used.
|
PageBuilder |
stylesheet(String uri)
Configure the stylesheet to be used.
|
@NotNull public PageBuilder stylesheet(@NotNull String uri)
uri - The URI of the stylesheet@NotNull public PageBuilder schema(@NotNull String name)
name - Name of schema@NotNull
public <T> T build(@NotNull
Class<T> base)
T - The type of result expectedbase - Parent class, which will be inheritedCopyright © 2011–2014 ReXSL.com. All rights reserved.