~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/structures/ErrorStreamDaemon.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2012-06-29 12:07:30 UTC
  • Revision ID: package-import@ubuntu.com-20120629120730-bfri1xys1i71dpn6
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (c) 2006 IBM Corporation.
 
3
 * All rights reserved. This program and the accompanying materials
 
4
 * are made available under the terms of the Eclipse Public License v1.0
 
5
 * which accompanies this distribution, and is available at
 
6
 * http://www.eclipse.org/legal/epl-v10.html
 
7
 *
 
8
 * Contributors:
 
9
 *     IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse
 
10
 *******************************************************************************/
 
11
 
 
12
package org.eclipse.linuxtools.systemtap.ui.consolelog.structures;
 
13
 
 
14
import org.eclipse.linuxtools.systemtap.ui.consolelog.internal.Localization;
 
15
import org.eclipse.linuxtools.systemtap.ui.consolelog.views.ErrorView;
 
16
 
 
17
/**
 
18
 * A class push data to both the </code>ScriptConsole</code> and the ErrorView
 
19
 * @author Ryan Morse
 
20
 */
 
21
public class ErrorStreamDaemon extends ConsoleStreamDaemon {
 
22
        public ErrorStreamDaemon(ScriptConsole console, ErrorView errorWindow, IErrorParser parser) {
 
23
                super(console);
 
24
 
 
25
                outputData = new StringBuilder();
 
26
                this.parser = parser;
 
27
                
 
28
                errorView = errorWindow;
 
29
                errorView.clear();
 
30
        }
 
31
        
 
32
        /**
 
33
         * Prints out the new output data to the console and parses it and sends it to the
 
34
         * ErrorView.
 
35
         */
 
36
        protected void pushData() {
 
37
                if(output.startsWith(Localization.getString("ErrorStreamDaemon.Password")))
 
38
                        output = output.substring(Localization.getString("ErrorStreamDaemon.Password").length());
 
39
 
 
40
                super.pushData();
 
41
 
 
42
                outputData.append(output);
 
43
                
 
44
                /* Since we never know when the last set of data is comming we don't clear the 
 
45
                 * errorStream in the hope of getting a more complete error message. As a result 
 
46
                 * the parser will always return what we already had.  Clear removes anything 
 
47
                 * that was added before.
 
48
                 */
 
49
                if(null != errorView) {
 
50
                        String[][] errors = parser.parseOutput(outputData.toString());
 
51
 
 
52
                        if(null != errors) {
 
53
                                errorView.clear();
 
54
                                for(int i=0; i<errors.length; i++)
 
55
                                        errorView.add(errors[i]);
 
56
                        }
 
57
                }
 
58
        }
 
59
        
 
60
        /**
 
61
         * Disposes of all internal references in the class. No method should be called after this.
 
62
         */
 
63
        public void dispose() {
 
64
                if(!isDisposed()) {
 
65
                        super.dispose();
 
66
                        errorView = null;
 
67
                        outputData.delete(0, outputData.length());
 
68
                        outputData = null;
 
69
                        parser = null;
 
70
                }
 
71
        }
 
72
        
 
73
        private ErrorView errorView;
 
74
        private StringBuilder outputData;
 
75
        private IErrorParser parser;
 
76
}