001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.commons.beanutils; 018 019/** 020 * <p>Decorates a {@link DynaBean} to provide <code>Map</code> behavior.</p> 021 * 022 * <p>The motivation for this implementation is to provide access to {@link DynaBean} 023 * properties in technologies that are unaware of BeanUtils and {@link DynaBean}s - 024 * such as the expression languages of JSTL and JSF.</p> 025 * 026 * <p>This can be achieved either by wrapping the {@link DynaBean} prior to 027 * providing it to the technolody to process or by providing a <code>Map</code> 028 * accessor method on the DynaBean implementation: 029 * </p> 030 * <pre> 031 * public Map getMap() { 032 * return new DynaBeanMapDecorator(this); 033 * }</pre> 034 * 035 * <p>This, for example, could be used in JSTL in the following way to access 036 * a DynaBean's <code>fooProperty</code>: 037 * </p> 038 * <code>${myDynaBean.<strong>map</strong>.fooProperty}</code> 039 * 040 * <strong>Usage</strong> 041 * 042 * <p>To decorate a {@link DynaBean} simply instantiate this class with the 043 * target {@link DynaBean}:</p> 044 * 045 * <code>Map fooMap = new DynaBeanMapDecorator(fooDynaBean);</code> 046 * 047 * <p>The above example creates a <strong><em>read only</em></strong> <code>Map</code>. 048 * To create a <code>Map</code> which can be modified, construct a 049 * <code>DynaBeanMapDecorator</code> with the <strong><em>read only</em></strong> 050 * attribute set to <code>false</code>:</p> 051 * 052 * <code>Map fooMap = new DynaBeanMapDecorator(fooDynaBean, false);</code> 053 * 054 * <strong>Limitations</strong> 055 * <p>In this implementation the <code>entrySet()</code>, <code>keySet()</code> 056 * and <code>values()</code> methods create an <strong><em>unmodifiable</em></strong> 057 * <code>Set</code> and it does not support the Map's <code>clear()</code> 058 * and <code>remove()</code> operations.</p> 059 * <p>For reasons of backwards compatibility, the generic types of this 060 * {@code Map} implementation are {@code <Object, Object>}. However, the 061 * keys of the map are typically strings.</p> 062 * 063 * @since BeanUtils 1.8.0 064 * @deprecated Use {@link DynaBeanPropertyMapDecorator} instead. When adding 065 * generics it turned out that it was not possible to use the correct type 066 * parameters without breaking backwards compatibility. Therefore, class 067 * {@code DynaBeanPropertyMapDecorator} was introduced as a replacement. 068 */ 069@Deprecated 070public class DynaBeanMapDecorator extends BaseDynaBeanMapDecorator<Object> { 071 /** 072 * Constructs a read only Map for the specified 073 * {@link DynaBean}. 074 * 075 * @param dynaBean The dyna bean being decorated 076 * @throws IllegalArgumentException if the {@link DynaBean} is null. 077 */ 078 public DynaBeanMapDecorator(final DynaBean dynaBean) { 079 super(dynaBean); 080 } 081 082 /** 083 * Construct a Map for the specified {@link DynaBean}. 084 * 085 * @param dynaBean The dyna bean being decorated 086 * @param readOnly <code>true</code> if the Map is read only 087 * otherwise <code>false</code> 088 * @throws IllegalArgumentException if the {@link DynaBean} is null. 089 */ 090 public DynaBeanMapDecorator(final DynaBean dynaBean, final boolean readOnly) { 091 super(dynaBean, readOnly); 092 } 093 094 @Override 095 protected Object convertKey(final String propertyName) { 096 return propertyName; 097 } 098}