|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
aktbus.core.AktMessage
The AKTMessage class represents an AKT message according to the AKT-Bus white paper. It provides methods to compose and manipulate AKT messages, including sending an AKT message to a specific URL.
Field Summary | |
protected java.util.HashMap |
name_space
|
Constructor Summary | |
AktMessage()
Creates an empty AktMessage. |
|
AktMessage(org.xml.sax.InputSource source)
Constructs an AktMessage by reading from an org.xml.sax.InputSource. |
|
AktMessage(java.lang.String message_to_parse)
Constructs an AktMessage by parsing an XML string. |
|
AktMessage(java.lang.String sender,
java.lang.String receiver,
java.lang.String simple_content)
Creates an AktMessage with <aktbus:SimpleContent> ,
using String for URLs. |
|
AktMessage(java.net.URL sender,
java.net.URL receiver,
boolean parse_content,
java.lang.String content)
A general constructor that creates an AktMessage. |
|
AktMessage(java.net.URL sender,
java.net.URL receiver,
org.w3c.dom.Node content)
Creates an AktMessage using the sender and reciever URIs and appends the content node as the content of the message. |
|
AktMessage(java.net.URL sender,
java.net.URL receiver,
java.lang.String simple_content)
Creates an AktMessage from a String. |
Method Summary | |
org.w3c.dom.Node |
createDOM(com.sun.xml.tree.XmlDocument parent,
java.net.URL sender,
java.net.URL receiver,
org.w3c.dom.Node content)
Creates an AktMessage as an XmlDocument, with proper header information and Node content as the message content. |
com.sun.xml.tree.ElementNode |
find_element_node(com.sun.xml.tree.ElementNode root,
java.lang.String tagname)
Search for an ElementNode with a given tag-name under a subtree by depth-first-search. |
com.sun.xml.tree.ElementNode |
find_element_node(java.lang.String tagname)
Given the tag, find an ElementNode in an AktMessage object by depth-first-search. |
java.lang.String |
get_element_node_text(com.sun.xml.tree.ElementNode parent,
java.lang.String tag_name)
Get the value of the 1st TextNode after a certain ElementNode. |
java.lang.String |
get_element_node_text(java.lang.String tag_name)
Get the value of the 1st TextNode under a certain ElementNode, start search from the root. |
org.w3c.dom.Node |
get_first_child_node(com.sun.xml.tree.ElementNode parent,
int type_wanted)
Get the first child node of a specific type under the current ElementNode. |
org.w3c.dom.Node |
get_first_child_node(com.sun.xml.tree.ElementNode parent,
java.lang.String node_name,
int type_wanted)
Get the first child node matching an optional node_name & type. |
org.w3c.dom.Node |
get_next_sibling_node(com.sun.xml.tree.ElementNode current_node,
int type_wanted)
Find the next sibling of an ElementNode with a specific type. |
org.w3c.dom.Node |
get_next_sibling_node(com.sun.xml.tree.ElementNode current_node,
java.lang.String node_name,
int type_wanted)
Find the next sibling of an com.sun.xml.tree.ElementNode with a specific type, matching an optional node_name . |
java.lang.String |
get_receiver()
Find the receiver URI in an AktMessage and return it as a String. |
java.lang.String |
get_sender()
Find the sender URI in an AktMessage and return it as a String. |
java.lang.String |
get_simple_message()
Find the content of the <aktbus:hasSimpleMessage> element. |
java.lang.String |
get_subtree_text(org.w3c.dom.Node n)
Return the subtree under the given node as a String. |
java.lang.String |
get_subtree_text(org.w3c.dom.Node n,
boolean translate)
Return the subtree under the given node as a String with optional entity references translation. |
protected void |
initialise_namespace()
Initialise the field name_space to contain the HashMap of default XML name space definition. |
static void |
print_node_type(org.w3c.dom.Node node)
Print out the type of a node according to the org.w3c.dom.Node class. |
void |
print_tree_type(aktbus.core.Node n)
Print out all nodes' type in the XML tree. |
AktMessage |
send_and_receive()
Send to receiver and waits for reply from the same connection. |
AktMessage |
send_and_receive(java.net.URL receiver_uri,
int timeout,
java.lang.Class result_class)
Send to receiver and waits for reply from the same connection. |
void |
send()
Send an AktMessage with blocking, using specified receiver URI in the AktMessage object. |
void |
send(int timeout)
Send to the receiver as specified in the AktMessage, with timeout. |
void |
send(java.net.URL receiver_uri,
int timeout)
Sends an AktMessage to a certain recipient. |
void |
ugly_write()
Ugly-printing an AktMessage to stdout without any translation of escape char (entity reference). |
void |
ugly_write(boolean translate)
Ugly-printing an AktMessage to stdout. |
void |
ugly_write(java.io.OutputStream out)
Ugly-printing an AktMessage to an OutputStream. |
void |
ugly_write(java.io.OutputStream out,
boolean translate)
Ugly-printing an AktMessage to a OutputStream. |
void |
ugly_write(java.io.Writer out)
Ugly-printing an AktMessage to a Writer. |
void |
ugly_write(java.io.Writer out,
boolean translate)
Ugly-printing an AktMessage to a Writer. |
void |
ugly_write(java.io.Writer out,
java.lang.String encoding)
Ugly-printing an AktMessage to a Writer, using a certain encoding. |
void |
ugly_write(java.io.Writer out,
java.lang.String encoding,
boolean translate)
Ugly-printing an AktMessage to a Writer, using a certain encoding. |
Field Detail |
protected java.util.HashMap name_space
Constructor Detail |
public AktMessage()
public AktMessage(java.lang.String message_to_parse) throws org.xml.sax.SAXException, java.lang.Exception
message_to_parse
- The string to be parsed.org.xml.sax.SAXException
- When a parse error is encounted.java.lang.Exception
- When a general exception is found.public AktMessage(org.xml.sax.InputSource source) throws org.xml.sax.SAXException, java.lang.Exception
source
- InputSource to read from.org.xml.sax.SAXException
- When a parsing error occurs.java.lang.Exception
- When other general erros occur.public AktMessage(java.net.URL sender, java.net.URL receiver, boolean parse_content, java.lang.String content) throws org.xml.sax.SAXException, java.lang.Exception
parse_content
is false, content
is treated as plain text without any XML parsing.
In this case it is put inside the default XML element parse_content
is true, the string content
is parsed to form
an XML subtree which will be inserted as the content of the message.sender
- The URL of the sender.receiver
- The URL of the receiver.parse_content
- A boolean flag indicating if the content is to be parsed as XML.content
- The content of the message.org.xml.sax.SAXException
- When a parsing error occurs.java.lang.Exception
- When other general error occur.public AktMessage(java.net.URL sender, java.net.URL receiver, org.w3c.dom.Node content) throws java.net.MalformedURLException, java.lang.Exception
sender
- The URI of the sender of the message.receiver
- The URI of the receiver of the message.content
- The Node (subtree) to be the content of the message.java.net.MalformedURLException
- When either URI is invalid.java.lang.Exception
- On other general errors.public AktMessage(java.net.URL sender, java.net.URL receiver, java.lang.String simple_content) throws org.xml.sax.SAXException, java.lang.Exception
sender
- The sender of the AktMessage.receiver
- The receiver of the AktMessage.simple_content
- A String forming the simple content of the AktMessage.public AktMessage(java.lang.String sender, java.lang.String receiver, java.lang.String simple_content) throws java.net.MalformedURLException, org.xml.sax.SAXException, java.lang.Exception
<aktbus:SimpleContent>
,
using String for URLs.sender
- The sender URL in a String.receiver
- The receiver URL in a String.simple_content
- The message content in a String.java.net.MalformedURLExcpetion
- When either sender/reciver URI is not valid.org.xml.sax.SAXException
- When simple_content
cannot be parsed as XML.java.lang.Exception
- On other general errors.Method Detail |
public org.w3c.dom.Node createDOM(com.sun.xml.tree.XmlDocument parent, java.net.URL sender, java.net.URL receiver, org.w3c.dom.Node content) throws java.net.MalformedURLException, java.lang.Exception
parent
- The parent XmlDocument object.sender
- The sender of this AktMessage.receiver
- The receiver of this AktMessage.content
- A Node containing the subtree as the AktMessage content.java.net.MalformedURLExcpetion
- When either sender/reciver URI is not valid.java.lang.Exception
- On other general errors.public com.sun.xml.tree.ElementNode find_element_node(java.lang.String tagname)
get_first_child_node()
to
look for its child which is a text node.
Then get the value of the text node by getNodeValue()
.tagname
- The name of the node to find.null
otherwise.public com.sun.xml.tree.ElementNode find_element_node(com.sun.xml.tree.ElementNode root, java.lang.String tagname)
root
- The root of the subtree to searchtagname
- The name of the node to find.null
otherwise.public java.lang.String get_subtree_text(org.w3c.dom.Node n)
n
- The node under which the text node of the subtree is to be extracted.public java.lang.String get_subtree_text(org.w3c.dom.Node n, boolean translate)
n
- The node under which the text node of the subtree is to be extracted.translate
- A boolean flag specifying if entity reference translation is needed.public org.w3c.dom.Node get_first_child_node(com.sun.xml.tree.ElementNode parent, int type_wanted) throws java.lang.Exception
parent
- The parent node under which we search for its children.type_wanted
- The type of node we are looking for.
It is defined in org.w3c.dom.Node.
Some of the valid values are:
ELEMENT_NODE
,
ATTRIBUTE_NODE
,
TEXT_NODE
.java.lang.Exception
- When an error occurs.public org.w3c.dom.Node get_first_child_node(com.sun.xml.tree.ElementNode parent, java.lang.String node_name, int type_wanted) throws java.lang.Exception
parent
- The Node under which we look for the child.node_name
- An optional node name to match. Specify null
to ignore it.type_wanted
- The node type to match.null
if not found.java.lang.Exception
- When an error occurs.public org.w3c.dom.Node get_next_sibling_node(com.sun.xml.tree.ElementNode current_node, int type_wanted) throws java.lang.Exception
parent
- The parent node, which is an com.sun.xml.tree.ElementNode.java.lang.Exception
- When an error occurs.public org.w3c.dom.Node get_next_sibling_node(com.sun.xml.tree.ElementNode current_node, java.lang.String node_name, int type_wanted) throws java.lang.Exception
node_name
.parent
- The parent node, which is an com.sun.xml.tree.ElementNode.java.lang.Exception
- When an error occurs.public java.lang.String get_element_node_text(java.lang.String tag_name)
get_first_child_node
and
get_next_sibling_node methods()
.tag_name
- The tagname of the ElementNode to search.null
if cannot find it.public java.lang.String get_element_node_text(com.sun.xml.tree.ElementNode parent, java.lang.String tag_name) throws java.lang.Exception
get_first_child_node()
and
get_next_sibling_node methods()
.parent
- The ElementNode to start searching.tag_name
- The tagname of the ElementNode to search.public java.lang.String get_sender() throws java.net.MalformedURLException, java.lang.Exception
java.net.MalformedURLException
- When the returned String is not a valid URL.java.lang.Exception
- When other errors occur.public java.lang.String get_receiver() throws java.net.MalformedURLException, java.lang.Exception
java.net.MalformedURLException
- When the returned String is not a valid URL.java.lang.Exception
- When other errors occur.public java.lang.String get_simple_message() throws java.lang.Exception
<aktbus:hasSimpleMessage>
element.<aktbus:hasSimpleMessage>
in a string.java.lang.Exception
- When an error occurs.public void send() throws java.lang.Exception, java.io.IOException, java.io.InterruptedIOException
java.lang.Exception
- When a general error occurs.java.io.IOException
- When I/O-related error occurs.java.io.InterruptedIOException
- When a timeout occurs.public void send(int timeout) throws java.lang.Exception, java.io.IOException, java.io.InterruptedIOException
timeout
- The timeout (in second) on the connection to the receiver.java.lang.Exception
- When a general error occurs.java.io.IOException
- When I/O-related error occurs.java.io.InterruptedIOException
- When a timeout occurs.public void send(java.net.URL receiver_uri, int timeout) throws java.lang.Exception, java.io.IOException, java.io.InterruptedIOException
sender_uri
- The URL of the sender. A null
means piggy-packed reply.receiver_uri
- The URL of the receiver.timeout
- The timeout value waiting for a response from the other side, in second.java.lang.Exception
- When sending fails. i.e. reply is not OK.java.io.IOException
- When I/O-related error occurs.java.io.InterruptedIOException
- When a timeout occurs.public AktMessage send_and_receive() throws java.io.IOException, java.io.InterruptedIOException, java.net.MalformedURLException, java.lang.Exception
java.net.MalformedURLException
- When the receiver URI is not valid.java.io.IOException
- When I/O-related error occurs.java.io.InterruptedIOException
- When a timeout occurs.java.lang.Exception
- When sending fails. i.e. reply is not OK.public AktMessage send_and_receive(java.net.URL receiver_uri, int timeout, java.lang.Class result_class) throws java.io.IOException, java.io.InterruptedIOException, java.net.MalformedURLException, java.lang.Exception
receiver_uri
- The URL of the receiver.timeout
- The timeout value waiting for a response from the other side, in second.result_class
- The class of the expected reply as a java.lang.Class object.java.net.MalformedURLException
- When the receiver URI is not valid.java.io.IOException
- When I/O-related error occurs.java.io.InterruptedIOException
- When a timeout occurs.java.lang.Exception
- When sending fails. i.e. reply is not OK.public void ugly_write() throws java.io.IOException
java.io.IOException
- When an I/O error occurs in writing.public void ugly_write(boolean translate) throws java.io.IOException
translate
- A boolean flag. True if translation wanted, false otherwise.java.io.IOException
- When an I/O error occurs in writing.public void ugly_write(java.io.OutputStream out) throws java.io.IOException
out
- The OutputStream where the message will be ugly-printed.java.io.IOException
- When an I/O error occurs in writing.public void ugly_write(java.io.OutputStream out, boolean translate) throws java.io.IOException
out
- The OutputStream where the message will be ugly-printed.translate
- true
to have entity references translated into characters, false
otherwise.java.io.IOException
- When an I/O error occurs in writing.public void ugly_write(java.io.Writer out) throws java.io.IOException
out
- The Writer where the message will be ugly-printed.java.io.IOException
- When an I/O error occurs in writing.public void ugly_write(java.io.Writer out, boolean translate) throws java.io.IOException
out
- The Writer where the message will be ugly-printed.translate
- true
to have entity references translated into characters, false
otherwise.java.io.IOException
- When an I/O error occurs in writing.public void ugly_write(java.io.Writer out, java.lang.String encoding) throws java.io.IOException
out
- The Writer where the message will be ugly-printed.encoding
- The encoding to use.java.io.IOException
- When an I/O error occurs in writing.public void ugly_write(java.io.Writer out, java.lang.String encoding, boolean translate) throws java.io.IOException
out
- The Writer where the message will be ugly-printed.encoding
- The encoding to use.translate
- true
to have entity references translated into characters, false
otherwise.java.io.IOException
- When an I/O error occurs in writing.public void print_tree_type(aktbus.core.Node n)
n
- The org.w3c.dom.Node from which we start to print in a deep-first manner.public static void print_node_type(org.w3c.dom.Node node)
node
- The node whose type is to be printed.protected void initialise_namespace()
name_space
to contain the HashMap of default XML name space definition.
When you extend the AktMessage, you may want to add more XML name space definitions.
You can do so by overriding this method and put
more definition into the field name_space
,
which is a HashMap.
Remember to call the superclass' initialise_namespace()
before adding, if you want to include
the default AktMessage XML name space definition.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |