Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZeb Ford-Reitz2012-07-19 10:54:53 -0400
committerZeb Ford-Reitz2012-07-19 11:12:52 -0400
commit93c8c68102f643ff779f243e8a511b6c2f50ebbb (patch)
tree17c4a97b598f0f9f30ecc294c72d2b86db29e58f
parent09b96a377e08cc79b75635d88e39f6a69753d852 (diff)
downloadorg.eclipse.jubula.core-93c8c68102f643ff779f243e8a511b6c2f50ebbb.tar.gz
org.eclipse.jubula.core-93c8c68102f643ff779f243e8a511b6c2f50ebbb.tar.xz
org.eclipse.jubula.core-93c8c68102f643ff779f243e8a511b6c2f50ebbb.zip
Improves performance when retrieving i18n strings for component system.v1.2.1.201207310845v1.2.1.201207240704
This improves performance for any operation that makes use of this i18n mechanism, including retrieving, displaying, and sorting Component types and Test Data types. These sorts of operations are used very frequently when, for example, automatically refreshing the Component Names Browser while saving an Object Mapping Editor. The improvement is implemented via caching: The i18n keys/values are stored in a map as they are retrieved from their respective ResourceBundle. This prevents having to search through several ResourceBundles over and over again. The additional memory consumed by the map should be minimal, as there are not very many (less than 200, I believe) i18n values in the Component System. I have also removed a superfluous method, as it was always called with the "fallback" boolean argument true. I replaced all references with a call to the boolean-less equivalent "getString(String key)".
-rw-r--r--org.eclipse.jubula.client.archive/src/org/eclipse/jubula/client/archive/XmlImporter.java5
-rw-r--r--org.eclipse.jubula.client.core/src/org/eclipse/jubula/client/core/businessprocess/AbstractComponentNameMapper.java4
-rw-r--r--org.eclipse.jubula.client.core/src/org/eclipse/jubula/client/core/businessprocess/AbstractXMLReportGenerator.java5
-rw-r--r--org.eclipse.jubula.client.core/src/org/eclipse/jubula/client/core/businessprocess/TestresultSummaryBP.java2
-rw-r--r--org.eclipse.jubula.client.core/src/org/eclipse/jubula/client/core/model/CapParamDescriptionPO.java2
-rw-r--r--org.eclipse.jubula.client.core/src/org/eclipse/jubula/client/core/utils/StringHelper.java3
-rw-r--r--org.eclipse.jubula.client.ui.rcp/src/org/eclipse/jubula/client/ui/rcp/businessprocess/ProblemsBP.java9
-rw-r--r--org.eclipse.jubula.client.ui.rcp/src/org/eclipse/jubula/client/ui/rcp/controllers/propertysources/OMLogicNameGUIPropertySource.java3
-rw-r--r--org.eclipse.jubula.client.ui.rcp/src/org/eclipse/jubula/client/ui/rcp/dialogs/AbstractEditParametersDialog.java2
-rw-r--r--org.eclipse.jubula.client.ui.rcp/src/org/eclipse/jubula/client/ui/rcp/provider/labelprovider/CentralTestDataLabelProvider.java3
-rw-r--r--org.eclipse.jubula.tools/src/org/eclipse/jubula/tools/i18n/CompSystemI18n.java62
-rw-r--r--org.eclipse.jubula.tools/src/org/eclipse/jubula/tools/xml/businessmodell/CompSystem.java4
12 files changed, 45 insertions, 59 deletions
diff --git a/org.eclipse.jubula.client.archive/src/org/eclipse/jubula/client/archive/XmlImporter.java b/org.eclipse.jubula.client.archive/src/org/eclipse/jubula/client/archive/XmlImporter.java
index 59ec516cd..edfd47b77 100644
--- a/org.eclipse.jubula.client.archive/src/org/eclipse/jubula/client/archive/XmlImporter.java
+++ b/org.eclipse.jubula.client.archive/src/org/eclipse/jubula/client/archive/XmlImporter.java
@@ -1620,12 +1620,11 @@ class XmlImporter {
msgSb.append(xmlCap.getComponentType());
msgSb.append(StringConstants.NEWLINE + Messages.Action);
msgSb.append(StringConstants.COLON + StringConstants.SPACE);
- msgSb.append(CompSystemI18n.getString(
- xmlCap.getActionName(), true));
+ msgSb.append(CompSystemI18n.getString(xmlCap.getActionName()));
msgSb.append(StringConstants.NEWLINE + Messages.Parameter);
msgSb.append(StringConstants.COLON + StringConstants.SPACE);
msgSb.append(CompSystemI18n.getString(
- parDescList.get(tdRow).getName(), true));
+ parDescList.get(tdRow).getName()));
final String msg = msgSb.toString();
log.error(msg, ioobe);
continue;
diff --git a/org.eclipse.jubula.client.core/src/org/eclipse/jubula/client/core/businessprocess/AbstractComponentNameMapper.java b/org.eclipse.jubula.client.core/src/org/eclipse/jubula/client/core/businessprocess/AbstractComponentNameMapper.java
index 21161e8bf..5a1f5d678 100644
--- a/org.eclipse.jubula.client.core/src/org/eclipse/jubula/client/core/businessprocess/AbstractComponentNameMapper.java
+++ b/org.eclipse.jubula.client.core/src/org/eclipse/jubula/client/core/businessprocess/AbstractComponentNameMapper.java
@@ -143,8 +143,8 @@ public abstract class AbstractComponentNameMapper implements
compNamePo, msg,
MessageIDs.E_COMP_TYPE_INCOMPATIBLE, new String[]{
compNamePo.getName(),
- CompSystemI18n.getString(currType, true),
- CompSystemI18n.getString(userType, true)});
+ CompSystemI18n.getString(currType),
+ CompSystemI18n.getString(userType)});
}
getCompNameCache().addReuse(newGuid);
diff --git a/org.eclipse.jubula.client.core/src/org/eclipse/jubula/client/core/businessprocess/AbstractXMLReportGenerator.java b/org.eclipse.jubula.client.core/src/org/eclipse/jubula/client/core/businessprocess/AbstractXMLReportGenerator.java
index fc8550796..dae0cbae3 100644
--- a/org.eclipse.jubula.client.core/src/org/eclipse/jubula/client/core/businessprocess/AbstractXMLReportGenerator.java
+++ b/org.eclipse.jubula.client.core/src/org/eclipse/jubula/client/core/businessprocess/AbstractXMLReportGenerator.java
@@ -271,10 +271,9 @@ public abstract class AbstractXMLReportGenerator {
compEl.addText(
StringUtils.defaultString(resultNode.getComponentName()));
Element compTypeEl = insertInto.addElement("component-type"); //$NON-NLS-1$
- compTypeEl.addText(CompSystemI18n.getString(cap.getComponentType(),
- true));
+ compTypeEl.addText(CompSystemI18n.getString(cap.getComponentType()));
Element actionEl = insertInto.addElement("action-type"); //$NON-NLS-1$
- actionEl.addText(CompSystemI18n.getString(cap.getActionName(), true));
+ actionEl.addText(CompSystemI18n.getString(cap.getActionName()));
if (resultNode.getStatus() == TestResultNode.ERROR
|| resultNode.getStatus() == TestResultNode.RETRYING) {
diff --git a/org.eclipse.jubula.client.core/src/org/eclipse/jubula/client/core/businessprocess/TestresultSummaryBP.java b/org.eclipse.jubula.client.core/src/org/eclipse/jubula/client/core/businessprocess/TestresultSummaryBP.java
index 0bc539b79..29e20244e 100644
--- a/org.eclipse.jubula.client.core/src/org/eclipse/jubula/client/core/businessprocess/TestresultSummaryBP.java
+++ b/org.eclipse.jubula.client.core/src/org/eclipse/jubula/client/core/businessprocess/TestresultSummaryBP.java
@@ -266,7 +266,7 @@ public class TestresultSummaryBP {
parameter.setParameterName(param.getName());
parameter.setInternalParameterType(param.getType());
parameter.setParameterType(CompSystemI18n.getString(
- param.getType(), true));
+ param.getType()));
String paramValue = StringConstants.EMPTY;
//parameter-value
diff --git a/org.eclipse.jubula.client.core/src/org/eclipse/jubula/client/core/model/CapParamDescriptionPO.java b/org.eclipse.jubula.client.core/src/org/eclipse/jubula/client/core/model/CapParamDescriptionPO.java
index 6c72438a1..45920098f 100644
--- a/org.eclipse.jubula.client.core/src/org/eclipse/jubula/client/core/model/CapParamDescriptionPO.java
+++ b/org.eclipse.jubula.client.core/src/org/eclipse/jubula/client/core/model/CapParamDescriptionPO.java
@@ -45,7 +45,7 @@ class CapParamDescriptionPO extends ParamDescriptionPO implements
*/
@Transient
public String getName() {
- return CompSystemI18n.getString(getUniqueId(), true);
+ return CompSystemI18n.getString(getUniqueId());
}
}
diff --git a/org.eclipse.jubula.client.core/src/org/eclipse/jubula/client/core/utils/StringHelper.java b/org.eclipse.jubula.client.core/src/org/eclipse/jubula/client/core/utils/StringHelper.java
index bf605078a..6b229b46a 100644
--- a/org.eclipse.jubula.client.core/src/org/eclipse/jubula/client/core/utils/StringHelper.java
+++ b/org.eclipse.jubula.client.core/src/org/eclipse/jubula/client/core/utils/StringHelper.java
@@ -151,8 +151,7 @@ public class StringHelper {
String paramValue = vSet.getValue();
// i18n only when default values are i18nable
if (!m_map.containsKey(paramValue)) {
- String value = CompSystemI18n.getString(
- paramValue, true);
+ String value = CompSystemI18n.getString(paramValue);
m_map.put(paramValue, value);
m_map.put(value, paramValue);
}
diff --git a/org.eclipse.jubula.client.ui.rcp/src/org/eclipse/jubula/client/ui/rcp/businessprocess/ProblemsBP.java b/org.eclipse.jubula.client.ui.rcp/src/org/eclipse/jubula/client/ui/rcp/businessprocess/ProblemsBP.java
index 6dc9d94f4..8c713017f 100644
--- a/org.eclipse.jubula.client.ui.rcp/src/org/eclipse/jubula/client/ui/rcp/businessprocess/ProblemsBP.java
+++ b/org.eclipse.jubula.client.ui.rcp/src/org/eclipse/jubula/client/ui/rcp/businessprocess/ProblemsBP.java
@@ -918,7 +918,7 @@ public class ProblemsBP implements ICompletenessCheckListener,
String message = NLS.bind(Messages.ProblemCheckerCompDoesNotExist,
new String[] { cap.getName(), tcPO.getName(),
CompSystemI18n.getString(
- cap.getComponentType(), true) });
+ cap.getComponentType()) });
m_localProblemsToShow.add(ProblemFactory.createProblemWithMarker(
new Status(IStatus.ERROR, Activator.PLUGIN_ID, message),
message, cap, ProblemType.REASON_COMP_DOES_NOT_EXIST));
@@ -1043,7 +1043,7 @@ public class ProblemsBP implements ICompletenessCheckListener,
} else if (cap.getMetaAction() instanceof InvalidAction) {
String message = Messages.CouldNotFindAction
+ StringConstants.SPACE
- + CompSystemI18n.getString(cap.getActionName(), true)
+ + CompSystemI18n.getString(cap.getActionName())
+ StringConstants.NEWLINE + "in" + StringConstants.SPACE //$NON-NLS-1$
+ Messages.Component + StringConstants.COLON
+ StringConstants.SPACE + cap.getComponentType();
@@ -1061,13 +1061,12 @@ public class ProblemsBP implements ICompletenessCheckListener,
+ Messages.Action
+ StringConstants.COLON
+ StringConstants.SPACE
- + CompSystemI18n.getString(cap.getActionName(),
- true)
+ + CompSystemI18n.getString(cap.getActionName())
+ StringConstants.NEWLINE
+ Messages.Parameter
+ StringConstants.COLON
+ StringConstants.SPACE
- + CompSystemI18n.getString(param.getName(), true);
+ + CompSystemI18n.getString(param.getName());
log.error(Messages.CouldNotFind + StringConstants.SPACE
+ message);
problemParamDoesNotExist(cap);
diff --git a/org.eclipse.jubula.client.ui.rcp/src/org/eclipse/jubula/client/ui/rcp/controllers/propertysources/OMLogicNameGUIPropertySource.java b/org.eclipse.jubula.client.ui.rcp/src/org/eclipse/jubula/client/ui/rcp/controllers/propertysources/OMLogicNameGUIPropertySource.java
index 9b4c18b53..6029b6c15 100644
--- a/org.eclipse.jubula.client.ui.rcp/src/org/eclipse/jubula/client/ui/rcp/controllers/propertysources/OMLogicNameGUIPropertySource.java
+++ b/org.eclipse.jubula.client.ui.rcp/src/org/eclipse/jubula/client/ui/rcp/controllers/propertysources/OMLogicNameGUIPropertySource.java
@@ -155,8 +155,7 @@ public class OMLogicNameGUIPropertySource
compName.getGuid());
}
if (compName != null && compName.getComponentType() != null) {
- return CompSystemI18n.getString(
- compName.getComponentType(), true);
+ return CompSystemI18n.getString(compName.getComponentType());
}
return StringConstants.EMPTY;
}
diff --git a/org.eclipse.jubula.client.ui.rcp/src/org/eclipse/jubula/client/ui/rcp/dialogs/AbstractEditParametersDialog.java b/org.eclipse.jubula.client.ui.rcp/src/org/eclipse/jubula/client/ui/rcp/dialogs/AbstractEditParametersDialog.java
index abff4e155..ee01f792b 100644
--- a/org.eclipse.jubula.client.ui.rcp/src/org/eclipse/jubula/client/ui/rcp/dialogs/AbstractEditParametersDialog.java
+++ b/org.eclipse.jubula.client.ui.rcp/src/org/eclipse/jubula/client/ui/rcp/dialogs/AbstractEditParametersDialog.java
@@ -1036,7 +1036,7 @@ public abstract class AbstractEditParametersDialog extends TitleAreaDialog {
case TYPE_TABLE_COLUMN:
final String paramType = parameter.getType();
- return CompSystemI18n.getString(paramType, true);
+ return CompSystemI18n.getString(paramType);
default:
StringBuilder msg = new StringBuilder();
diff --git a/org.eclipse.jubula.client.ui.rcp/src/org/eclipse/jubula/client/ui/rcp/provider/labelprovider/CentralTestDataLabelProvider.java b/org.eclipse.jubula.client.ui.rcp/src/org/eclipse/jubula/client/ui/rcp/provider/labelprovider/CentralTestDataLabelProvider.java
index 51a014a4b..205c5e9c1 100644
--- a/org.eclipse.jubula.client.ui.rcp/src/org/eclipse/jubula/client/ui/rcp/provider/labelprovider/CentralTestDataLabelProvider.java
+++ b/org.eclipse.jubula.client.ui.rcp/src/org/eclipse/jubula/client/ui/rcp/provider/labelprovider/CentralTestDataLabelProvider.java
@@ -44,8 +44,7 @@ public class CentralTestDataLabelProvider extends GeneralLabelProvider {
while (iter.hasNext()) {
IParamDescriptionPO descr = (IParamDescriptionPO)iter
.next();
- info.append(
- CompSystemI18n.getString(descr.getType(), true));
+ info.append(CompSystemI18n.getString(descr.getType()));
info.append(StringConstants.COLON);
info.append(descr.getName());
if (iter.hasNext()) {
diff --git a/org.eclipse.jubula.tools/src/org/eclipse/jubula/tools/i18n/CompSystemI18n.java b/org.eclipse.jubula.tools/src/org/eclipse/jubula/tools/i18n/CompSystemI18n.java
index 647a4fc51..8b3338704 100644
--- a/org.eclipse.jubula.tools/src/org/eclipse/jubula/tools/i18n/CompSystemI18n.java
+++ b/org.eclipse.jubula.tools/src/org/eclipse/jubula/tools/i18n/CompSystemI18n.java
@@ -15,14 +15,17 @@ import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Enumeration;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
+import java.util.Map;
import java.util.MissingResourceException;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
+import org.apache.commons.lang.StringUtils;
import org.eclipse.jubula.tools.constants.DebugConstants;
import org.eclipse.jubula.tools.constants.StringConstants;
import org.slf4j.Logger;
@@ -40,6 +43,10 @@ public class CompSystemI18n {
/** List of ResourceBundles */
private static final List PLUGIN_BUNDLES = new LinkedList();
+ /**
+ * mapping from i18n keys (String) to i18n values (String)
+ */
+ private static final Map I18N_MAP = new HashMap();
/**
* Constructor
@@ -68,16 +75,15 @@ public class CompSystemI18n {
* @return a internationalized <code>String</code>.
*/
public static String getString(String key) {
- if (StringConstants.EMPTY.equals(key)) {
- return key;
- }
- String str = key;
+
try {
- str = getStringInternal(key);
+ return getStringInternal(key);
} catch (MissingResourceException mre) {
logError(key, mre);
}
- return str;
+
+ return key;
+
}
/**
@@ -96,54 +102,40 @@ public class CompSystemI18n {
* @return the value for the given key
*/
private static String getStringInternal(String key) {
+
+ if (key == null) {
+ return StringUtils.EMPTY;
+ }
+
+ String value = (String)I18N_MAP.get(key);
+ if (value != null) {
+ return value;
+ }
+
Iterator bundleIter = PLUGIN_BUNDLES.iterator();
while (bundleIter.hasNext()) {
ResourceBundle bundle = (ResourceBundle)bundleIter.next();
try {
- return bundle.getString(key);
+ value = bundle.getString(key);
+ I18N_MAP.put(key, value);
+ return value;
} catch (MissingResourceException ex) {
// ok here, we search in multiple bundles
}
}
+
+ I18N_MAP.put(key, key);
throw new MissingResourceException("No entry found for key: " + key, //$NON-NLS-1$
CompSystemI18n.class.getName(), key);
}
/**
- * Gets the internationalized String by a given key.
- * @param key the key for the internationalized String.
- * @param fallBack returns the key if no value found
- * @return a internationalized <code>String</code>.
- */
- public static String getString(String key, boolean fallBack) {
- if (key == null) {
- return StringConstants.EMPTY;
- }
- if (StringConstants.EMPTY.equals(key)) {
- return key;
- }
- String str = StringConstants.EMPTY;
- try {
- str = getStringInternal(key);
- } catch (MissingResourceException mre) {
- if (fallBack) {
- return key;
- }
- logError(key, mre);
- }
- return str;
- }
-
- /**
* returns an internationalized string for the given key
* @param key the key
* @param args the arguments needed to generate the string
* @return the internationalized string
*/
public static String getString(String key, Object[] args) {
- if (StringConstants.EMPTY.equals(key)) {
- return key;
- }
try {
MessageFormat formatter =
new MessageFormat(getStringInternal(key));
diff --git a/org.eclipse.jubula.tools/src/org/eclipse/jubula/tools/xml/businessmodell/CompSystem.java b/org.eclipse.jubula.tools/src/org/eclipse/jubula/tools/xml/businessmodell/CompSystem.java
index a2cd8d100..1f800af59 100644
--- a/org.eclipse.jubula.tools/src/org/eclipse/jubula/tools/xml/businessmodell/CompSystem.java
+++ b/org.eclipse.jubula.tools/src/org/eclipse/jubula/tools/xml/businessmodell/CompSystem.java
@@ -448,7 +448,7 @@ public class CompSystem {
}
if (log.isDebugEnabled()) {
- String translatedName = CompSystemI18n.getString(typeName, true);
+ String translatedName = CompSystemI18n.getString(typeName);
String message = "Component " + translatedName + " does not exist"; //$NON-NLS-1$ //$NON-NLS-2$
log.debug(message);
}
@@ -490,7 +490,7 @@ public class CompSystem {
}
if (log.isDebugEnabled()) {
- String translatedName = CompSystemI18n.getString(typeName, true);
+ String translatedName = CompSystemI18n.getString(typeName);
String message = "Component " + translatedName + " does not exist"; //$NON-NLS-1$ //$NON-NLS-2$
log.debug(message);
}

Back to the top