}
private Map<String, List> getNavigationCases(FacesContext facesContext)
{
ExternalContext externalContext = facesContext.getExternalContext();
RuntimeConfig runtimeConfig = RuntimeConfig.getCurrentInstance(externalContext);
if (_navigationCases == null || runtimeConfig.isNavigationRulesChanged())
{
synchronized(this)
{
if (_navigationCases == null || runtimeConfig.isNavigationRulesChanged())
{
Collection rules = runtimeConfig.getNavigationRules();
int rulesSize = rules.size();
Map<String, List> cases = new HashMap<String, List>(HashMapUtils.calcCapacity(rulesSize));
List<String> wildcardKeys = new ArrayList<String>();
for (Iterator iterator = rules.iterator(); iterator.hasNext();)
{
NavigationRule rule = (NavigationRule) iterator.next();
String fromViewId = rule.getFromViewId();
//specification 7.4.2 footnote 4 - missing fromViewId is allowed:
if (fromViewId == null)
{
fromViewId = ASTERISK;
}
else
{
fromViewId = fromViewId.trim();
}
List list = cases.get(fromViewId);
if (list == null)
{
list = new ArrayList(rule.getNavigationCases());
cases.put(fromViewId, list);
if (fromViewId.endsWith(ASTERISK))
{
wildcardKeys.add(fromViewId);
}
} else {
list.addAll(rule.getNavigationCases());
}
}
Collections.sort(wildcardKeys, new KeyComparator());
synchronized (cases)
{
// We do not really need this sychronization at all, but this
// gives us the peace of mind that some good optimizing compiler
// will not rearrange the execution of the assignment to an
// earlier time, before all init code completes
_navigationCases = cases;
_wildcardKeys = wildcardKeys;
runtimeConfig.setNavigationRulesChanged(false);
}
}
}
}
return _navigationCases;