package org.yamcs.xtce;

import java.io.Serializable;
import java.util.Set;
import java.util.logging.Logger;

public interface MatchCriteria extends Serializable {
    /**
     * Return the set of parameters which are required in order to evaluate the match criteria. If no parameter is
     * required, return an empty set.
     * 
     * @return
     */
    public Set<Parameter> getDependentParameters();

    static String printExpressionReference(ParameterOrArgumentRef ref) {
        if (!ref.useCalibratedValue()) {
            return "'raw://" + ref.getName() + "'";
        } else {
            return "'" + ref.getName() + "'";
        }
    }

    static String printExpressionValue(Object value) {
        if (value != null && value instanceof String) {
            // Need to allow for quotes and slashes within the string itself
            // Turn '\' into '\\' and next, '"' into '\"'
            String escaped = ((String) value).replace("\\", "\\\\").replace("\"", "\\\"");
            return "\"" + escaped + "\"";
        } else {
            return String.valueOf(value);
        }
    }

    /**
     * For debugging purpose
     * 
     * @param criteria
     */
    static public void printParsedMatchCriteria(Logger log, MatchCriteria criteria, String indent) {
        if (criteria instanceof Comparison) {
            log.fine(indent + criteria.toString());
        } else if (criteria instanceof ComparisonList) {
            log.fine(indent + "ComparisonList (");
            for (Comparison c : ((ComparisonList) criteria).comparisons) {
                log.fine(indent + "  " + c.toString());
            }
            log.fine(indent + ")");
        } else if (criteria instanceof Condition) {
            log.fine(indent + criteria.toString());
        } else if (criteria instanceof ANDedConditions) {
            log.fine(indent + "AND (");
            for (MatchCriteria c : ((ExpressionList) criteria).expressions) {
                printParsedMatchCriteria(log, c, indent + "  ");
            }
            log.fine(indent + ")");
        } else if (criteria instanceof ORedConditions) {
            log.fine(indent + "OR (");
            for (MatchCriteria c : ((ExpressionList) criteria).expressions) {
                printParsedMatchCriteria(log, c, indent + "  ");
            }
            log.fine(indent + ")");
        }
    }
}

@@ -471,24 +471,341 @@
 tRef ref) %7B%0A
+        String fullName = ref.getName();%0A        PathElement%5B%5D path = ref.getMemberPath();%0A        if (path != null) %7B%0A            for (PathElement el : path) %7B%0A                if (el.getName() != null) %7B%0A                    fullName += %22.%22;%0A                %7D%0A                fullName += el;%0A            %7D%0A        %7D%0A%0A
         if (
@@ -860,37 +860,32 @@
 %22'raw://%22 + 
-ref.get
+full
 Name
-()
  + %22'%22;%0A    
@@ -922,29 +922,24 @@
 n %22'%22 + 
-ref.get
+full
 Name
-()
  + %22'%22;%0A

Fix member path not included in expression strings