class 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)";
    }

}