use of com.dexels.navajo.document.Navajo in project navajo by Dexels.
the class Test method createTestMessage.
public Navajo createTestMessage() throws NavajoException {
Navajo navajo = NavajoFactory.getInstance().createNavajo();
Message element = NavajoFactory.getInstance().createMessage(navajo, "Data", Message.MSG_TYPE_ARRAY);
navajo.addMessage(element);
init(element);
navajo.write(System.err);
return navajo;
}
use of com.dexels.navajo.document.Navajo in project navajo by Dexels.
the class Test method processLine.
// 0060;AMELAND;681
private void processLine(String line, Message parent) throws NavajoException {
// "5392 Maasdonk";"795";"1671";"Maasdonk"
StringTokenizer st = new StringTokenizer(line, ";");
String code = st.nextToken();
st.nextToken();
String members = st.nextToken();
if (code == null) {
throw new RuntimeException();
}
int total = Gemeente2Population.getGemeente(code);
int member = Integer.parseInt(members);
double res = (double) member / (double) total / 0.12;
Navajo navajo = parent.getRootDoc();
Message element = NavajoFactory.getInstance().createMessage(navajo, "Data", Message.MSG_TYPE_ARRAY_ELEMENT);
parent.addMessage(element);
Property key = NavajoFactory.getInstance().createProperty(navajo, "Key", Property.STRING_PROPERTY, code, 9, "", Property.DIR_IN);
Property value = NavajoFactory.getInstance().createProperty(navajo, "Value", Property.STRING_PROPERTY, "" + res, 9, "", Property.DIR_IN);
Property description = NavajoFactory.getInstance().createProperty(navajo, "Description", Property.STRING_PROPERTY, "Leden per 1000 inwoners: " + (int) (res * 1000), 99, "", Property.DIR_IN);
element.addProperty(key);
element.addProperty(value);
element.addProperty(description);
}
use of com.dexels.navajo.document.Navajo in project navajo by Dexels.
the class Dispatcher method generateErrorMessage.
/**
* Generate a Navajo error message and log the error to the Database.
*/
@Override
public final Navajo generateErrorMessage(Access access, String message, int code, int level, Throwable t) throws FatalException {
if (message == null) {
message = "Null pointer exception";
}
if (t != null) {
logger.error("Generating error message for: ", t);
}
try {
Navajo outMessage = NavajoFactory.getInstance().createNavajo();
// Make sure empty Header is constructed
Header h = NavajoFactory.getInstance().createHeader(outMessage, "", "", "", -1);
outMessage.addHeader(h);
Message errorMessage = NavajoFactory.getInstance().createMessage(outMessage, Constants.ERROR_MESSAGE);
outMessage.addMessage(errorMessage);
Property prop = NavajoFactory.getInstance().createProperty(outMessage, "message", Property.STRING_PROPERTY, message, 200, "Message", Property.DIR_OUT);
errorMessage.addProperty(prop);
prop = NavajoFactory.getInstance().createProperty(outMessage, "code", Property.INTEGER_PROPERTY, code + "", 100, "Code", Property.DIR_OUT);
errorMessage.addProperty(prop);
prop = NavajoFactory.getInstance().createProperty(outMessage, "level", Property.INTEGER_PROPERTY, level + "", 100, "Level", Property.DIR_OUT);
errorMessage.addProperty(prop);
if (access != null) {
prop = NavajoFactory.getInstance().createProperty(outMessage, "access_id", Property.STRING_PROPERTY, access.accessID + "", 100, "Access id", Property.DIR_OUT);
errorMessage.addProperty(prop);
access.setException(t);
}
if (access != null) {
access.setOutputDoc(outMessage);
}
return outMessage;
} catch (Exception e) {
throw new FatalException(e.getMessage(), e);
}
}
use of com.dexels.navajo.document.Navajo in project navajo by Dexels.
the class Request method getThanksMessage.
/**
* Generate a simple "feedback" message with only 1 property: "resultaat".
*/
public Navajo getThanksMessage(String what) throws NavajoException {
// Create Navajo out message
Navajo outMessage = NavajoFactory.getInstance().createNavajo();
Message resultMessage = NavajoFactory.getInstance().createMessage(outMessage, "feedback");
outMessage.addMessage(resultMessage);
Property prop = NavajoFactory.getInstance().createProperty(outMessage, "resultaat", Property.STRING_PROPERTY, what, 1, "", Property.DIR_OUT);
resultMessage.addProperty(prop);
return outMessage;
}
use of com.dexels.navajo.document.Navajo in project navajo by Dexels.
the class Request method getInitialNavajoMesssage.
/**
* This method returns the Navajo message that corresponds to an initial
* service request. Initial services are always located somewhere on the filesystem.
*/
public Navajo getInitialNavajoMesssage(String service) throws IOException, NavajoException {
Navajo outMessage = null;
// Read the filename from koopsom properties
String fileName = properties.get(service).toString();
outMessage = NavajoFactory.getInstance().createNavajo(new FileInputStream(fileName));
return outMessage;
}
Aggregations