1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.commons.beanutils; 18 19 20 /** 21 * <p>Decorates a {@link DynaBean} to provide <code>Map</code> behaviour.</p> 22 * 23 * <p>The motivation for this implementation is to provide access to {@link DynaBean} 24 * properties in technologies that are unaware of BeanUtils and {@link DynaBean}s - 25 * such as the expression languages of JSTL and JSF.</p> 26 * 27 * <p>This can be achieved either by wrapping the {@link DynaBean} prior to 28 * providing it to the technolody to process or by providing a <code>Map</code> 29 * accessor method on the DynaBean implementation: 30 * <pre><code> 31 * public Map getMap() { 32 * return new DynaBeanMapDecorator(this); 33 * }</code></pre> 34 * </ul> 35 * </p> 36 * 37 * <p>This, for example, could be used in JSTL in the following way to access 38 * a DynaBean's <code>fooProperty</code>: 39 * <ul><li><code>${myDynaBean.<b>map</b>.fooProperty}</code></li></ul> 40 * </p> 41 * 42 * <h3>Usage</h3> 43 * 44 * <p>To decorate a {@link DynaBean} simply instantiate this class with the 45 * target {@link DynaBean}:</p> 46 * 47 * <ul><li><code>Map fooMap = new DynaBeanMapDecorator(fooDynaBean);</code></li></ul> 48 * 49 * <p>The above example creates a <b><i>read only</i></b> <code>Map</code>. 50 * To create a <code>Map</code> which can be modified, construct a 51 * <code>DynaBeanMapDecorator</code> with the <b><i>read only</i></b> 52 * attribute set to <code>false</code>:</p> 53 * 54 * <ul><li><code>Map fooMap = new DynaBeanMapDecorator(fooDynaBean, false);</code></li></ul> 55 * 56 * <h3>Limitations</h3> 57 * <p>In this implementation the <code>entrySet()</code>, <code>keySet()</code> 58 * and <code>values()</code> methods create an <b><i>unmodifiable</i></b> 59 * <code>Set</code> and it does not support the Map's <code>clear()</code> 60 * and <code>remove()</code> operations.</p> 61 * <p>For reasons of backwards compatibility, the generic types of this 62 * {@code Map} implementation are {@code <Object, Object>}. However, the 63 * keys of the map are typically strings.</p> 64 * 65 * @since BeanUtils 1.8.0 66 * @version $Id$ 67 * @deprecated Use {@link DynaBeanPropertyMapDecorator} instead. When adding 68 * generics it turned out that it was not possible to use the correct type 69 * parameters without breaking backwards compatibility. Therefore, class 70 * {@code DynaBeanPropertyMapDecorator} was introduced as a replacement. 71 */ 72 @Deprecated 73 public class DynaBeanMapDecorator extends BaseDynaBeanMapDecorator<Object> { 74 /** 75 * Construct a Map for the specified {@link DynaBean}. 76 * 77 * @param dynaBean The dyna bean being decorated 78 * @param readOnly <code>true</code> if the Map is read only 79 * otherwise <code>false</code> 80 * @throws IllegalArgumentException if the {@link DynaBean} is null. 81 */ 82 public DynaBeanMapDecorator(final DynaBean dynaBean, final boolean readOnly) { 83 super(dynaBean, readOnly); 84 } 85 86 /** 87 * Constructs a read only Map for the specified 88 * {@link DynaBean}. 89 * 90 * @param dynaBean The dyna bean being decorated 91 * @throws IllegalArgumentException if the {@link DynaBean} is null. 92 */ 93 public DynaBeanMapDecorator(final DynaBean dynaBean) { 94 super(dynaBean); 95 } 96 97 @Override 98 protected Object convertKey(final String propertyName) { 99 return propertyName; 100 } 101 }