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/** 021 * <p>Decorates a {@link DynaBean} to provide <code>Map</code> behaviour.</p> 022 * 023 * <p>The motivation for this implementation is to provide access to {@link DynaBean} 024 * properties in technologies that are unaware of BeanUtils and {@link DynaBean}s - 025 * such as the expression languages of JSTL and JSF.</p> 026 * 027 * <p>This can be achieved either by wrapping the {@link DynaBean} prior to 028 * providing it to the technolody to process or by providing a <code>Map</code> 029 * accessor method on the DynaBean implementation:</p> 030 * <pre><code> 031 * public Map getMap() { 032 * return new DynaBeanMapDecorator(this); 033 * }</code></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>:</p> 037 * <ul><li><code>${myDynaBean.<b>map</b>.fooProperty}</code></li></ul> 038 * 039 * <h3>Usage</h3> 040 * 041 * <p>To decorate a {@link DynaBean} simply instantiate this class with the 042 * target {@link DynaBean}:</p> 043 * 044 * <ul><li><code>Map fooMap = new DynaBeanMapDecorator(fooDynaBean);</code></li></ul> 045 * 046 * <p>The above example creates a <b><i>read only</i></b> <code>Map</code>. 047 * To create a <code>Map</code> which can be modified, construct a 048 * <code>DynaBeanMapDecorator</code> with the <b><i>read only</i></b> 049 * attribute set to <code>false</code>:</p> 050 * 051 * <ul><li><code>Map fooMap = new DynaBeanMapDecorator(fooDynaBean, false);</code></li></ul> 052 * 053 * <h3>Limitations</h3> 054 * <p>In this implementation the <code>entrySet()</code>, <code>keySet()</code> 055 * and <code>values()</code> methods create an <b><i>unmodifiable</i></b> 056 * <code>Set</code> and it does not support the Map's <code>clear()</code> 057 * and <code>remove()</code> operations.</p> 058 * <p>For reasons of backwards compatibility, the generic types of this 059 * {@code Map} implementation are {@code <Object, Object>}. However, the 060 * keys of the map are typically strings.</p> 061 * 062 * @since BeanUtils 1.8.0 063 * @version $Id$ 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 * Construct a Map for the specified {@link DynaBean}. 073 * 074 * @param dynaBean The dyna bean being decorated 075 * @param readOnly <code>true</code> if the Map is read only 076 * otherwise <code>false</code> 077 * @throws IllegalArgumentException if the {@link DynaBean} is null. 078 */ 079 public DynaBeanMapDecorator(final DynaBean dynaBean, final boolean readOnly) { 080 super(dynaBean, readOnly); 081 } 082 083 /** 084 * Constructs a read only Map for the specified 085 * {@link DynaBean}. 086 * 087 * @param dynaBean The dyna bean being decorated 088 * @throws IllegalArgumentException if the {@link DynaBean} is null. 089 */ 090 public DynaBeanMapDecorator(final DynaBean dynaBean) { 091 super(dynaBean); 092 } 093 094 @Override 095 protected Object convertKey(final String propertyName) { 096 return propertyName; 097 } 098}