Search in sources :

Example 1 with Property

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

the class DefaultExpressionEvaluator method getExpressionDependencyMap.

private final Map<Property, List<Property>> getExpressionDependencyMap(Navajo n, List<Property> exprList) throws NavajoException {
    Map<Property, List<Property>> depMap = new HashMap<Property, List<Property>>();
    for (int i = 0; i < exprList.size(); i++) {
        Property current = exprList.get(i);
        List<Property> l = getExpressionDependencies(n, current);
        depMap.put(current, l);
    }
    return depMap;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) Property(com.dexels.navajo.document.Property)

Example 2 with Property

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

the class DefaultExpressionEvaluator method getExpressionList.

private List<Property> getExpressionList(Navajo n) throws NavajoException {
    List<Property> expressionList = new ArrayList<Property>();
    List<Message> a = n.getAllMessages();
    for (int i = 0; i < a.size(); i++) {
        Message current = a.get(i);
        getExpressionList(n, current, expressionList);
    }
    return expressionList;
}
Also used : Message(com.dexels.navajo.document.Message) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) ArrayList(java.util.ArrayList) Property(com.dexels.navajo.document.Property)

Example 3 with Property

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

the class DefaultExpressionEvaluator method createUpdateQueue.

private final List<Property> createUpdateQueue(Map<Property, List<Property>> mm) throws NavajoException {
    Map<Property, List<Property>> dependencyMap = duplicateDependencyMap(mm);
    Set<Property> propKeys = dependencyMap.keySet();
    List<Property> queue = new ArrayList<Property>();
    Navajo first = null;
    while (dependencyMap.size() > 0) {
        for (Iterator<Property> iter = propKeys.iterator(); iter.hasNext(); ) {
            Property item = iter.next();
            if (first == null) {
                first = item.getRootDoc();
            }
            if (!Property.EXPRESSION_PROPERTY.equals(item.getType())) {
                if (!queue.contains(item)) {
                    queue.add(item);
                }
                dependencyMap.remove(item);
                break;
            }
            List<Property> deps = dependencyMap.get(item);
            if (deps == null) {
                if (!queue.contains(item)) {
                    queue.add(item);
                }
                dependencyMap.remove(item);
                break;
            }
            if (!containsExpressions(deps)) {
                if (!queue.contains(item)) {
                    queue.add(item);
                }
                dependencyMap.remove(item);
                break;
            }
            if (queue.containsAll(deps)) {
                if (!queue.contains(item)) {
                    queue.add(item);
                }
                dependencyMap.remove(item);
                break;
            }
            try {
                addExpressionToQueue(item, dependencyMap, queue);
                break;
            } catch (ExpressionDependencyException ex1) {
                logger.info("Did not succeed adding. Continuing", ex1);
            }
        }
    }
    // UUUUUUUUUUUGLY: MAKE SURE EVERY SINGLE ONE GETS ADDED
    if (first != null) {
        queue.addAll(getExpressionList(first));
    }
    return queue;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Navajo(com.dexels.navajo.document.Navajo) Property(com.dexels.navajo.document.Property)

Example 4 with Property

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

the class DefaultExpressionEvaluator method getExpressionList.

private final void getExpressionList(Navajo n, Message m, List<Property> expressionList) throws NavajoException {
    List<Message> a = m.getAllMessages();
    for (int i = 0; i < a.size(); i++) {
        Message current = a.get(i);
        getExpressionList(n, current, expressionList);
    }
    List<Property> b = m.getAllProperties();
    for (int i = 0; i < b.size(); i++) {
        Property current = b.get(i);
        if (current.getType().equals(Property.EXPRESSION_PROPERTY)) {
            expressionList.add(current);
        }
    }
}
Also used : Message(com.dexels.navajo.document.Message) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) Property(com.dexels.navajo.document.Property)

Example 5 with Property

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

the class DefaultExpressionEvaluator method addExpressionToQueue.

private final void addExpressionToQueue(Property item, Map<Property, List<Property>> depMap, List<Property> queue) throws ExpressionDependencyException {
    List<Property> deps = depMap.get(item);
    if (deps == null) {
        throw new RuntimeException("Huh?");
    }
    boolean problems = false;
    for (int i = 0; i < deps.size(); i++) {
        Property p = deps.get(i);
        List<Property> deps2 = depMap.get(p);
        if (deps2 == null) {
            depMap.remove(p);
            if (!queue.contains(p)) {
                queue.add(p);
            }
            continue;
        }
        if (queue.containsAll(deps2)) {
            if (!queue.contains(p)) {
                queue.add(p);
            }
            depMap.remove(item);
            continue;
        }
        try {
            addExpressionToQueue(p, depMap, queue);
        } catch (ExpressionDependencyException ex) {
            problems = true;
        }
    }
    if (problems) {
        throw new ExpressionDependencyException();
    }
}
Also used : Property(com.dexels.navajo.document.Property)

Aggregations

Property (com.dexels.navajo.document.Property)253 Message (com.dexels.navajo.document.Message)148 Test (org.junit.Test)88 Navajo (com.dexels.navajo.document.Navajo)84 Selection (com.dexels.navajo.document.Selection)36 NavajoException (com.dexels.navajo.document.NavajoException)30 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)17 ArrayList (java.util.ArrayList)17 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)16 Binary (com.dexels.navajo.document.types.Binary)16 UserException (com.dexels.navajo.script.api.UserException)16 Access (com.dexels.navajo.script.api.Access)15 StringWriter (java.io.StringWriter)13 List (java.util.List)11 Operand (com.dexels.navajo.document.Operand)10 MappableException (com.dexels.navajo.script.api.MappableException)9 IOException (java.io.IOException)9 Writer (java.io.Writer)9 StringTokenizer (java.util.StringTokenizer)9 JSONTML (com.dexels.navajo.document.json.JSONTML)8