use of de.ids_mannheim.korap.response.Message in project Krill by KorAP.
the class Messages method add.
/**
* Append a new message.
*
* @param code
* Integer code representation of the warning
* @param msg
* String representation of the warning
* @param terms
* Optional strings of additional information
* @return New Message object
*/
public Message add(int code, String message, String... terms) {
Message newMsg = new Message(code, message);
messages.add(newMsg);
if (terms != null)
for (String t : terms) newMsg.addParameter(t);
return newMsg;
}
use of de.ids_mannheim.korap.response.Message in project Krill by KorAP.
the class Messages method add.
/**
* Append an existing message comming from a JsonNode.
*
* @param node
* <code>JsonNode</code> representing a message
* @return New Message object
* @throws QueryException
* if notification is not well formed (Error 750)
*/
public Message add(JsonNode msg) throws QueryException {
if (!msg.isArray() || !msg.has(0))
throw new QueryException(750, "Passed notifications are not well formed");
// Valid message
Message newMsg = new Message();
short i = 1;
if (msg.get(0).isNumber()) {
newMsg.setCode(msg.get(0).asInt());
if (!msg.has(1))
throw new QueryException(750, "Passed notifications are not well formed");
newMsg.setMessage(msg.get(1).asText());
i++;
} else {
newMsg.setMessage(msg.get(0).asText());
}
;
// Add parameters
while (msg.has(i)) newMsg.addParameter(msg.get(i++).asText());
// Add messages to list
this.add(newMsg);
return newMsg;
}
use of de.ids_mannheim.korap.response.Message in project Krill by KorAP.
the class TestMessage method CheckIterability.
@Test
public void CheckIterability() {
Messages km = new Messages();
km.add(612, "Foo");
km.add(613, "Bar", "Instanz");
km.add(614, "Test");
String test = "";
for (Message msg : km) test += msg.getCode();
assertEquals(test, "612613614");
}
use of de.ids_mannheim.korap.response.Message in project Krill by KorAP.
the class Messages method add.
/**
* Append an existing message.
*
* @param msg
* Message object to be added. Message will be cloned.
* @return Cloned Message object
*/
public Message add(Message msg) {
try {
Message msgClone = (Message) msg.clone();
messages.add(msgClone);
return msgClone;
} catch (CloneNotSupportedException e) {
}
;
return (Message) null;
}
Aggregations