You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by se...@apache.org on 2011/11/25 04:02:13 UTC

svn commit: r1206045 - in /jmeter/trunk: src/core/org/apache/jmeter/testbeans/gui/FileEditor.java src/jorphan/org/apache/jorphan/util/Converter.java xdocs/changes.xml

Author: sebb
Date: Fri Nov 25 03:02:12 2011
New Revision: 1206045

URL: http://svn.apache.org/viewvc?rev=1206045&view=rev
Log:
Bug 52242 - FileEditor does not allow output to be saved in a File 

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/FileEditor.java
    jmeter/trunk/src/jorphan/org/apache/jorphan/util/Converter.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/FileEditor.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/FileEditor.java?rev=1206045&r1=1206044&r2=1206045&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/FileEditor.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/FileEditor.java Fri Nov 25 03:02:12 2011
@@ -195,41 +195,28 @@ public class FileEditor implements Prope
 
     private static class SimpleFileEditor extends PropertyEditorSupport {
 
-        /**
-         * {@inheritDoc}
-         */
         @Override
         public String getAsText() {
-            return ((File) super.getValue()).getPath();
+            Object value = super.getValue();
+            if (value instanceof File) {
+                return ((File) value).getPath();
+            }
+            return (String) value; // assume it's string
         }
 
-        /**
-         * {@inheritDoc}
-         */
         @Override
         public void setAsText(String text) throws IllegalArgumentException {
             super.setValue(new File(text));
         }
 
-        /**
-         * JMeter doesn't support File properties yet. Need to
-         * work on this as a String :-(
-         * <p>
-         * {@inheritDoc}
-         */
         @Override
         public Object getValue() {
-            return getAsText(); // should be super.getValue();
+            return super.getValue();
         }
 
-        /**
-         * I need to handle Strings when setting too.
-         * <p>
-         * {@inheritDoc}
-         */
         @Override
         public void setValue(Object file) {
-            setAsText((String) file);
+            super.setValue(file);
         }
     }
 }
\ No newline at end of file

Modified: jmeter/trunk/src/jorphan/org/apache/jorphan/util/Converter.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/jorphan/org/apache/jorphan/util/Converter.java?rev=1206045&r1=1206044&r2=1206045&view=diff
==============================================================================
--- jmeter/trunk/src/jorphan/org/apache/jorphan/util/Converter.java (original)
+++ jmeter/trunk/src/jorphan/org/apache/jorphan/util/Converter.java Fri Nov 25 03:02:12 2011
@@ -17,6 +17,7 @@
  */
 package org.apache.jorphan.util;
 
+import java.io.File;
 import java.text.DateFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
@@ -39,7 +40,7 @@ public class Converter {
      */
     public static Object convert(Object value, Class<?> toType) {
         if (value == null) {
-            value = "";
+            value = ""; // TODO should we allow null for non-primitive types?
         } else if (toType.isAssignableFrom(value.getClass())) {
             return value;
         } else if (toType.equals(float.class) || toType.equals(Float.class)) {
@@ -60,6 +61,8 @@ public class Converter {
             return getDate(value);
         } else if (toType.equals(Calendar.class)) {
             return getCalendar(value);
+        } else if (toType.equals(File.class)) {
+            return getFile(value);
         } else if (toType.equals(Class.class)) {
             try {
                 return Class.forName(value.toString());
@@ -367,4 +370,14 @@ public class Converter {
     public static String getString(Object o) {
         return getString(o, "");
     }
+    
+    public static File getFile(Object o){
+        if (o instanceof File) {
+            return (File) o;
+        }
+        if (o instanceof String) {
+            return new File((String) o);
+        }
+        throw new IllegalArgumentException("Expected String or file, actual "+o.getClass().getName());
+    }
 }

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1206045&r1=1206044&r2=1206045&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Fri Nov 25 03:02:12 2011
@@ -228,6 +228,7 @@ Loads any additional properties found in
 <li>Bug 46921 - Add Ability to Change Controller elements</li>
 <li>Bug 52240 - TestBeans should support Boolean, Integer and Long</li>
 <li>Bug 52241 - GenericTestBeanCustomizer assumes that the default value is the empty string</li>
+<li>Bug 52242 - FileEditor does not allow output to be saved in a File </li>
 </ul>
 
 <h2>Non-functional changes</h2>