File: Processor.java

package info (click to toggle)
emma-coverage 2.0.5312%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch, wheezy
  • size: 2,000 kB
  • ctags: 3,667
  • sloc: java: 23,109; xml: 414; makefile: 22
file content (119 lines) | stat: -rw-r--r-- 3,534 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/* Copyright (C) 2004 Vladimir Roubtsov. All rights reserved.
 * 
 * This program and the accompanying materials are made available under
 * the terms of the Common Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/cpl-v10.html
 * 
 * $Id: Processor.java,v 1.1.2.1 2004/07/16 23:32:03 vlad_r Exp $
 */
package com.vladium.emma;

import java.util.Properties;

import com.vladium.logging.Logger;
import com.vladium.util.IProperties;
import com.vladium.util.asserts.$assert;

// ----------------------------------------------------------------------------
/**
 * @author Vlad Roubtsov, (C) 2004
 */
public
abstract class Processor
{
    // public: ................................................................


    public synchronized void run ()
    {
        validateState ();
        
        // load tool properties:
        final IProperties toolProperties;
        {
            final IProperties appProperties = EMMAProperties.getAppProperties ();
            
            toolProperties = IProperties.Factory.combine (m_propertyOverrides, appProperties);
        }
        if ($assert.ENABLED) $assert.ASSERT (toolProperties != null, "toolProperties is null"); // can be empty, though

        final Logger current = Logger.getLogger ();
        final Logger log = AppLoggers.create (m_appName, toolProperties, current);
        
        if (log.atTRACE1 ())
        {
            log.trace1 ("run", "complete tool properties:");
            toolProperties.list (log.getWriter ());
        }
        
        try
        {
            Logger.push (log);
            m_log = log;
        
            _run (toolProperties);
        }
        finally
        {
            if (m_log != null)
            {
                Logger.pop (m_log);
                m_log = null;
            }
        }
    }

    
    public synchronized final void setAppName (final String appName)
    {
        m_appName = appName;
    }
    
    /**
     * 
     * @param overrides [may be null (unsets the previous overrides)]
     */
    public synchronized final void setPropertyOverrides (final Properties overrides)
    {
        m_propertyOverrides = EMMAProperties.wrap (overrides);
    }
    
    /**
     * 
     * @param overrides [may be null (unsets the previous overrides)]
     */
    public synchronized final void setPropertyOverrides (final IProperties overrides)
    {
        m_propertyOverrides = overrides;
    }
    
    // protected: .............................................................
    
    
    protected Processor ()
    {
        // not publicly instantiable
    }

    protected abstract void _run (IProperties toolProperties);

    
    protected void validateState ()
    {
        // no Processor state needs validation
        
        // [m_appName allowed to be null]
        // [m_propertyOverrides allowed to be null]
    }
    
    
    protected String m_appName; // used as logging prefix, can be null
    protected IProperties m_propertyOverrides; // user override; can be null/empty for run()
    protected Logger m_log; // not null only within run()

    // package: ...............................................................
    
    // private: ...............................................................

} // end of class
// ----------------------------------------------------------------------------