Search in sources :

Example 61 with Message

use of com.dexels.navajo.document.Message in project navajo by Dexels.

the class JSONTMLImpl method parseArrayMessageElement.

private void parseArrayMessageElement(Message arrayMessage, JsonParser jp) throws Exception {
    Message m = NavajoFactory.getInstance().createMessage(arrayMessage.getRootDoc(), arrayMessage.getName());
    arrayMessage.addElement(m);
    if (jp.getCurrentToken() == JsonToken.START_OBJECT) {
        // Array with sub message structure
        parse(arrayMessage.getRootDoc(), m, jp);
    } else {
        String name = jp.getCurrentName();
        String value = jp.getText();
        parseProperty(name, value, m, jp);
    }
}
Also used : Message(com.dexels.navajo.document.Message)

Example 62 with Message

use of com.dexels.navajo.document.Message in project navajo by Dexels.

the class JSONTMLImpl method parse.

private Navajo parse(JsonParser jp) throws Exception {
    Navajo n = NavajoFactory.getInstance().createNavajo();
    Message parent = NavajoFactory.getInstance().createMessage(n, (topLevelMessageName != null ? topLevelMessageName : "Request"));
    boolean first = true;
    while (jp.nextToken() != null) {
        if (first) {
            n.addMessage(parent);
            first = false;
        }
        parse(n, parent, jp);
    }
    return n;
}
Also used : Message(com.dexels.navajo.document.Message) Navajo(com.dexels.navajo.document.Navajo)

Example 63 with Message

use of com.dexels.navajo.document.Message in project navajo by Dexels.

the class BasePropertyImpl method getEvaluatedValue.

public final Object getEvaluatedValue() {
    Operand o;
    // No evaluator present.
    if (NavajoFactory.getInstance().getExpressionEvaluator() == null) {
        return null;
    }
    try {
        try {
            if (!EXPRESSION_PROPERTY.equals(getType())) {
                throw NavajoFactory.getInstance().createNavajoException("Can only evaluate expression type properties!");
            }
            try {
                o = NavajoFactory.getInstance().getExpressionEvaluator().evaluate(getValue(), getRootDoc(), null, getParentMessage(), null);
                evaluatedType = o.type;
                return o.value;
            } catch (Throwable e) {
                logger.info("Exception while evaluating property: {} expression: {}", getFullPropertyName(), getValue());
                return null;
            }
        } catch (NavajoException ex) {
            logger.error("Error: ", ex);
            if (myParent != null) {
                Message pp = myParent.getArrayParentMessage();
                if (pp != null && Message.MSG_TYPE_ARRAY.equals(pp.getType())) {
                    Message def = pp.getDefinitionMessage();
                    if (def != null) {
                        Property ppp = def.getProperty(getName());
                        if (ppp != null) {
                            evaluatedType = ppp.getType();
                            return null;
                        }
                    }
                }
            }
            evaluatedType = "string";
            return null;
        }
    } catch (Throwable ex1) {
        evaluatedType = "string";
        return null;
    }
}
Also used : Message(com.dexels.navajo.document.Message) Operand(com.dexels.navajo.document.Operand) NavajoException(com.dexels.navajo.document.NavajoException) Property(com.dexels.navajo.document.Property)

Example 64 with Message

use of com.dexels.navajo.document.Message in project navajo by Dexels.

the class BaseNavajoImpl method mask.

@Override
public Navajo mask(Navajo with, String method) {
    // Find duplicate messages.
    List<Message> superMessages = this.getAllMessages();
    List<Message> subMessages = with.getAllMessages();
    for (int i = 0; i < superMessages.size(); i++) {
        Message superMsg = superMessages.get(i);
        for (int j = 0; j < subMessages.size(); j++) {
            Message subMsg = subMessages.get(j);
            if (superMsg.getName().equals(subMsg.getName())) {
                boolean matchMethod = method.equals("") || superMsg.getMethod().equals("") || subMsg.getMethod().equals("") || superMsg.getMethod().equals(method);
                if (!matchMethod) {
                    this.removeMessage(superMsg);
                }
                // Found duplicate!
                superMsg.maskMessage(subMsg, method);
            }
        }
    }
    // Find new messages.
    for (int i = 0; i < subMessages.size(); i++) {
        Message subMsg = subMessages.get(i);
        boolean newMsg = true;
        for (int j = 0; j < superMessages.size(); j++) {
            Message superMsg = superMessages.get(j);
            if (superMsg.getName().equals(subMsg.getName())) {
                newMsg = false;
                j = superMessages.size() + 1;
            }
        }
        if (newMsg) {
            this.addMessage(subMsg.copy(this));
        }
    }
    return this;
}
Also used : Message(com.dexels.navajo.document.Message)

Example 65 with Message

use of com.dexels.navajo.document.Message in project navajo by Dexels.

the class BaseNavajoImpl method getProperties.

@Override
public List<Property> getProperties(String s) {
    List<Property> props = new ArrayList<>();
    Property prop = null;
    List<Message> messages = null;
    String property = null;
    Message message = null;
    StringTokenizer tok = new StringTokenizer(s, Navajo.MESSAGE_SEPARATOR);
    String messageList = "";
    int count = tok.countTokens();
    for (int i = 0; i < count - 1; i++) {
        property = tok.nextToken();
        messageList += property;
        if ((i + 1) < count - 1)
            messageList += Navajo.MESSAGE_SEPARATOR;
    }
    String realProperty = tok.nextToken();
    messages = this.getMessages(messageList);
    for (int i = 0; i < messages.size(); i++) {
        message = messages.get(i);
        prop = message.getProperty(realProperty);
        if (prop != null)
            props.add(prop);
    }
    return props;
}
Also used : StringTokenizer(java.util.StringTokenizer) Message(com.dexels.navajo.document.Message) ArrayList(java.util.ArrayList) Property(com.dexels.navajo.document.Property)

Aggregations

Message (com.dexels.navajo.document.Message)312 Property (com.dexels.navajo.document.Property)149 Navajo (com.dexels.navajo.document.Navajo)127 Test (org.junit.Test)95 NavajoException (com.dexels.navajo.document.NavajoException)39 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)35 Access (com.dexels.navajo.script.api.Access)27 UserException (com.dexels.navajo.script.api.UserException)27 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)26 Selection (com.dexels.navajo.document.Selection)25 Operand (com.dexels.navajo.document.Operand)22 IOException (java.io.IOException)19 ArrayList (java.util.ArrayList)19 MappableException (com.dexels.navajo.script.api.MappableException)18 Ignore (org.junit.Ignore)17 SystemException (com.dexels.navajo.script.api.SystemException)16 Optional (java.util.Optional)15 ContextExpression (com.dexels.navajo.expression.api.ContextExpression)13 MappableTreeNode (com.dexels.navajo.script.api.MappableTreeNode)13 HashMap (java.util.HashMap)13