Source Code Cross Referenced for Save.java in  » Testing » jakarta-jmeter » org » apache » jmeter » gui » action » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » jakarta jmeter » org.apache.jmeter.gui.action 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *   http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         * 
017:         */
018:
019:        package org.apache.jmeter.gui.action;
020:
021:        import java.awt.event.ActionEvent;
022:        import java.io.File;
023:        import java.io.FileOutputStream;
024:        import java.util.HashSet;
025:        import java.util.Iterator;
026:        import java.util.LinkedList;
027:        import java.util.Set;
028:
029:        import javax.swing.JFileChooser;
030:        import javax.swing.JOptionPane;
031:
032:        import org.apache.commons.io.FilenameUtils;
033:        import org.apache.jmeter.exceptions.IllegalUserActionException;
034:        import org.apache.jmeter.gui.GuiPackage;
035:        import org.apache.jmeter.gui.tree.JMeterTreeNode;
036:        import org.apache.jmeter.gui.util.FileDialoger;
037:        import org.apache.jmeter.save.OldSaveService;
038:        import org.apache.jmeter.save.SaveService;
039:        import org.apache.jmeter.testelement.TestElement;
040:        import org.apache.jmeter.util.JMeterUtils;
041:        import org.apache.jorphan.collections.HashTree;
042:        import org.apache.jorphan.logging.LoggingManager;
043:        import org.apache.jorphan.util.JOrphanUtils;
044:        import org.apache.log.Logger;
045:
046:        /**
047:         * Save the current test plan; implements:
048:         * Save
049:         * Save TestPlan As
050:         * Save (Selection) As
051:         */
052:        public class Save implements  Command {
053:            private static final Logger log = LoggingManager
054:                    .getLoggerForClass();
055:
056:            public final static String JMX_FILE_EXTENSION = ".jmx"; // $NON-NLS-1$
057:
058:            private static Set commands = new HashSet();
059:            static {
060:                commands.add(ActionNames.SAVE_AS); // Save (Selection) As
061:                commands.add(ActionNames.SAVE_ALL_AS); // Save TestPlan As
062:                commands.add(ActionNames.SAVE); // Save
063:            }
064:
065:            /**
066:             * Constructor for the Save object.
067:             */
068:            public Save() {
069:            }
070:
071:            /**
072:             * Gets the ActionNames attribute of the Save object.
073:             * 
074:             * @return the ActionNames value
075:             */
076:            public Set getActionNames() {
077:                return commands;
078:            }
079:
080:            public void doAction(ActionEvent e)
081:                    throws IllegalUserActionException {
082:                HashTree subTree = null;
083:                if (!commands.contains(e.getActionCommand())) {
084:                    throw new IllegalUserActionException(
085:                            "Invalid user command:" + e.getActionCommand());
086:                }
087:                if (e.getActionCommand().equals(ActionNames.SAVE_AS)) {
088:                    JMeterTreeNode[] nodes = GuiPackage.getInstance()
089:                            .getTreeListener().getSelectedNodes();
090:                    if (nodes.length > 1) {
091:                        JMeterUtils.reportErrorToUser(JMeterUtils
092:                                .getResString("save_as_error"), // $NON-NLS-1$
093:                                JMeterUtils.getResString("save_as")); // $NON-NLS-1$
094:                        return;
095:                    }
096:                    subTree = GuiPackage.getInstance().getCurrentSubTree();
097:                } else {
098:                    subTree = GuiPackage.getInstance().getTreeModel()
099:                            .getTestPlan();
100:                }
101:
102:                String updateFile = GuiPackage.getInstance().getTestPlanFile();
103:                if (!ActionNames.SAVE.equals(e.getActionCommand())
104:                        || updateFile == null) {
105:                    JFileChooser chooser = FileDialoger
106:                            .promptToSaveFile(GuiPackage.getInstance()
107:                                    .getTreeListener().getCurrentNode()
108:                                    .getName()
109:                                    + JMX_FILE_EXTENSION);
110:                    if (chooser == null) {
111:                        return;
112:                    }
113:                    updateFile = chooser.getSelectedFile().getAbsolutePath();
114:                    // Make sure the file ends with proper extension
115:                    if (FilenameUtils.getExtension(updateFile).equals("")) {
116:                        updateFile = updateFile + JMX_FILE_EXTENSION;
117:                    }
118:                    // Check if the user is trying to save to an existing file
119:                    if (!e.getActionCommand().equals(ActionNames.SAVE)) {//so it must be a SAVE_AS action
120:                        File f = new File(updateFile);
121:                        if (f.exists()) {
122:                            int response = JOptionPane
123:                                    .showConfirmDialog(
124:                                            GuiPackage.getInstance()
125:                                                    .getMainFrame(),
126:                                            JMeterUtils
127:                                                    .getResString("save_overwrite_existing_file"), // $NON-NLS-1$
128:                                            JMeterUtils.getResString("save?"), // $NON-NLS-1$
129:                                            JOptionPane.YES_NO_OPTION,
130:                                            JOptionPane.QUESTION_MESSAGE);
131:                            if (response == JOptionPane.CLOSED_OPTION
132:                                    || response == JOptionPane.NO_OPTION) {
133:                                return; // Do not save, user does not want to overwrite
134:                            }
135:                        }
136:                    }
137:
138:                    if (!e.getActionCommand().equals(ActionNames.SAVE_AS)) {
139:                        GuiPackage.getInstance().setTestPlanFile(updateFile);
140:                    }
141:                }
142:                // TODO: doesn't putting this here mark the tree as
143:                // saved even though a failure may occur later?
144:
145:                ActionRouter.getInstance().doActionNow(
146:                        new ActionEvent(subTree, e.getID(),
147:                                ActionNames.SUB_TREE_SAVED));
148:                try {
149:                    convertSubTree(subTree);
150:                } catch (Exception err) {
151:                }
152:                FileOutputStream ostream = null;
153:                try {
154:                    ostream = new FileOutputStream(updateFile);
155:                    if (SaveService.isSaveTestPlanFormat20()) {
156:                        OldSaveService.saveSubTree(subTree, ostream);
157:                    } else {
158:                        SaveService.saveTree(subTree, ostream);
159:                    }
160:                } catch (Throwable ex) {
161:                    GuiPackage.getInstance().setTestPlanFile(null);
162:                    log.error("", ex);
163:                    throw new IllegalUserActionException(
164:                            "Couldn't save test plan to file: " + updateFile);
165:                } finally {
166:                    JOrphanUtils.closeQuietly(ostream);
167:                }
168:                GuiPackage.getInstance().updateCurrentGui();
169:            }
170:
171:            // package protected to all for separate test code
172:            void convertSubTree(HashTree tree) {
173:                Iterator iter = new LinkedList(tree.list()).iterator();
174:                while (iter.hasNext()) {
175:                    JMeterTreeNode item = (JMeterTreeNode) iter.next();
176:                    convertSubTree(tree.getTree(item));
177:                    TestElement testElement = item.getTestElement();
178:                    tree.replace(item, testElement);
179:                }
180:            }
181:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.