~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/internal/tracepointactions/WhileSteppingAction.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (c) 2010 Ericsson and others.
 
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
 *     Ericsson - initial API and implementation
 
10
 *******************************************************************************/
 
11
package org.eclipse.cdt.dsf.gdb.internal.tracepointactions;
 
12
 
 
13
import java.io.ByteArrayOutputStream;
 
14
import java.io.StringReader;
 
15
 
 
16
import javax.xml.parsers.DocumentBuilder;
 
17
import javax.xml.parsers.DocumentBuilderFactory;
 
18
import javax.xml.transform.OutputKeys;
 
19
import javax.xml.transform.Transformer;
 
20
import javax.xml.transform.TransformerFactory;
 
21
import javax.xml.transform.dom.DOMSource;
 
22
import javax.xml.transform.stream.StreamResult;
 
23
 
 
24
import org.w3c.dom.Document;
 
25
import org.w3c.dom.Element;
 
26
import org.xml.sax.InputSource;
 
27
import org.xml.sax.helpers.DefaultHandler;
 
28
 
 
29
import com.ibm.icu.text.MessageFormat;
 
30
 
 
31
/**
 
32
 * @since 3.0
 
33
 */
 
34
public class WhileSteppingAction extends AbstractTracepointAction {
 
35
        private static final String WHILE_STEPPING_ACTION_ID = "org.eclipse.cdt.dsf.gdb.tracepointactions.WhileSteppingAction"; //$NON-NLS-1$
 
36
 
 
37
        // The name of the sub actions
 
38
        private String fSubActionNames = ""; //$NON-NLS-1$
 
39
        // A comma-separated string of the actual content of each sub command
 
40
        // This is the string than can be sent to GDB
 
41
        private String fSubActionContent = ""; //$NON-NLS-1$
 
42
        // The number of steps this while-stepping command will occur
 
43
        private int fStepCount = 1;
 
44
        
 
45
        public String getDefaultName() {
 
46
                return MessagesForTracepointActions.TracepointActions_Untitled_WhileStepping;
 
47
        }
 
48
 
 
49
        public String getSubActionsNames() {
 
50
                return fSubActionNames;
 
51
        }
 
52
        
 
53
        public void setSubActionsNames(String str) {
 
54
                fSubActionNames = str;
 
55
        }
 
56
 
 
57
        public String getSubActionsContent() {
 
58
                return fSubActionContent;
 
59
        }
 
60
        
 
61
        // Take all the sub action names, and find their corresponding action,
 
62
        // then build the content string
 
63
        public void setSubActionsContent(String subActionNames) {
 
64
                String[] names = subActionNames.split(","); //$NON-NLS-1$
 
65
                fSubActionContent = ""; //$NON-NLS-1$
 
66
                
 
67
                for (String name : names) {
 
68
                        ITracepointAction action = TracepointActionManager.getInstance().findAction(name.trim());
 
69
                        if (action != null) {
 
70
                                fSubActionContent += action.getSummary() + ","; //$NON-NLS-1$
 
71
                        }
 
72
                }
 
73
                // Remove last comma
 
74
                if (fSubActionContent.length() >0) {
 
75
                        fSubActionContent = fSubActionContent.substring(0, fSubActionContent.length()-1);
 
76
                }
 
77
        }
 
78
 
 
79
        public int getStepCount() {
 
80
                return fStepCount;
 
81
        }
 
82
 
 
83
        public void setStepCount(int count) {
 
84
                fStepCount = count;
 
85
        }
 
86
 
 
87
        public String getIdentifier() {
 
88
                return WHILE_STEPPING_ACTION_ID;
 
89
        }
 
90
 
 
91
        public String getMemento() {
 
92
                String collectData = new String(""); //$NON-NLS-1$
 
93
 
 
94
                DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
 
95
                DocumentBuilder docBuilder = null;
 
96
                try {
 
97
                        docBuilder = dfactory.newDocumentBuilder();
 
98
                        Document doc = docBuilder.newDocument();
 
99
 
 
100
                        Element rootElement = doc.createElement("whileSteppingData"); //$NON-NLS-1$
 
101
                        rootElement.setAttribute("whileSteppingCount", Integer.toString(fStepCount)); //$NON-NLS-1$
 
102
                        rootElement.setAttribute("subActionNames", fSubActionNames); //$NON-NLS-1$
 
103
 
 
104
                        doc.appendChild(rootElement);
 
105
 
 
106
                        ByteArrayOutputStream s = new ByteArrayOutputStream();
 
107
 
 
108
                        TransformerFactory factory = TransformerFactory.newInstance();
 
109
                        Transformer transformer = factory.newTransformer();
 
110
                        transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
 
111
                        transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
 
112
 
 
113
                        DOMSource source = new DOMSource(doc);
 
114
                        StreamResult outputTarget = new StreamResult(s);
 
115
                        transformer.transform(source, outputTarget);
 
116
 
 
117
                        collectData = s.toString("UTF8"); //$NON-NLS-1$
 
118
 
 
119
                } catch (Exception e) {
 
120
                        e.printStackTrace();
 
121
                }
 
122
                return collectData;
 
123
        }
 
124
 
 
125
        public String getSummary() {
 
126
                return MessageFormat.format(MessagesForTracepointActions.TracepointActions_WhileStepping_text, new Object[] { fStepCount, fSubActionContent });
 
127
        }
 
128
 
 
129
        public String getTypeName() {
 
130
                return MessagesForTracepointActions.TracepointActions_WhileStepping_Name;
 
131
        }
 
132
 
 
133
        public void initializeFromMemento(String data) {
 
134
                Element root = null;
 
135
                DocumentBuilder parser;
 
136
                try {
 
137
                        parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
 
138
                        parser.setErrorHandler(new DefaultHandler());
 
139
                        root = parser.parse(new InputSource(new StringReader(data))).getDocumentElement();
 
140
                        setStepCount(Integer.parseInt(root.getAttribute("whileSteppingCount"))); //$NON-NLS-1$
 
141
                        setSubActionsNames(root.getAttribute("subActionNames")); //$NON-NLS-1$
 
142
                        if (fSubActionNames == null)
 
143
                                throw new Exception();
 
144
                        setSubActionsContent(fSubActionNames);
 
145
                } catch (Exception e) {
 
146
                        e.printStackTrace();
 
147
                }
 
148
        }
 
149
        
 
150
        @Override
 
151
        public String toString() {
 
152
                return MessageFormat.format(MessagesForTracepointActions.TracepointActions_WhileStepping_text, new Object[] { fStepCount, fSubActionContent });
 
153
        }
 
154
}