package org.globus.swift.data;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

import org.globus.cog.karajan.arguments.Arg;
import org.globus.cog.karajan.stack.VariableStack;
import org.globus.cog.karajan.util.TypeUtil;
import org.globus.cog.karajan.workflow.ExecutionException;
import org.globus.cog.karajan.workflow.nodes.functions.FunctionsCollection;

import org.globus.swift.data.policy.Policy;

public class Query extends FunctionsCollection {

    public static final Arg PA_QUERY = new Arg.Positional("query");
    public static final Arg PA_NAME  = new Arg.Positional("name");

    static {
        setArguments("cdm_query", new Arg[]{ PA_QUERY });
        setArguments("cdm_name", new Arg[]{ PA_NAME });
        setArguments("cdm_file", new Arg[]{});
    }

    public String cdm_query(VariableStack stack) throws ExecutionException {
        String file = (String) PA_QUERY.getValue(stack);
        Policy policy = Director.lookup(file);
        return policy.toString();
    }

    public String cdm_property(VariableStack stack) throws ExecutionException {
        String name  = (String) PA_NAME.getValue(stack);
        String value = Director.property(name);
        return value;
    }
    
    public String cdm_file(VariableStack stack) throws ExecutionException {
        String file = "";
        if (Director.policyFile != null)
            file = Director.policyFile.toString();
        return file;
    }
}

@@ -710,20 +710,19 @@
 ts(%22cdm_
-name
+get
 %22, new A
@@ -1007,32 +1007,72 @@
 tring();%0A    %7D%0A%0A
+    /** %0A     Get a CDM property%0A    */%0A
     public Strin
@@ -1077,24 +1077,19 @@
 ing cdm_
-property
+get
 (Variabl

Avoid name collision.