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: /*
020: * Created on Jun 13, 2003
021: */
022: package org.apache.jmeter.util;
023:
024: import java.io.File;
025: import java.io.FileInputStream;
026: import java.io.FileNotFoundException;
027: import java.io.IOException;
028: import java.util.Properties;
029:
030: import org.apache.jorphan.logging.LoggingManager;
031: import org.apache.jorphan.util.JOrphanUtils;
032: import org.apache.log.Logger;
033:
034: /**
035: * @author ano ano
036: * @version $Revision: 579227 $
037: */
038: public final class NameUpdater {
039: private static Properties nameMap;
040:
041: private static Logger log = LoggingManager.getLoggerForClass();
042:
043: static {
044: nameMap = new Properties();
045: FileInputStream fis = null;
046: File f = new File(JMeterUtils.getJMeterHome(), JMeterUtils
047: .getPropDefault("upgrade_properties", // $NON-NLS-1$
048: "/bin/upgrade.properties")); // $NON-NLS-1$
049: try {
050: fis = new FileInputStream(f);
051: nameMap.load(fis);
052: } catch (FileNotFoundException e) {
053: log.error("Could not find upgrade file: ", e);
054: } catch (IOException e) {
055: log.error("Error processing upgrade file: " + f.getPath(),
056: e);
057: } finally {
058: JOrphanUtils.closeQuietly(fis);
059: }
060: }
061:
062: public static String getCurrentName(String className) {
063: if (nameMap.containsKey(className)) {
064: String newName = nameMap.getProperty(className);
065: log.info("Upgrading class " + className + " to " + newName);
066: return newName;
067: }
068: return className;
069: }
070:
071: /**
072: * Looks up test element / gui class combination; if that
073: * does not exist in the map, then defaults to getCurrentName.
074: *
075: * @param testClassName - test element class name
076: * @param guiClassName - associated gui class name
077: * @return new test class name
078: */
079:
080: public static String getCurrentTestName(String testClassName,
081: String guiClassName) {
082: String key = testClassName + "|" + guiClassName;
083: if (nameMap.containsKey(key)) {
084: String newName = nameMap.getProperty(key);
085: log.info("Upgrading " + key + " to " + newName);
086: return newName;
087: }
088: return getCurrentName(testClassName);
089: }
090:
091: public static String getCurrentName(String propertyName,
092: String className) {
093: String key = className + "/" + propertyName;
094: if (nameMap.containsKey(key)) {
095: String newName = nameMap.getProperty(key);
096: log.info("Upgrading property " + propertyName + " to "
097: + newName);
098: return newName;
099: }
100: return propertyName;
101: }
102:
103: public static String getCurrentName(String value,
104: String propertyName, String className) {
105: String key = className + "." + propertyName + "/" + value;
106: if (nameMap.containsKey(key)) {
107: String newValue = nameMap.getProperty(key);
108: log.info("Upgrading value " + value + " to " + newValue);
109: return newValue;
110: }
111: return value;
112: }
113:
114: /**
115: * Private constructor to prevent instantiation.
116: */
117: private NameUpdater() {
118: }
119: }
|