package com.nailabs.abac.test; import java.io.*; import java.util.*; public class Debug { static PrintStream out = System.out; static PrintStream rbtm = null; static PrintStream sysOut = System.out; static PrintStream oldOut = out; static PrintStream sysErr = System.err; static boolean failurePropagation; static int redirect = 0; static HashSet allowed = new HashSet(); static { allowed.add("strategy"); //allowed.add("worklist"); allowed.add("negotiate"); allowed.add("root"); allowed.add("message"); allowed.add("linked"); allowed.add("linking-goal"); //allowed.add("node"); allowed.add("perform"); allowed.add("newop"); allowed.add("process"); allowed.add("satisfaction"); allowed.add("evidence"); try { failurePropagation = System.getProperty ("com.nailabs.abac.Failure", "true").equalsIgnoreCase("true"); rbtm = new PrintStream(new FileOutputStream("rbtm.log")); } catch(Exception ex) { ex.printStackTrace(); } } public static boolean sendFailure() { return failurePropagation; } public static void addKey(String key) { allowed.add(key); } public static void removeKey(String key) { allowed.remove(key); } public static void open(String name) { try { out = new PrintStream(new FileOutputStream(name)); } catch(Exception ex) { ex.printStackTrace(out); } } public static void close() { out.close(); } public static void rbtmStart() { //sysOut = System.out; //oldOut = out; //out = rbtm; System.setOut(rbtm); System.setErr(rbtm); //System.out.println("\nBeggining cycle " + redirect + "\n"); //out.println("\nrbtm.BeginCycle=" + redirect + "\n"); } public static void rbtmStop() { //System.out.println("\nRestoring standard output " + redirect + "\n"); //out.println("rbtm.EndCycle= " + redirect++ + "\n"); System.setOut(sysOut); System.setErr(sysErr); //out = oldOut; } public static void debug(String level, String message) { if(allowed.contains(level)) { out.println(message); } } }