use of com.dexels.navajo.document.stream.api.Prop in project navajo by Dexels.
the class NavajoDomStreamer method messageProperties.
private static List<Prop> messageProperties(Message msg) {
List<Property> all = msg.getAllProperties();
final List<Prop> result = new ArrayList<>();
for (Property property : all) {
result.add(create(property));
}
return Collections.unmodifiableList(result);
}
use of com.dexels.navajo.document.stream.api.Prop in project navajo by Dexels.
the class NavajoStreamSerializer method processNavajoEvent.
@SuppressWarnings("unchecked")
private void processNavajoEvent(NavajoStreamEvent event, Writer w) {
try {
String name = event.path();
switch(event.type()) {
case MESSAGE_STARTED:
messageIgnoreStack.push("ignore".equals(event.attribute("mode")));
if (!messageIgnoreStack.contains(true)) {
printStartTag(w, INDENT * (tagDepth + 1), true, "message", createMessageAttributes("name=\"" + name + "\"", event.attributes()));
} else {
logger.info("Message IGNORE!");
}
tagDepth++;
messageNameStack.push(name);
break;
case MESSAGE_DEFINITION_STARTED:
messageIgnoreStack.push("ignore".equals(event.attribute("mode")));
if (!messageIgnoreStack.contains(true)) {
printStartTag(w, INDENT * (tagDepth + 1), true, "message", createMessageAttributes("name=\"" + name + "\" type=\"definition\"", event.attributes()));
}
tagDepth++;
messageNameStack.push(name + "@definition");
break;
case ARRAY_ELEMENT_STARTED:
messageIgnoreStack.push("ignore".equals(event.attribute("mode")));
String arrayName = messageNameStack.peek();
String pth = currentPath();
AtomicInteger index = counterStack.peek();
if (index == null) {
logger.error("no current index for path: " + pth);
}
if (!"ignore".equals(event.attribute("mode"))) {
printStartTag(w, INDENT * (tagDepth + 1), true, "message", createMessageAttributes("name=\"" + arrayName + "\" index=\"" + index + "\" type=\"array_element\"", event.attributes()));
tagDepth++;
}
int ind = index.getAndIncrement();
messageNameStack.push("@" + ind);
break;
case MESSAGE:
case MESSAGE_DEFINITION:
case ARRAY_ELEMENT:
messageNameStack.pop();
Msg msgBody = event.message();
List<Prop> properties = msgBody.properties();
if (!messageIgnoreStack.contains(true)) {
for (Prop prop : properties) {
prop.write(w, INDENT * (tagDepth + 1));
}
printEndTag(w, INDENT * tagDepth, "message");
}
messageIgnoreStack.pop();
tagDepth--;
break;
case ARRAY_STARTED:
messageIgnoreStack.push("ignore".equals(event.attribute("mode")));
if (!messageIgnoreStack.contains(true)) {
printStartTag(w, INDENT * (tagDepth + 1), true, "message", "name=\"" + name + "\" type=\"array\"");
}
messageNameStack.push(name);
tagDepth++;
counterStack.push(new AtomicInteger());
// arrayCounter.put(currentPath(), new AtomicInteger(0));
break;
case ARRAY_DONE:
if (!messageIgnoreStack.contains(true)) {
printEndTag(w, INDENT * tagDepth, "message");
}
// printCloseTag(w, INDENT*tagStack.size());
// arrayCounter.remove(currentPath());
tagDepth--;
counterStack.pop();
messageIgnoreStack.pop();
messageNameStack.pop();
break;
case NAVAJO_STARTED:
w.write("<tml>\n");
NavajoHead head = (NavajoHead) event.body();
// head.printElement(w,INDENT);
head.print(w, INDENT);
// h.printElement(w, INDENT);
break;
case NAVAJO_DONE:
List<Method> methods = (List<Method>) event.body();
if (methods.size() > 0) {
printStartTag(w, INDENT * (tagDepth + 1), true, "methods", "");
methods.forEach(e -> {
try {
e.write(w, INDENT * (tagDepth + 2));
} catch (IOException e1) {
logger.error("Error: ", e1);
}
});
printEndTag(w, INDENT * (tagDepth + 1), "methods");
}
w.write("</tml>\n");
break;
case BINARY_STARTED:
int length = (Integer) event.attribute("length");
String description = (String) event.attribute("description");
String direction = (String) event.attribute("direction");
String subtype = (String) event.attribute("subtype");
StringBuilder sb = new StringBuilder("name=\"" + event.path() + "\" type=\"binary\" length=\"" + length + "\"");
if (description != null) {
sb.append(" description=\"" + description + "\"");
}
if (direction != null) {
sb.append(" direction=\"" + direction + "\"");
}
if (subtype != null) {
sb.append(" subtype=\"" + subtype + "\"");
}
printStartTag(w, INDENT * (tagDepth + 1), true, "property", sb.toString());
tagDepth++;
break;
case BINARY_CONTENT:
String body = (String) event.body();
w.write(body);
tagDepth++;
break;
case BINARY_DONE:
tagDepth--;
printEndTag(w, INDENT * tagDepth, "property");
break;
default:
break;
}
} catch (IOException e) {
logger.error("Error: ", e);
}
}
use of com.dexels.navajo.document.stream.api.Prop in project navajo by Dexels.
the class NavajoStreamToMutableMessageStream method processNavajoEvent.
public Flowable<Message> processNavajoEvent(NavajoStreamEvent n) {
switch(n.type()) {
case NAVAJO_STARTED:
return Flowable.empty();
case MESSAGE_STARTED:
Message prMessage = null;
if (!messageStack.isEmpty()) {
prMessage = messageStack.peek();
}
String mode = (String) n.attribute("mode");
Message msg = NavajoFactory.getInstance().createMessage(null, n.path(), Message.MSG_TYPE_SIMPLE);
msg.setMode(mode);
if (prMessage == null) {
// assemble.addMessage(msg);
// currentMessage.set(msg);
} else {
prMessage.addMessage(msg);
}
messageStack.push(msg);
tagStack.push(n.path());
return Flowable.empty();
case MESSAGE:
// if(messageStack.isEmpty())
Message msgParent = null;
if (messageStack.isEmpty()) {
msgParent = NavajoFactory.getInstance().createMessage(null, n.path(), Message.MSG_TYPE_SIMPLE);
} else {
msgParent = messageStack.pop();
}
Msg mm = (Msg) n.body();
List<Prop> msgProps = mm.properties();
for (Prop e : msgProps) {
msgParent.addProperty(createTmlProperty(e));
}
if (emitStack()) {
tagStack.pop();
return Flowable.just(msgParent);
}
tagStack.pop();
return Flowable.empty();
case ARRAY_STARTED:
tagStack.push(n.path());
Message parentMessage = null;
if (!messageStack.isEmpty()) {
parentMessage = messageStack.peek();
}
Message arr = NavajoFactory.getInstance().createMessage(null, n.path(), Message.MSG_TYPE_ARRAY);
if (parentMessage == null) {
// assemble.addMessage(arr);
} else {
parentMessage.addMessage(arr);
}
messageStack.push(arr);
return Flowable.empty();
case ARRAY_DONE:
// String apath = currentPath();
// arrayCounts.remove(apath);
this.messageStack.pop();
return Flowable.empty();
case ARRAY_ELEMENT_STARTED:
String arrayElementName = tagStack.peek();
Message newElt = NavajoFactory.getInstance().createMessage(null, arrayElementName, Message.MSG_TYPE_ARRAY_ELEMENT);
Message arrParent = messageStack.peek();
arrParent.addElement(newElt);
messageStack.push(newElt);
return Flowable.empty();
case ARRAY_ELEMENT:
Message elementParent = messageStack.pop();
Msg msgElement = (Msg) n.body();
List<Prop> elementProps = msgElement.properties();
for (Prop e : elementProps) {
elementParent.addProperty(createTmlProperty(e));
}
if (emitStack()) {
// tagStack.pop();
return Flowable.just(elementParent);
}
// tagStack.pop();
return Flowable.empty();
case MESSAGE_DEFINITION_STARTED:
return Flowable.empty();
case MESSAGE_DEFINITION:
// deferredMessages.get(stripIndex(n.path())).setDefinitionMessage((Message) n.body());
return Flowable.empty();
case NAVAJO_DONE:
return Flowable.empty();
default:
return Flowable.empty();
}
}
use of com.dexels.navajo.document.stream.api.Prop in project navajo by Dexels.
the class NavajoStreamCollector method processNavajoEvent.
public Optional<Navajo> processNavajoEvent(NavajoStreamEvent n) throws IOException {
switch(n.type()) {
case NAVAJO_STARTED:
createHeader((NavajoHead) n.body());
return Optional.empty();
case MESSAGE_STARTED:
Message prMessage = null;
if (!messageStack.isEmpty()) {
prMessage = messageStack.peek();
}
String mode = (String) n.attribute("mode");
Message msg = NavajoFactory.getInstance().createMessage(assemble, n.path(), Message.MSG_TYPE_SIMPLE);
msg.setMode(mode);
if (prMessage == null) {
assemble.addMessage(msg);
} else {
prMessage.addMessage(msg);
}
messageStack.push(msg);
tagStack.push(n.path());
return Optional.empty();
case MESSAGE:
Message msgParent = messageStack.pop();
tagStack.pop();
Msg mm = (Msg) n.body();
List<Prop> msgProps = mm.properties();
for (Prop e : msgProps) {
msgParent.addProperty(createTmlProperty(e));
}
// pushBinaries
for (Entry<String, Binary> e : pushBinaries.entrySet()) {
msgParent.addProperty(createBinaryProperty(e.getKey(), e.getValue()));
}
pushBinaries.clear();
binaryProperties.clear();
return Optional.empty();
case ARRAY_STARTED:
tagStack.push(n.path());
String path = currentPath();
AtomicInteger cnt = arrayCounts.get(path);
if (cnt == null) {
cnt = new AtomicInteger();
arrayCounts.put(path, cnt);
}
// cnt.incrementAndGet();
Message parentMessage = null;
if (!messageStack.isEmpty()) {
parentMessage = messageStack.peek();
}
Message arr = NavajoFactory.getInstance().createMessage(assemble, n.path(), Message.MSG_TYPE_ARRAY);
if (parentMessage == null) {
assemble.addMessage(arr);
} else {
parentMessage.addMessage(arr);
}
messageStack.push(arr);
return Optional.empty();
case ARRAY_DONE:
String apath = currentPath();
arrayCounts.remove(apath);
this.messageStack.pop();
return Optional.empty();
case ARRAY_ELEMENT_STARTED:
String arrayElementName = tagStack.peek();
String arrayPath = currentPath();
AtomicInteger currentCount = arrayCounts.get(arrayPath);
if (currentCount != null) {
String ind = "@" + currentCount.getAndIncrement();
tagStack.push(ind);
}
arrayPath = currentPath();
Message newElt = NavajoFactory.getInstance().createMessage(assemble, arrayElementName, Message.MSG_TYPE_ARRAY_ELEMENT);
Message arrParent = messageStack.peek();
arrParent.addElement(newElt);
messageStack.push(newElt);
return Optional.empty();
case ARRAY_ELEMENT:
tagStack.pop();
Message elementParent = messageStack.pop();
Msg msgElement = (Msg) n.body();
List<Prop> elementProps = msgElement.properties();
for (Prop e : elementProps) {
elementParent.addProperty(createTmlProperty(e));
}
for (Entry<String, Binary> e : pushBinaries.entrySet()) {
elementParent.addProperty(createBinaryProperty(e.getKey(), e.getValue()));
}
pushBinaries.clear();
return Optional.empty();
case MESSAGE_DEFINITION_STARTED:
return Optional.empty();
case MESSAGE_DEFINITION:
return Optional.empty();
case NAVAJO_DONE:
@SuppressWarnings("unchecked") List<Method> methodList = (List<Method>) n.body();
methodList.stream().map(m -> NavajoFactory.getInstance().createMethod(assemble, m.name, "")).forEach(e -> assemble.addMethod(e));
return Optional.of(assemble);
case BINARY_STARTED:
String name = n.path();
n.attribute("direction");
this.currentBinary = new Binary();
this.currentBinary.startPushRead();
this.pushBinaries.put(name, currentBinary);
int length = (Integer) n.attribute("length", () -> -1);
String description = (String) n.attribute("description", () -> "");
String direction = (String) n.attribute("direction", () -> "");
String subtype = (String) n.attribute("subtype", () -> "");
this.currentProperty = NavajoFactory.getInstance().createProperty(assemble, name, Property.BINARY_PROPERTY, "", length, description, direction);
this.currentProperty.setSubType(subtype);
return Optional.empty();
case BINARY_CONTENT:
if (this.currentBinary == null) {
// whoops;
}
this.currentBinary.pushContent((String) n.body());
return Optional.empty();
case BINARY_DONE:
this.currentBinary.finishPushContent();
return Optional.empty();
default:
return Optional.empty();
}
}
use of com.dexels.navajo.document.stream.api.Prop in project navajo by Dexels.
the class NavajoStreamEvent method toString.
@SuppressWarnings("unchecked")
public String toString() {
if (type == NavajoEventTypes.NAVAJO_STARTED) {
NavajoHead h = (NavajoHead) body;
return "Type: " + type + " path: " + path + " attributes: {" + attributes + "} - RPCNAME: " + h.name() + " user: " + h.username();
}
if (type == NavajoEventTypes.MESSAGE) {
Msg msgBody = (Msg) body;
List<Prop> contents = msgBody.properties();
StringBuilder sb = new StringBuilder("Message detected. Name: " + path + " with mode: " + this.attributes.get("mode") + "\n");
for (Prop prop : contents) {
sb.append("Prop: " + prop.name() + " = " + prop.value() + " value type: " + prop.type() + "with direction: " + prop.direction() + "\n");
if (prop.value() != null) {
sb.append(" -> value class: " + prop.value().getClass() + "\n");
}
}
return sb.toString();
}
if (type == NavajoEventTypes.NAVAJO_DONE) {
List<String> methods = (List<String>) body;
return "Navajo Done. Methods: " + methods;
}
return "Type: " + type + " path: " + path + " attributes: {" + attributes + "} " + body;
}
Aggregations