AnyScopePropertyAccessor implements PropertyAccessor { @Override public String getSourceSetter(OgnlContext context, Object target, Object index) { Request request = (Request) target; String attributeName = (String) index; String[] availableScopes = request.getAvailableScopes().toArray(new String[0]); for (String scopeName : availableScopes) { Map<String, Object> scope = request.getContext(scopeName); if (scope.containsKey(attributeName)) { return ".getContext(\"" + scopeName + "\").put(index, target)"; } } return ".getContext(\"" + availableScopes[0] + "\").put(index, target)"; }  @Override Object getProperty(@SuppressWarnings("rawtypes") Map context, Object target, Object name); @Override String getSourceAccessor(OgnlContext context, Object target,
            Object index); @Override String getSourceSetter(OgnlContext context, Object target,
            Object index); @Override void setProperty(@SuppressWarnings("rawtypes") Map context, Object target, Object name,
            Object value);  }
@SuppressWarnings("unchecked") @Test public void testGetSourceSetter() { Request request = createMock(Request.class); Map<String, Object> oneScope = createMock(Map.class); Map<String, Object> twoScope = createMock(Map.class); expect(request.getAvailableScopes()).andReturn(Arrays.asList(new String[] {"one", "two"})).anyTimes(); expect(request.getContext("one")).andReturn(oneScope).anyTimes(); expect(request.getContext("two")).andReturn(twoScope).anyTimes(); expect(oneScope.containsKey("name1")).andReturn(true); expect(oneScope.containsKey("name2")).andReturn(false); expect(oneScope.containsKey("name3")).andReturn(false); expect(twoScope.containsKey("name2")).andReturn(true); expect(twoScope.containsKey("name3")).andReturn(false); replay(request, oneScope, twoScope); assertEquals(".getContext(\"one\").put(index, target)", accessor.getSourceSetter(null, request, "name1")); assertEquals(".getContext(\"two\").put(index, target)", accessor.getSourceSetter(null, request, "name2")); assertEquals(".getContext(\"one\").put(index, target)", accessor.getSourceSetter(null, request, "name3")); verify(request, oneScope, twoScope); }