All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.commons.beanutils.DynaBeanMapDecorator Maven / Gradle / Ivy

Go to download

This artifact provides a single jar that contains all classes required to use remote EJB and JMS, including all dependencies. It is intended for use by those not using maven, maven users should just import the EJB and JMS BOM's instead (shaded JAR's cause lots of problems with maven, as it is very easy to inadvertently end up with different versions on classes on the class path).

There is a newer version: 32.0.0.Final
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.commons.beanutils;


/**
 * 

Decorates a {@link DynaBean} to provide Map behaviour.

* *

The motivation for this implementation is to provide access to {@link DynaBean} * properties in technologies that are unaware of BeanUtils and {@link DynaBean}s - * such as the expression languages of JSTL and JSF.

* *

This can be achieved either by wrapping the {@link DynaBean} prior to * providing it to the technolody to process or by providing a Map * accessor method on the DynaBean implementation: *


 *         public Map getMap() {
 *             return new DynaBeanMapDecorator(this);
 *         }
* *

* *

This, for example, could be used in JSTL in the following way to access * a DynaBean's fooProperty: *

  • ${myDynaBean.map.fooProperty}
*

* *

Usage

* *

To decorate a {@link DynaBean} simply instantiate this class with the * target {@link DynaBean}:

* *
  • Map fooMap = new DynaBeanMapDecorator(fooDynaBean);
* *

The above example creates a read only Map. * To create a Map which can be modified, construct a * DynaBeanMapDecorator with the read only * attribute set to false:

* *
  • Map fooMap = new DynaBeanMapDecorator(fooDynaBean, false);
* *

Limitations

*

In this implementation the entrySet(), keySet() * and values() methods create an unmodifiable * Set and it does not support the Map's clear() * and remove() operations.

*

For reasons of backwards compatibility, the generic types of this * {@code Map} implementation are {@code }. However, the * keys of the map are typically strings.

* * @since BeanUtils 1.8.0 * @version $Id: DynaBeanMapDecorator.java 1540186 2013-11-08 21:08:30Z oheger $ * @deprecated Use {@link DynaBeanPropertyMapDecorator} instead. When adding * generics it turned out that it was not possible to use the correct type * parameters without breaking backwards compatibility. Therefore, class * {@code DynaBeanPropertyMapDecorator} was introduced as a replacement. */ @Deprecated public class DynaBeanMapDecorator extends BaseDynaBeanMapDecorator { /** * Construct a Map for the specified {@link DynaBean}. * * @param dynaBean The dyna bean being decorated * @param readOnly true if the Map is read only * otherwise false * @throws IllegalArgumentException if the {@link DynaBean} is null. */ public DynaBeanMapDecorator(DynaBean dynaBean, boolean readOnly) { super(dynaBean, readOnly); } /** * Constructs a read only Map for the specified * {@link DynaBean}. * * @param dynaBean The dyna bean being decorated * @throws IllegalArgumentException if the {@link DynaBean} is null. */ public DynaBeanMapDecorator(DynaBean dynaBean) { super(dynaBean); } @Override protected Object convertKey(String propertyName) { return propertyName; } }