Search in sources :

Example 6 with Message

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

the class ASTForAllNode method interpretToLambda.

@Override
public ContextExpression interpretToLambda(List<String> problems, String expression, Function<String, FunctionClassification> functionClassifier, Function<String, Optional<Node>> mapResolver) {
    return new ContextExpression() {

        @Override
        public boolean isLiteral() {
            return false;
        }

        @Override
        public Operand apply(Navajo doc, Message parentMsg, Message parentParamMsg, Selection parentSel, MappableTreeNode mapNode, TipiLink tipiLink, Access access, Optional<ImmutableMessage> immutableMessage, Optional<ImmutableMessage> paramMessage) {
            List<String> problems = new ArrayList<>();
            ContextExpression a = jjtGetChild(0).interpretToLambda(problems, expression, functionClassifier, mapResolver);
            ContextExpression b = jjtGetChild(1).interpretToLambda(problems, expression, functionClassifier, mapResolver);
            if (!problems.isEmpty()) {
                throw new TMLExpressionException(problems, expression);
            }
            return interpret(doc, parentMsg, parentParamMsg, parentSel, mapNode, tipiLink, access, immutableMessage, paramMessage, a, b);
        }

        @Override
        public Optional<String> returnType() {
            return Optional.empty();
        }

        @Override
        public String expression() {
            return expression;
        }
    };
}
Also used : MappableTreeNode(com.dexels.navajo.script.api.MappableTreeNode) TipiLink(com.dexels.navajo.expression.api.TipiLink) Message(com.dexels.navajo.document.Message) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) Optional(java.util.Optional) Selection(com.dexels.navajo.document.Selection) ContextExpression(com.dexels.navajo.expression.api.ContextExpression) Access(com.dexels.navajo.script.api.Access) ArrayList(java.util.ArrayList) Navajo(com.dexels.navajo.document.Navajo) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 7 with Message

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

the class Expression method match.

public static final Message match(String matchString, Navajo inMessage, MappableTreeNode o, Message parent) throws SystemException {
    try {
        StringTokenizer tokens = new StringTokenizer(matchString, ";");
        String matchSet = tokens.nextToken();
        if (matchSet == null)
            throw new TMLExpressionException("Invalid usage of match: match=\"[match set];[match value]\"");
        String matchValue = tokens.nextToken();
        if (matchValue == null)
            throw new TMLExpressionException("Invalid usage of match: match=\"[match set];[match value]\"");
        Operand value = evaluate(matchValue, inMessage, o, parent, null, null, null, null);
        List<Property> properties;
        if (parent == null)
            properties = inMessage.getProperties(matchSet);
        else
            properties = parent.getProperties(matchSet);
        for (int i = 0; i < properties.size(); i++) {
            Property prop = properties.get(i);
            Message parentMsg = prop.getParentMessage();
            if (prop.getValue().equals(value.value))
                return parentMsg;
        }
    } catch (NavajoException e) {
        throw new SystemException(-1, e.getMessage(), e);
    }
    return null;
}
Also used : StringTokenizer(java.util.StringTokenizer) Message(com.dexels.navajo.document.Message) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) SystemException(com.dexels.navajo.script.api.SystemException) Operand(com.dexels.navajo.document.Operand) NavajoException(com.dexels.navajo.document.NavajoException) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) Property(com.dexels.navajo.document.Property)

Example 8 with Message

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

the class SaxHandler method parseProperty.

