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
9
* Ericsson - initial API and implementation
10
*******************************************************************************/
11
package org.eclipse.cdt.dsf.gdb.internal.tracepointactions;
13
import java.io.ByteArrayOutputStream;
14
import java.io.StringReader;
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;
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;
29
import com.ibm.icu.text.MessageFormat;
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$
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;
45
public String getDefaultName() {
46
return MessagesForTracepointActions.TracepointActions_Untitled_WhileStepping;
49
public String getSubActionsNames() {
50
return fSubActionNames;
53
public void setSubActionsNames(String str) {
54
fSubActionNames = str;
57
public String getSubActionsContent() {
58
return fSubActionContent;
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$
67
for (String name : names) {
68
ITracepointAction action = TracepointActionManager.getInstance().findAction(name.trim());
70
fSubActionContent += action.getSummary() + ","; //$NON-NLS-1$
74
if (fSubActionContent.length() >0) {
75
fSubActionContent = fSubActionContent.substring(0, fSubActionContent.length()-1);
79
public int getStepCount() {
83
public void setStepCount(int count) {
87
public String getIdentifier() {
88
return WHILE_STEPPING_ACTION_ID;
91
public String getMemento() {
92
String collectData = new String(""); //$NON-NLS-1$
94
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
95
DocumentBuilder docBuilder = null;
97
docBuilder = dfactory.newDocumentBuilder();
98
Document doc = docBuilder.newDocument();
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$
104
doc.appendChild(rootElement);
106
ByteArrayOutputStream s = new ByteArrayOutputStream();
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$
113
DOMSource source = new DOMSource(doc);
114
StreamResult outputTarget = new StreamResult(s);
115
transformer.transform(source, outputTarget);
117
collectData = s.toString("UTF8"); //$NON-NLS-1$
119
} catch (Exception e) {
125
public String getSummary() {
126
return MessageFormat.format(MessagesForTracepointActions.TracepointActions_WhileStepping_text, new Object[] { fStepCount, fSubActionContent });
129
public String getTypeName() {
130
return MessagesForTracepointActions.TracepointActions_WhileStepping_Name;
133
public void initializeFromMemento(String data) {
135
DocumentBuilder parser;
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) {
151
public String toString() {
152
return MessageFormat.format(MessagesForTracepointActions.TracepointActions_WhileStepping_text, new Object[] { fStepCount, fSubActionContent });