1 | package com.nailabs.abac.test; |
---|
2 | |
---|
3 | import java.io.*; |
---|
4 | import java.util.*; |
---|
5 | |
---|
6 | public class Debug { |
---|
7 | |
---|
8 | static PrintStream out = System.out; |
---|
9 | static PrintStream rbtm = null; |
---|
10 | static PrintStream sysOut = System.out; |
---|
11 | static PrintStream oldOut = out; |
---|
12 | static PrintStream sysErr = System.err; |
---|
13 | |
---|
14 | static boolean failurePropagation; |
---|
15 | |
---|
16 | static int redirect = 0; |
---|
17 | |
---|
18 | static HashSet allowed = new HashSet(); |
---|
19 | |
---|
20 | static { |
---|
21 | allowed.add("strategy"); |
---|
22 | //allowed.add("worklist"); |
---|
23 | allowed.add("negotiate"); |
---|
24 | allowed.add("root"); |
---|
25 | allowed.add("message"); |
---|
26 | allowed.add("linked"); |
---|
27 | allowed.add("linking-goal"); |
---|
28 | //allowed.add("node"); |
---|
29 | allowed.add("perform"); |
---|
30 | allowed.add("newop"); |
---|
31 | allowed.add("process"); |
---|
32 | allowed.add("satisfaction"); |
---|
33 | allowed.add("evidence"); |
---|
34 | try { |
---|
35 | failurePropagation = System.getProperty |
---|
36 | ("com.nailabs.abac.Failure", "true").equalsIgnoreCase("true"); |
---|
37 | rbtm = new PrintStream(new FileOutputStream("rbtm.log")); |
---|
38 | } catch(Exception ex) { |
---|
39 | ex.printStackTrace(); |
---|
40 | } |
---|
41 | } |
---|
42 | |
---|
43 | |
---|
44 | public static boolean sendFailure() { |
---|
45 | return failurePropagation; |
---|
46 | } |
---|
47 | |
---|
48 | public static void addKey(String key) { |
---|
49 | allowed.add(key); |
---|
50 | } |
---|
51 | |
---|
52 | public static void removeKey(String key) { |
---|
53 | allowed.remove(key); |
---|
54 | } |
---|
55 | |
---|
56 | public static void open(String name) { |
---|
57 | try { |
---|
58 | out = new PrintStream(new FileOutputStream(name)); |
---|
59 | } |
---|
60 | catch(Exception ex) { |
---|
61 | ex.printStackTrace(out); |
---|
62 | } |
---|
63 | } |
---|
64 | |
---|
65 | public static void close() { out.close(); } |
---|
66 | |
---|
67 | |
---|
68 | public static void rbtmStart() { |
---|
69 | //sysOut = System.out; |
---|
70 | //oldOut = out; |
---|
71 | //out = rbtm; |
---|
72 | System.setOut(rbtm); |
---|
73 | System.setErr(rbtm); |
---|
74 | //System.out.println("\nBeggining cycle " + redirect + "\n"); |
---|
75 | //out.println("\nrbtm.BeginCycle=" + redirect + "\n"); |
---|
76 | } |
---|
77 | |
---|
78 | public static void rbtmStop() { |
---|
79 | //System.out.println("\nRestoring standard output " + redirect + "\n"); |
---|
80 | //out.println("rbtm.EndCycle= " + redirect++ + "\n"); |
---|
81 | System.setOut(sysOut); |
---|
82 | System.setErr(sysErr); |
---|
83 | //out = oldOut; |
---|
84 | } |
---|
85 | |
---|
86 | public static void debug(String level, String message) { |
---|
87 | if(allowed.contains(level)) { |
---|
88 | out.println(message); |
---|
89 | } |
---|
90 | } |
---|
91 | |
---|
92 | } |
---|
93 | |
---|