View Javadoc

1   package org.e2etrace.trace;
2   
3   /*
4    * Copyright 2006 Gunther Popp
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import java.util.HashMap;
20  import java.util.Map;
21  
22  import org.e2etrace.config.ITraceConfig;
23  import org.e2etrace.trace.ITraceStepId;
24  
25  
26  /**
27   * Mock-Object for trace configurations.
28   *
29   * All trace parameters can be defined at runtime using the setters of the mock.
30   * <p>
31   *
32   * @author Gunther Popp
33   */
34  public class MockTraceConfig implements ITraceConfig {
35  
36    boolean traceEnabled = true;
37    Map traceEnabledForId;
38  
39    /**
40     * Default constructor.
41     * <p>
42     *
43     */
44    public MockTraceConfig() {
45      this.traceEnabledForId = new HashMap();
46    }
47  
48    /**
49     * Modifies the configuration setting <code>isTraceEnabled</code>.
50     * <p>
51     *
52     * @param enabled new setting
53     */
54    public void setTraceEnabled(boolean enabled) {
55      this.traceEnabled = enabled;
56    }
57  
58    /** {@inheritDoc} */
59    public boolean isTraceEnabled() {
60      return this.traceEnabled;
61    }
62  
63    /**
64     * Modifies the configuration setting <code>isTraceEnabledForId</code>.
65     * <p>
66     *
67     * @param id trace step id
68     * @param enabled tracing enabled for this step
69     */
70    public void setTraceEnabledForId(ITraceStepId id, boolean enabled) {
71      this.traceEnabledForId.put(id, new Boolean(enabled));
72    }
73  
74    /** {@inheritDoc} */
75    public boolean isTraceEnabledForId(ITraceStepId id) {
76      boolean ret = true;
77      Boolean enabled;
78  
79      enabled = (Boolean) this.traceEnabledForId.get(id);
80  
81      if (enabled != null) {
82        ret = enabled.booleanValue();
83      }
84  
85      return ret;
86    }
87  
88  }