Package org.igniterealtime.jbosh
Class ComposableBody
java.lang.Object
org.igniterealtime.jbosh.AbstractBody
org.igniterealtime.jbosh.ComposableBody
Implementation of the
AbstractBody
class which allows for the
definition of messages from individual elements of a body.
A message is constructed by creating a builder, manipulating the
configuration of the builder, and then building it into a class instance,
as in the following example:
ComposableBody body = ComposableBody.builder() .setNamespaceDefinition("foo", "http://foo.com/bar") .setPayloadXML("invalid input: '<'foo:data>Data to send to remote serverinvalid input: '<'/foo:data>") .build();Class instances can also be "rebuilt", allowing them to be used as templates when building many similar messages:
ComposableBody body2 = body.rebuild() .setPayloadXML("invalid input: '<'foo:data>More data to sendinvalid input: '<'/foo:data>") .build();This class does only minimal syntactic and semantic checking with respect to what the generated XML will look like. It is up to the developer to protect against the definition of malformed XML messages when building instances of this class. Instances of this class are immutable and thread-safe.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
Class instance builder, after the builder pattern. -
Field Summary
FieldsModifier and TypeFieldDescriptionMap of all attributes to their values.private static final Pattern
Pattern used to identify the beginningbody
element of a BOSH message.private final AtomicReference
<String> Computed raw XML.private final String
Payload XML. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
ComposableBody
(Map<BodyQName, String> attrMap, String payloadXML) Prevent direct construction. -
Method Summary
Modifier and TypeMethodDescriptionstatic ComposableBody.Builder
builder()
Create a builder instance to build new instances of this class.private String
Generate a String representation of the message body.private String
Escape the value of an attribute to ensure we maintain valid XML syntax.(package private) static ComposableBody
fromStaticBody
(StaticBody body) Parse a static body instance into a composable instance.Get a map of all defined attribute names with their corresponding values.Get the paylaod XML in String form.rebuild()
If thisComposableBody
instance is a dynamic instance, uses thisComposableBody
instance as a starting point, create a builder which can be used to create anotherComposableBody
instance based on this one.toXML()
Get an XML String representation of this message.Methods inherited from class org.igniterealtime.jbosh.AbstractBody
getAttribute, getAttributeNames, getBodyQName
-
Field Details
-
BOSH_START
Pattern used to identify the beginningbody
element of a BOSH message. -
attrs
Map of all attributes to their values. -
payload
Payload XML. -
computed
Computed raw XML.
-
-
Constructor Details
-
ComposableBody
Prevent direct construction. This constructor is for body messages which are dynamically assembled.
-
-
Method Details
-
fromStaticBody
Parse a static body instance into a composable instance. This is an expensive operation and should not be used lightly. The current implementation does not obtain the payload XML by means of a proper XML parser. It uses some string pattern searching to find the first @{code body} element and the last element's closing tag. It is assumed that the static body's XML is well formed, etc.. This implementation may change in the future.- Parameters:
body
- static body instance to convert- Returns:
- composable body instance
- Throws:
BOSHException
-
builder
Create a builder instance to build new instances of this class.- Returns:
- AbstractBody instance
-
rebuild
If thisComposableBody
instance is a dynamic instance, uses thisComposableBody
instance as a starting point, create a builder which can be used to create anotherComposableBody
instance based on this one. This allows aComposableBody
instance to be used as a template. Note that the use of the returned builder in no way modifies or manipulates the currentComposableBody
instance.- Returns:
- builder instance which can be used to build similar
ComposableBody
instances
-
getAttributes
Get a map of all defined attribute names with their corresponding values.- Specified by:
getAttributes
in classAbstractBody
- Returns:
- map of qualified attributes
-
toXML
Get an XML String representation of this message.- Specified by:
toXML
in classAbstractBody
- Returns:
- XML string representing the body message
-
getPayloadXML
Get the paylaod XML in String form.- Returns:
- payload XML
-
escape
Escape the value of an attribute to ensure we maintain valid XML syntax.- Parameters:
value
- value to escape- Returns:
- escaped value
-
computeXML
Generate a String representation of the message body.- Returns:
- XML string representation of the body
-