You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by wo...@apache.org on 2005/08/24 05:40:07 UTC
cvs commit: jakarta-jmeter/src/components/org/apache/jmeter/control/gui IncludeControllerGui.java
woolfel 2005/08/23 20:40:07
Added: src/components/org/apache/jmeter/control
IncludeController.java
src/components/org/apache/jmeter/control/gui
IncludeControllerGui.java
Log:
adding the rough implementation of the include controller. it isn't working, but hopefully
mike can take a look. my cold is making it hard to think clealry
peter
Revision Changes Path
1.1 jakarta-jmeter/src/components/org/apache/jmeter/control/IncludeController.java
Index: IncludeController.java
===================================================================
// $Header: /home/cvs/jakarta-jmeter/src/components/org/apache/jmeter/control/IncludeController.java,v 1.1 2005/08/24 03:40:07 woolfel Exp $
/*
* Copyright 2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.jmeter.control;
import java.io.FileInputStream;
import java.io.InputStream;
import org.apache.jmeter.gui.GuiPackage;
import org.apache.jmeter.exceptions.IllegalUserActionException;
import org.apache.jmeter.save.SaveService;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.collections.HashTree;
import org.apache.jorphan.collections.SearchByClass;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;
/**
*
*
* @author Peter Lin
* @version $Revision: 1.1 $
*/
public class IncludeController extends GenericController implements ReplaceableController {
private static final Logger log = LoggingManager.getLoggerForClass();
public static final String INCLUDE_PATH = "IncludeController.includepath";
private Controller INCLUDED_ELEMENTS = null;
private HashTree SUBTREE = null;
/**
* No-arg constructor
*
* @see java.lang.Object#Object()
*/
public IncludeController() {
super();
}
public Object clone() {
IncludeController clone = (IncludeController) super.clone();
return clone;
}
/**
* In the event an user wants to include an external JMX test plan
* the GUI would call this.
* @param jmxfile
*/
public void setIncludePath(String jmxfile) {
this.setProperty(INCLUDE_PATH,jmxfile);
}
/**
* return the JMX file path.
* @return
*/
public String getIncludePath() {
return this.getPropertyAsString(INCLUDE_PATH);
}
public TestElement getReplacement() {
this.loadIncludedElements();
return this;
}
/**
* Copies the controller's subelements into the execution tree
*
* @param tree -
* The current tree under which the nodes will be added
*/
public void replace(HashTree tree) {
/**
*
HashTree thistree = findTree(tree);
if (thistree != null) {
thistree.add(loadIncludedElements());
log.info("replace - added the include tree");
}
*/
try {
GuiPackage.getInstance().addSubTree(loadIncludedElements());
} catch (IllegalUserActionException e) {
log.warn(e.getMessage());
}
}
public HashTree findTree(HashTree tree) {
log.info("search the tree ---- " + tree.size() + " --- " + tree.hashCode());
SearchByClass search = new SearchByClass(IncludeController.class);
tree.traverse(search);
return search.getSubTree(this);
}
/**
* load the included elements using SaveService
* @param node
*/
protected HashTree loadIncludedElements() {
// only try to load the JMX test plan if there is one
if (getIncludePath() != null && getIncludePath().length() > 0) {
try {
log.info("loadIncludedElements -- try to load included module");
InputStream reader = new FileInputStream(getIncludePath());
this.SUBTREE = SaveService.loadTree(reader);
return this.SUBTREE;
} catch (NoClassDefFoundError ex) // Allow for missing optional jars
{
String msg = ex.getMessage();
if (msg == null) {
msg = "Missing jar file - see log for details";
log.warn("Missing jar file", ex);
}
JMeterUtils.reportErrorToUser(msg);
} catch (Exception ex) {
String msg = ex.getMessage();
if (msg == null) {
msg = "Unexpected error - see log for details";
log.warn("Unexpected error", ex);
}
}
}
return this.SUBTREE;
}
}
1.1 jakarta-jmeter/src/components/org/apache/jmeter/control/gui/IncludeControllerGui.java
Index: IncludeControllerGui.java
===================================================================
// $Header: /home/cvs/jakarta-jmeter/src/components/org/apache/jmeter/control/gui/IncludeControllerGui.java,v 1.1 2005/08/24 03:40:07 woolfel Exp $
/*
* Copyright 2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.jmeter.control.gui;
import java.awt.FlowLayout;
import java.util.Collection;
import java.util.Iterator;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import org.apache.jmeter.control.IncludeController;
import org.apache.jmeter.gui.util.FilePanel;
import org.apache.jmeter.gui.util.MenuFactory;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.gui.layout.VerticalLayout;
/**
*
*
* @version $Revision: 1.1 $ on $Date: 2005/08/24 03:40:07 $
*/
public class IncludeControllerGui extends AbstractControllerGui
/*
* implements
* UnsharedComponent
*/
{
private JLabel warningLabel;
private FilePanel includePanel =
new FilePanel(JMeterUtils.getResString("include_path"), ".jmx");
public static final String CONTROLLER = "Module To Run";
/**
* Initializes the gui panel for the ModuleController instance.
*/
public IncludeControllerGui() {
init();
}
public String getLabelResource() {
return "include_controller";
}
/*
* (non-Javadoc)
*
* @see org.apache.jmeter.gui.JMeterGUIComponent#configure(TestElement)
*/
public void configure(TestElement el) {
super.configure(el);
IncludeController controller = (IncludeController) el;
this.includePanel.setFilename(controller.getIncludePath());
}
private String renderPath(Collection path) {
Iterator iter = path.iterator();
StringBuffer buf = new StringBuffer();
boolean first = true;
while (iter.hasNext()) {
if (first) {
first = false;
iter.next();
continue;
}
buf.append(iter.next());
if (iter.hasNext())
buf.append(" > ");
}
return buf.toString();
}
/*
* (non-Javadoc)
*
* @see org.apache.jmeter.gui.JMeterGUIComponent#createTestElement()
*/
public TestElement createTestElement() {
IncludeController mc = new IncludeController();
configureTestElement(mc);
return mc;
}
/*
* (non-Javadoc)
*
* @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
*/
public void modifyTestElement(TestElement element) {
configureTestElement(element);
IncludeController controller = (IncludeController)element;
controller.setIncludePath(this.includePanel.getFilename());
}
public JPopupMenu createPopupMenu() {
JPopupMenu menu = new JPopupMenu();
JMenu addMenu = MenuFactory.makeMenus(new String[] { MenuFactory.CONFIG_ELEMENTS, MenuFactory.ASSERTIONS,
MenuFactory.TIMERS, MenuFactory.LISTENERS, }, JMeterUtils.getResString("Add"), "Add");
menu.add(addMenu);
MenuFactory.addEditMenu(menu, true);
MenuFactory.addFileMenu(menu);
return menu;
}
private void init() {
setLayout(new VerticalLayout(5, VerticalLayout.LEFT, VerticalLayout.TOP));
setBorder(makeBorder());
add(makeTitlePanel());
// DROP-DOWN MENU
JPanel modulesPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 20, 5));
modulesPanel.add(new JLabel(CONTROLLER));
warningLabel = new JLabel("");
modulesPanel.add(warningLabel);
add(modulesPanel);
add(includePanel);
}
private String spaces(int level) {
int multi = 4;
StringBuffer spaces = new StringBuffer(level * multi);
for (int i = 0; i < level * multi; i++) {
spaces.append(" ");
}
return spaces.toString();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org