You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by jw...@apache.org on 2007/07/31 18:55:14 UTC
svn commit: r561398 - in
/myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin:
SkinExtension.java SkinImpl.java
Author: jwaldman
Date: Tue Jul 31 09:55:13 2007
New Revision: 561398
URL: http://svn.apache.org/viewvc?view=rev&rev=561398
Log:
TRINIDAD-133 SkinExtension's getTranslatedValue performance improvement
on trunk
https://issues.apache.org/jira/browse/TRINIDAD-133
Cache base skin's non-null translatedValue with this skin to make it faster.
Modified:
myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinExtension.java
myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinImpl.java
Modified: myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinExtension.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinExtension.java?view=diff&rev=561398&r1=561397&r2=561398
==============================================================================
--- myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinExtension.java (original)
+++ myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinExtension.java Tue Jul 31 09:55:13 2007
@@ -251,13 +251,20 @@
// Look for the skin's translated value (first bundle name, then registered bundles)
// if that's not found, then look in the base skin's translated value.
// getCachedTranslatedValue will protect against MissingResourceExceptions
- Object translatedValue = super.getCachedTranslatedValue(lContext, key);
- // TODO Cache base skin's non-null translatedValue with this skin to
- // make it faster.
+ Object translatedValue = getCachedTranslatedValue(lContext, key);
+
+
if (translatedValue == null)
- return getBaseSkin().getTranslatedValue(lContext, key);
- else
- return translatedValue;
+ {
+ translatedValue = getBaseSkin().getTranslatedValue(lContext, key);
+ // Cache the non-null translated value with the SkinExtension to avoid looking
+ // at the base skin's map.
+ if (translatedValue != null)
+ putTranslatedValueInLocaleCache(lContext, key, translatedValue);
+
+ }
+
+ return translatedValue;
}
/**
Modified: myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinImpl.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinImpl.java?view=diff&rev=561398&r1=561397&r2=561398
==============================================================================
--- myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinImpl.java (original)
+++ myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinImpl.java Tue Jul 31 09:55:13 2007
@@ -376,6 +376,20 @@
_properties.put(key, value);
}
+
+ /**
+ * @param styleSheetName
+ * @see #addSkinAddition(SkinAddition)
+ * @deprecated Use addSkinAddition instead
+ */
+ public void registerStyleSheet(String styleSheetName)
+ {
+ //TODO Take out deprecated after sufficient amount of time has passed
+ // deprecated July, 2007
+ SkinAddition addition = new SkinAddition(styleSheetName, null);
+ addSkinAddition(addition);
+ }
+
/**
* Returns a translated value in the LocaleContext's translation Locale, or null
* if the key could not be found.
@@ -427,18 +441,35 @@
resourceBundleNames, key);
}
-
+
/**
- * @param styleSheetName
- * @see #addSkinAddition(SkinAddition)
- * @deprecated Use addSkinAddition instead
+ * Put the locale/key/value in the cache (i.e., translations map). This is useful for subclasses
+ * to call so that they can store/retrieve the key/value locally rather than always
+ * having to look in the parent skins' maps.
+ * @param lContext
+ * @param key
+ * @param value
*/
- public void registerStyleSheet(String styleSheetName)
+ protected void putTranslatedValueInLocaleCache(
+ LocaleContext lContext,
+ String key,
+ Object value)
{
- //TODO Take out deprecated after sufficient amount of time has passed
- // deprecated July, 2007
- SkinAddition addition = new SkinAddition(styleSheetName, null);
- addSkinAddition(addition);
+ Locale locale = lContext.getTranslationLocale();
+
+ KeyValueMapStatus keyValueMapStatus = _translations.get(locale);
+ if (keyValueMapStatus != null)
+ {
+ Map keyValueMap = keyValueMapStatus.getKeyValueMap();
+ if (keyValueMap != null)
+ {
+ keyValueMap.put(key, value);
+ }
+ }
+ else
+ {
+ _createKeyValueMapStatusInCache(locale, key, value);
+ }
}
/**
@@ -774,6 +805,7 @@
return _resourceBundleNames;
}
+
// get the cached value for the locale and key from the _translations map.
// If the value does not exist, then find it in the resource bundles,
@@ -807,15 +839,10 @@
else
{
// create the keyValueMapStatus object and put it on the locale
- synchronized (_translations)
- {
- if (!_translations.contains(locale))
- {
- keyValueMapStatus = new KeyValueMapStatus();
- keyValueMap = keyValueMapStatus.getKeyValueMap();
- _translations.put(locale, keyValueMapStatus);
- }
- }
+
+ keyValueMapStatus = _createKeyValueMapStatusInCache(locale, key, null);
+ keyValueMap = keyValueMapStatus.getKeyValueMap();
+
}
// at this point the keyValueMapStatus is set on the locale,
@@ -848,6 +875,43 @@
// nothing was found
return null;
+ }
+
+ // this method provides a single point of entry for creating KeyValueMapStatus object and
+ // putting the locale/keyValueMapStatus in the _translations map. If value != null,
+ // it adds the key/value to the keyValueMap.
+ // It synchronizes on the _translations parameter
+ // It returns the newly created KeyValueMapStatus object.
+ private KeyValueMapStatus _createKeyValueMapStatusInCache(
+ Locale locale,
+ String key,
+ Object value
+ )
+ {
+ KeyValueMapStatus keyValueMapStatus = null;
+
+ // create the keyValueMapStatus object and put it on the locale
+ synchronized (_translations)
+ {
+ // check to see if another thread has put locale in the map
+ if (!_translations.contains(locale))
+ {
+ keyValueMapStatus = new KeyValueMapStatus();
+ if (value != null)
+ {
+ Map keyValueMap = keyValueMapStatus.getKeyValueMap();
+ keyValueMap.put(key, value);
+ }
+ _translations.put(locale, keyValueMapStatus);
+ }
+ else
+ {
+ keyValueMapStatus = _translations.get(locale);
+ }
+ }
+
+ return keyValueMapStatus;
+
}
/**