private final void parseProperty(Map<String, String> h) throws NavajoException {
    // logger.info("NAME: "+(String)h.get("name"));
    String sLength = null;
    String myName = h.get(Property.PROPERTY_NAME);
    String myValue = h.get(Property.PROPERTY_VALUE);
    String subType = h.get(Property.PROPERTY_SUBTYPE);
    String description = h.get(Property.PROPERTY_DESCRIPTION);
    String direction = h.get(Property.PROPERTY_DIRECTION);
    String type = h.get(Property.PROPERTY_TYPE);
    sLength = h.get(Property.PROPERTY_LENGTH);
    String cardinality = h.get(Property.PROPERTY_CARDINALITY);
    String extendsProp = h.get(Property.PROPERTY_EXTENDS);
    String reference = h.get(Property.PROPERTY_REFERENCE);
    String key = h.get(Property.PROPERTY_KEY);
    String bind = h.get(Property.PROPERTY_BIND);
    String method = h.get(Property.PROPERTY_METHOD);
    Integer plength = null;
    Property definitionProperty = null;
    String subtype = null;
    int length = 0;
    try {
        if (sLength != null) {
            length = Integer.parseInt(sLength);
            plength = Integer.valueOf(length);
        }
    } catch (Exception e1) {
    // logger.info("ILLEGAL LENGTH IN PROPERTY " + myName + ": " +
    // sLength);
    }
    if (myName == null) {
        throw NavajoFactory.getInstance().createNavajoException("Can not parse property without a name ");
    }
    boolean isListType = (type != null && type.equals(Property.SELECTION_PROPERTY));
    if (isListType) {
        currentProperty = (BasePropertyImpl) NavajoFactory.getInstance().createProperty(currentDocument, myName, cardinality, description, direction);
    } else {
        currentProperty = (BasePropertyImpl) NavajoFactory.getInstance().createProperty(currentDocument, myName, type, myValue, length, description, direction, subtype);
    }
    if (messageStack.isEmpty()) {
        throw NavajoFactory.getInstance().createNavajoException("Can not parse property without being inside a message, probably an input error");
    }
    Message current = messageStack.peek();
    current.addProperty(currentProperty);
    BaseMessageImpl arrayParent = (BaseMessageImpl) current.getArrayParentMessage();
    if (arrayParent != null && arrayParent.isArrayMessage()) {
        definitionProperty = arrayParent.getPropertyDefinition(myName);
        if (definitionProperty != null) {
            if (description == null || "".equals(description)) {
                description = definitionProperty.getDescription();
            }
            if (direction == null || "".equals(direction)) {
                direction = definitionProperty.getDirection();
            }
            if (type == null || "".equals(type)) {
                type = definitionProperty.getType();
            }
            if (plength == null) {
                length = definitionProperty.getLength();
            }
            if (subType == null) {
                if (definitionProperty.getSubType() != null) {
                    currentProperty.setSubType(definitionProperty.getSubType());
                }
            } else {
                if (definitionProperty.getSubType() != null) {
                    /**
                     * Concatenated subtypes. The if the same key of a subtype is present
                     * in both the property and the definition property.
                     */
                    currentProperty.setSubType(definitionProperty.getSubType() + "," + subType);
                }
            }
        }
    }
    if (subType == null && NavajoFactory.getInstance().getDefaultSubtypeForType(type) != null) {
        currentProperty.setSubType(NavajoFactory.getInstance().getDefaultSubtypeForType(type));
    } else {
        currentProperty.setSubType(subType);
    }
    if (type == null && current.isArrayMessage()) {
        logger.info("Found undefined property: " + currentProperty.getName());
    }
    isListType = (type != null && type.equals(Property.SELECTION_PROPERTY));
    if (isListType && definitionProperty != null) {
        if (cardinality == null) {
            cardinality = definitionProperty.getCardinality();
        }
        type = Property.SELECTION_PROPERTY;
        List<Selection> l = definitionProperty.getAllSelections();
        for (int i = 0; i < l.size(); i++) {
            BaseSelectionImpl s1 = (BaseSelectionImpl) l.get(i);
            BaseSelectionImpl s2 = (BaseSelectionImpl) s1.copy(currentDocument);
            currentProperty.addSelection(s2);
        }
    }
    currentProperty.setType(type);
    currentProperty.setDescription(description);
    currentProperty.setDirection(direction);
    currentProperty.setCardinality(cardinality);
    currentProperty.setLength(length);
    currentProperty.setExtends(extendsProp);
    currentProperty.setKey(key);
    currentProperty.setReference(reference);
    currentProperty.setBind(bind);
    currentProperty.setMethod(method);
}
Also used : BaseMessageImpl(com.dexels.navajo.document.base.BaseMessageImpl) Message(com.dexels.navajo.document.Message) Selection(com.dexels.navajo.document.Selection) BaseSelectionImpl(com.dexels.navajo.document.base.BaseSelectionImpl) Property(com.dexels.navajo.document.Property) NavajoException(com.dexels.navajo.document.NavajoException) IOException(java.io.IOException) EOFException(java.io.EOFException)

Example 9 with Message

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

the class SaxHandler method mergeDefinitionMessage.

private void mergeDefinitionMessage() {
    Message currentMessage = messageStack.peek();
    if (currentMessage == null) {
        return;
    }
    Message parentMessage = currentMessage.getParentMessage();
    if (parentMessage == null) {
        return;
    }
    Message def = parentMessage.getDefinitionMessage();
    if (def == null) {
        return;
    }
    List<Property> props = def.getAllProperties();
    for (int i = 0; i < props.size(); i++) {
        Property src = props.get(i);
        Property dest = currentMessage.getProperty(src.getName());
        if (dest == null) {
            dest = src.copy(currentDocument);
            currentMessage.addProperty(dest);
        }
    }
}
Also used : Message(com.dexels.navajo.document.Message) Property(com.dexels.navajo.document.Property)

Example 10 with Message

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

the class SaxHandler method parseMessage.

private final void parseMessage(Map<String, String> h) throws NavajoException {
    String name = h.get("name");
    String type = h.get("type");
    String orderby = h.get("orderby");
    String scope = h.get(Message.MSG_SCOPE);
    String extendsMsg = h.get(Message.MSG_EXTENDS);
    String eTag = h.get(Message.MSG_ETAG);
    String subtype = h.get(Message.MSG_SUBTYPE);
    Message m = null;
    if (type != null) {
        m = NavajoFactory.getInstance().createMessage(currentDocument, name, type);
    } else {
        m = NavajoFactory.getInstance().createMessage(currentDocument, name);
    }
    if (orderby != null && !"".equals(orderby)) {
        m.setOrderBy(orderby);
    }
    if (scope != null && !"".equals(scope)) {
        m.setScope(scope);
    }
    if (extendsMsg != null && !"".equals(extendsMsg)) {
        m.setExtends(extendsMsg);
    }
    if (eTag != null && !"".equals(eTag)) {
        m.setEtag(eTag);
    }
    if (subtype != null && !"".equals(subtype)) {
        m.setSubType(subtype);
    }
    if (messageStack.isEmpty()) {
        currentDocument.addMessage(m);
    } else {
        // Don't add definition messages.
        Message parentMessage = messageStack.peek();
        if (!Message.MSG_TYPE_DEFINITION.equals(type)) {
            parentMessage.addMessage(m);
        } else {
            parentMessage.setDefinitionMessage(m);
        }
    }
    messageStack.push(m);
}
Also used : Message(com.dexels.navajo.document.Message)

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