ExpressionUtils { public static void populatePropertyExpressionsFromGraph(UifDictionaryBean expressionConfigurable) { if (expressionConfigurable == null || expressionConfigurable.getExpressionGraph() == null) { return; } Map<String, Map<String, String>> refreshExpressionGraphs = new HashMap<String, Map<String, String>>(); Map<String, String> expressionGraph = expressionConfigurable.getExpressionGraph(); for (Map.Entry<String, String> expressionEntry : expressionGraph.entrySet()) { String propertyName = expressionEntry.getKey(); String expression = expressionEntry.getValue(); UifDictionaryBean configurableWithExpression = expressionConfigurable; String adjustedPropertyName = propertyName; if (StringUtils.contains(propertyName, ".")) { String configurablePath = StringUtils.substringBeforeLast(propertyName, "."); adjustedPropertyName = StringUtils.substringAfterLast(propertyName, "."); Object nestedObject = ObjectPropertyUtils.getPropertyValue(expressionConfigurable, configurablePath); if (nestedObject == null && expressionConfigurable instanceof LifecycleElement && ((LifecycleElement) expressionConfigurable).skipLifecycle()) { continue; } if ((nestedObject == null) || !(nestedObject instanceof UifDictionaryBean)) { throw new RiceRuntimeException("Object for which expression is configured on is null or does not " + "implement UifDictionaryBean: '" + configurablePath + "' on class " + expressionConfigurable.getClass().getName() + " while evaluating " + "expression for " + propertyName); } configurableWithExpression = (UifDictionaryBean) nestedObject; } configurableWithExpression.getPropertyExpressions().put(adjustedPropertyName, expression); } }  static void populatePropertyExpressionsFromGraph(UifDictionaryBean expressionConfigurable); static String parseExpression(String exp, List<String> controlNames); static void evaluateCurrentStack(String stack, List<String> controlNames);  }
@Test public void testPopulatePropertyExpressionsFromGraph() { Map<String, String> expressionGraph = new HashMap<String, String>(); expressionGraph.put("property1", "@{expr1}"); expressionGraph.put("property2", "@{expr2}"); expressionGraph.put("property3['key1']", "@{key1expr}"); expressionGraph.put("property4.property1", "@{nexpr1}"); expressionGraph.put("property4.property4.property3['key2']", "@{nkey2expr}"); MockConfigurable configurable = new MockConfigurable(); MockConfigurable configurable2 = new MockConfigurable(); MockConfigurable configurable3 = new MockConfigurable(); configurable2.setProperty4(configurable3); configurable.setProperty4(configurable2); configurable.setExpressionGraph(expressionGraph); ViewLifecycle.getExpressionEvaluator().populatePropertyExpressionsFromGraph(configurable, false); assertEquals("Expression count not correct in root configurable", 3, configurable.getPropertyExpressions().size()); assertEquals("Expression not correct for property1", "@{expr1}", configurable.getPropertyExpression( "property1")); assertEquals("Expression not correct for property2", "@{expr2}", configurable.getPropertyExpression( "property2")); assertEquals("Expression not correct for map property3", "@{key1expr}", configurable.getPropertyExpression( "property3['key1']")); assertEquals("Expression count not correct in nested configurable", 1, configurable.getProperty4().getPropertyExpressions().size()); assertEquals("Expression not correct for nested property1", "@{nexpr1}", configurable.getProperty4().getPropertyExpression("property1")); assertEquals("Expression count not correct in two level nested configurable", 1, configurable.getProperty4().getProperty4().getPropertyExpressions().size()); assertEquals("Expression not correct for nested map property3", "@{nkey2expr}", configurable.getProperty4().getProperty4().getPropertyExpression("property3['key2']")); }
@Test public void testPopulatePropertyExpressionsFromGraph_RefreshGraphs() { Map<String, String> expressionGraph = new HashMap<String, String>(); expressionGraph.put("property1", "@{expr1}"); expressionGraph.put("property2", "@{expr2}"); expressionGraph.put("property3['key1']", "@{key1expr}"); expressionGraph.put("property4.property1", "@{nexpr1}"); expressionGraph.put("property4.property4.property3['key2']", "@{nkey2expr}"); MockConfigurable configurable = new MockConfigurable(); MockConfigurable configurable2 = new MockConfigurable(); MockConfigurable configurable3 = new MockConfigurable(); configurable2.setProperty4(configurable3); configurable.setProperty4(configurable2); configurable.setExpressionGraph(expressionGraph); ViewLifecycle.getExpressionEvaluator().populatePropertyExpressionsFromGraph(configurable, true); }