|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.freecol.common.networking.Message
public class Message
Class for parsing raw message data into an XML-tree and for creating new XML-trees.
Constructor Summary | |
---|---|
Message(org.w3c.dom.Document document)
Constructs a new Message with data from the given XML-document. |
|
Message(java.io.InputStream inputStream)
Constructs a new Message with data from the given InputStream. |
|
Message(java.lang.String msg)
Constructs a new Message with data from the given String. |
Method Summary | |
---|---|
static org.w3c.dom.Element |
clientError(java.lang.String message)
Creates an error message in response to bad client data. |
static org.w3c.dom.Element |
createError(java.lang.String messageID,
java.lang.String message)
Creates an error message. |
static void |
createError(javax.xml.stream.XMLStreamWriter out,
java.lang.String messageID,
java.lang.String message)
Creates an error message. |
static org.w3c.dom.Document |
createNewDocument()
Creates and returns a new XML-document. |
static org.w3c.dom.Element |
createNewRootElement(java.lang.String tagName)
Creates a new root element. |
java.lang.String |
getAttribute(java.lang.String key)
Gets an attribute from the root element. |
static org.w3c.dom.Element |
getChildElement(org.w3c.dom.Element element,
java.lang.String tagName)
Convenience method: returns the first child element with the specified tagname. |
org.w3c.dom.Document |
getDocument()
Gets the Document holding the message data. |
static java.lang.String |
getFreeColProtocolVersion()
Gets the current version of the FreeCol protocol. |
java.lang.String |
getType()
Gets the type of this Message. |
boolean |
hasAttribute(java.lang.String attribute)
Checks if an attribute is set on the root element. |
void |
insertAsRoot(org.w3c.dom.Element newRoot)
Inserts newRoot as the new root element and appends the
old root element. |
boolean |
isType(java.lang.String type)
Checks if this message is of a given type. |
void |
setAttribute(java.lang.String key,
int value)
Sets an attribute on the root element. |
void |
setAttribute(java.lang.String key,
java.lang.String value)
Sets an attribute on the root element. |
java.lang.String |
toString()
Returns the String representation of the message. |
org.w3c.dom.Element |
toXMLElement()
|
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Message(java.lang.String msg) throws org.xml.sax.SAXException, java.io.IOException
msg
- The raw message data.
java.io.IOException
- should not be thrown.
org.xml.sax.SAXException
- if thrown during parsing.public Message(java.io.InputStream inputStream) throws org.xml.sax.SAXException, java.io.IOException
inputStream
- The InputStream
to get the XML-data
from.
java.io.IOException
- if thrown by the InputStream
.
org.xml.sax.SAXException
- if thrown during parsing.public Message(org.w3c.dom.Document document)
document
- The document representing an XML-message.Method Detail |
---|
public static java.lang.String getFreeColProtocolVersion()
public static org.w3c.dom.Document createNewDocument()
public static org.w3c.dom.Element createNewRootElement(java.lang.String tagName)
tagName
- The tag name of the root element beeing created,
public static org.w3c.dom.Element createError(java.lang.String messageID, java.lang.String message)
messageID
- Identifies the "i18n"-keyname. Not specified in the
message if null.message
- The error in plain text. Not specified in the message if
null.
Element
of the error message.public static void createError(javax.xml.stream.XMLStreamWriter out, java.lang.String messageID, java.lang.String message)
out
- The output stream for the message.messageID
- Identifies the "i18n"-keyname. Not specified in the
message if null.message
- The error in plain text. Not specified in the message if
null.public static org.w3c.dom.Element clientError(java.lang.String message)
message
- The error in plain text.
Element
of the error message.public org.w3c.dom.Document getDocument()
Document
holding the message data.
Document
holding the message data.public java.lang.String getType()
public boolean isType(java.lang.String type)
type
- The type you wish to test against.
true
if the type of this message equals the given
type and false
otherwise.public void setAttribute(java.lang.String key, java.lang.String value)
key
- The key of the attribute.value
- The value of the attribute.public void setAttribute(java.lang.String key, int value)
key
- The key of the attribute.value
- The value of the attribute.public java.lang.String getAttribute(java.lang.String key)
key
- The key of the attribute.
public boolean hasAttribute(java.lang.String attribute)
attribute
- The attribute in which to verify the existence of.
true
if the root element has the given attribute.public void insertAsRoot(org.w3c.dom.Element newRoot)
newRoot
as the new root element and appends the
old root element.
newRoot
- The new root element.public static org.w3c.dom.Element getChildElement(org.w3c.dom.Element element, java.lang.String tagName)
element
- The Element
to search for the child
element.tagName
- The tag name of the child element to be found.
public org.w3c.dom.Element toXMLElement()
public java.lang.String toString()
String
representation of the message. This is
what actually gets transmitted to the other peer.
toString
in class java.lang.Object
String
representation of the message.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |