|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.rexsl.page.JaxbBundle
public final class JaxbBundle
JAXB bundle.
It's a convenient instrument that enables on-fly creation of DOM/XML structures, for example (fluent interface):
final org.w3c.dom.Element elm = new JaxbBundle("root")
.add("employee")
.attr("age", "28")
.add("dept", "Software")
.attr("country", "DE")
.up()
.add("salary", "> \u20AC 50,000")
.up()
.add("rank", "high")
.up()
.attr("time", new Date())
.element();
If you convert this elm to XML this is how it will look:
<?xml version="1.0" ?>
<root time="Sun Jul 20 16:17:00 EDT 1969">
<employee age="28">
<dept country="DE">Software</dept>
<salary>> € 50,000</salary>
<rank>high</rank>
</employee>
</root>
Then, you can add this Element to your JAXB object, and return
it from a method annotated with XmlElement,
for example:
@XmlRootElement
public class Page {
@XmlElement
public Object getEmployee() {
return new JaxbBundle("employee")
.attr("age", "35")
.attr("country", "DE")
.add("salary", "> \u20AC 50,000")
.up()
.element();
}
}
This mechanism, very often, is much more convenient and shorter than a declaration of a new POJO every time you need to return a small piece of XML data.
The class is mutable and thread-safe.
| Constructor Summary | |
|---|---|
JaxbBundle()
Default ctor, for JAXB (always throws a runtime exception). |
|
JaxbBundle(String nam)
Public ctor, with just a name of XML element an no content. |
|
JaxbBundle(String nam,
Object text)
Public ctor, with XML element name and its content. |
|
| Method Summary | |
|---|---|
JaxbBundle |
add(String nam)
Add new child XML element. |
JaxbBundle |
add(String nam,
Object txt)
Add new child with text value. |
JaxbBundle |
attr(String nam,
Object val)
Add XML attribute to this bundle. |
Element |
element()
Convert this bundle into DOM/XML Element. |
JaxbBundle |
up()
Return parent bundle. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public JaxbBundle()
public JaxbBundle(@NotNull
String nam)
nam - The name of it
public JaxbBundle(@NotNull
String nam,
Object text)
nam - The name of XML elementtext - Plain text content| Method Detail |
|---|
public JaxbBundle add(@NotNull
String nam)
nam - The name of child element
up() on it in order to get back to
this object)
public JaxbBundle add(@NotNull
String nam,
@NotNull
Object txt)
nam - The name of childtxt - The text
up() on it in order to get back to
this object)
public JaxbBundle attr(@NotNull
String nam,
@NotNull
Object val)
nam - The name of attributeval - The plain text value
public JaxbBundle up()
public Element element()
Element.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||