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 js...@apache.org on 2004/01/16 00:50:19 UTC

cvs commit: jakarta-jmeter/src/core/org/apache/jmeter/util NameUpdater.java

jsalvata    2004/01/15 15:50:19

  Modified:    src/core/org/apache/jmeter/save SaveService.java
               src/core/org/apache/jmeter/util NameUpdater.java
  Log:
  Ability to upgrade property names and, to some extent, values.
  
  Revision  Changes    Path
  1.34      +37 -26    jakarta-jmeter/src/core/org/apache/jmeter/save/SaveService.java
  
  Index: SaveService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/save/SaveService.java,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- SaveService.java	7 Jan 2004 00:29:35 -0000	1.33
  +++ SaveService.java	15 Jan 2004 23:50:19 -0000	1.34
  @@ -86,6 +86,7 @@
   import org.apache.jmeter.testelement.property.CollectionProperty;
   import org.apache.jmeter.testelement.property.JMeterProperty;
   import org.apache.jmeter.testelement.property.MapProperty;
  +import org.apache.jmeter.testelement.property.StringProperty;
   import org.apache.jmeter.testelement.property.TestElementProperty;
   import org.apache.jmeter.util.JMeterUtils;
   import org.apache.jmeter.util.NameUpdater;
  @@ -997,12 +998,9 @@
       {
           TestElement element = null;
   
  -        element =
  -            (TestElement) Class
  -                .forName(
  -                    NameUpdater.getCurrentName(
  -                        (String) config.getAttribute("class")))
  -                .newInstance();
  +		String testClass= (String) config.getAttribute("class");
  +        element = (TestElement) Class.forName(
  +        	NameUpdater.getCurrentName(testClass)).newInstance();
           Configuration[] children = config.getChildren();
   
           for (int i = 0; i < children.length; i++)
  @@ -1011,7 +1009,7 @@
               {
                   try
                   {
  -                    element.setProperty(createProperty(children[i]));
  +                    element.setProperty(createProperty(children[i], testClass));
                   }
                   catch (Exception ex)
                   {
  @@ -1031,20 +1029,21 @@
                   element.setProperty(
                       new CollectionProperty(
                           children[i].getAttribute("name",""),
  -                        createCollection(children[i])));
  +                        createCollection(children[i], testClass)));
               }
               else if (children[i].getName().equals("map"))
               {
                   element.setProperty(
                       new MapProperty(
                           children[i].getAttribute("name",""),
  -                        createMap(children[i])));
  +                        createMap(children[i], testClass)));
               }
           }
           return element;
       }
   
  -    private static Collection createCollection(Configuration config)
  +    private static Collection createCollection(
  +    		Configuration config, String testClass)
           throws
               ConfigurationException,
               ClassNotFoundException,
  @@ -1061,7 +1060,7 @@
           {
               if (items[i].getName().equals("property"))
               {
  -                coll.add(createProperty(items[i]));
  +                coll.add(createProperty(items[i], testClass));
               }
               else if (items[i].getName().equals("testelement"))
               {
  @@ -1075,24 +1074,24 @@
                   coll.add(
                       new CollectionProperty(
                           items[i].getAttribute("name", ""),
  -                        createCollection(items[i])));
  +                        createCollection(items[i], testClass)));
               }
               else if (items[i].getName().equals("string"))
               {
  -                coll.add(createProperty(items[i]));
  +                coll.add(createProperty(items[i], testClass));
               }
               else if (items[i].getName().equals("map"))
               {
                   coll.add(
                       new MapProperty(
                           items[i].getAttribute("name", ""),
  -                        createMap(items[i])));
  +                        createMap(items[i], testClass)));
               }
           }
           return coll;
       }
   
  -    private static JMeterProperty createProperty(Configuration config)
  +    private static JMeterProperty createProperty(Configuration config, String testClass)
           throws
               ConfigurationException,
               IllegalAccessException,
  @@ -1100,17 +1099,29 @@
               InstantiationException
       {
           String value = config.getValue("");
  -        JMeterProperty prop = (JMeterProperty) Class.forName(
  -                config.getAttribute(
  -                    "propType",
  -                    "org.apache.jmeter.testelement.property.StringProperty"))
  -                .newInstance();
  -        prop.setName(config.getAttribute("name", value));
  +        String name= config.getAttribute("name", value);
  +		String type= config.getAttribute("propType", StringProperty.class.getName());
  +		
  +		// Do upgrade translation:
  +		name= NameUpdater.getCurrentName(name, testClass);
  +		if (TestElement.GUI_CLASS.equals(name) || TestElement.TEST_CLASS.equals(name))
  +		{
  +			value= NameUpdater.getCurrentName(value);
  +		}
  +		else
  +		{
  +			value= NameUpdater.getCurrentName(value, name, testClass);
  +		}
  +		
  +        // Create the property:
  +        JMeterProperty prop = (JMeterProperty) Class.forName(type).newInstance();
  +        prop.setName(name);
           prop.setObjectValue(value);
  +
           return prop;
       }
   
  -    private static Map createMap(Configuration config)
  +    private static Map createMap(Configuration config, String testClass)
           throws
               ConfigurationException,
               ClassNotFoundException,
  @@ -1127,7 +1138,7 @@
           {
               if (items[i].getName().equals("property"))
               {
  -                JMeterProperty prop = createProperty(items[i]);
  +                JMeterProperty prop = createProperty(items[i], testClass);
                   map.put(prop.getName(), prop);
               }
               else if (items[i].getName().equals("testelement"))
  @@ -1144,7 +1155,7 @@
                       items[i].getAttribute("name"),
                       new CollectionProperty(
                           items[i].getAttribute("name", ""),
  -                        createCollection(items[i])));
  +                        createCollection(items[i], testClass)));
               }
               else if (items[i].getName().equals("map"))
               {
  @@ -1152,7 +1163,7 @@
                       items[i].getAttribute("name", ""),
                       new MapProperty(
                           items[i].getAttribute("name", ""),
  -                        createMap(items[i])));
  +                        createMap(items[i], testClass)));
               }
           }
           return map;
  
  
  
  1.4       +34 -8     jakarta-jmeter/src/core/org/apache/jmeter/util/NameUpdater.java
  
  Index: NameUpdater.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/util/NameUpdater.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- NameUpdater.java	18 Aug 2003 19:40:41 -0000	1.3
  +++ NameUpdater.java	15 Jan 2004 23:50:19 -0000	1.4
  @@ -35,15 +35,41 @@
           }
       }
       
  -    public static String getCurrentName(String guiName)
  +    public static String getCurrentName(String className)
       {
  -        if(nameMap.containsKey(guiName))
  -        {
  -            return nameMap.getProperty(guiName);
  -        }
  -        return guiName;
  +    	if (nameMap.containsKey(className))
  +    	{
  +			String newName= nameMap.getProperty(className);
  +    		log.info("Upgrading class "+className+" to "+newName);
  +    		return newName; 
  +    	}
  +        return className;
       }
  -    
  +
  +	public static String getCurrentName(String propertyName, String className)
  +	{
  +		String key= className+"/"+propertyName;
  +		if (nameMap.containsKey(key))
  +		{
  +			String newName= nameMap.getProperty(key);
  +			log.info("Upgrading property "+propertyName+" to "+newName);
  +			return newName;
  +		}
  +		return propertyName;
  +	}
  +
  +	public static String getCurrentName(String value, String propertyName, String className)
  +	{
  +		String key= className+"."+propertyName+"/"+value;
  +		if (nameMap.containsKey(key))
  +		{
  +			String newValue= nameMap.getProperty(key);
  +			log.info("Upgrading value "+value+" to "+newValue);
  +			return newValue;
  +		}
  +		return value;
  +	}
  +
       /**
        * Private constructor to prevent instantiation.
        */
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org