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

com.feilong.lib.ognl.ObjectIndexedPropertyDescriptor Maven / Gradle / Ivy

Go to download

feilong is a suite of core and expanded libraries that include utility classes, http, excel,cvs, io classes, and much much more.

There is a newer version: 4.0.8
Show newest version
//--------------------------------------------------------------------------
//	Copyright (c) 1998-2004, Drew Davidson and Luke Blanshard
//  All rights reserved.
//
//	Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are
//  met:
//
//	Redistributions of source code must retain the above copyright notice,
//  this list of conditions and the following disclaimer.
//	Redistributions in binary form must reproduce the above copyright
//  notice, this list of conditions and the following disclaimer in the
//  documentation and/or other materials provided with the distribution.
//	Neither the name of the Drew Davidson nor the names of its contributors
//  may be used to endorse or promote products derived from this software
//  without specific prior written permission.
//
//	THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
//  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
//  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
//  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
//  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
//  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
//  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
//  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
//  AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
//  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
//  THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
//  DAMAGE.
//--------------------------------------------------------------------------
package com.feilong.lib.ognl;

import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;

/**
 * 

* PropertyDescriptor subclass that describes an indexed set of read/write * methods to get a property. Unlike IndexedPropertyDescriptor this allows * the "key" to be an arbitrary object rather than just an int. Consequently * it does not have a "readMethod" or "writeMethod" because it only expects * a pattern like: *

* *
 *    public void setProperty(KeyType, ValueType);
 *    public ValueType getProperty(KeyType);
 * 
*

* and does not require the methods that access it as an array. OGNL can * get away with this without losing functionality because if the object * does expose the properties they are most probably in a Map and that case * is handled by the normal OGNL property accessors. *

*

* For example, if an object were to have methods that accessed and "attributes" * property it would be natural to index them by String rather than by integer * and expose the attributes as a map with a different property name: * *

 * 
 * public void setAttribute(String name,Object value);
 * 
 * public Object getAttribute(String name);
 * 
 * public Map getAttributes();
 * 
*

* Note that the index get/set is called get/set Attribute * whereas the collection getter is called Attributes. This * case is handled unambiguously by the OGNL property accessors because the * set/getAttribute methods are detected by this object and the * "attributes" case is handled by the MapPropertyAccessor. * Therefore OGNL expressions calling this code would be handled in the * following way: *

* * * * * * * * * * * * * * * * * * * * * * *
OGNL Expression
OGNL ExpressionHandling
attribute["name"]Handled by an index getter, like getAttribute(String).
attribute["name"] = valueHandled by an index setter, like setAttribute(String, Object).
attributes["name"]Handled by MapPropertyAccessor via a Map.get(). This * will not go through the index get accessor. *
attributes["name"] = valueHandled by MapPropertyAccessor via a Map.put(). This * will not go through the index set accessor. *
* * @author Luke Blanshard ([email protected]) * @author Drew Davidson ([email protected]) */ public class ObjectIndexedPropertyDescriptor extends PropertyDescriptor{ private Method indexedReadMethod; private Method indexedWriteMethod; private Class propertyType; public ObjectIndexedPropertyDescriptor(String propertyName, Class propertyType, Method indexedReadMethod, Method indexedWriteMethod) throws IntrospectionException{ super(propertyName, null, null); this.propertyType = propertyType; this.indexedReadMethod = indexedReadMethod; this.indexedWriteMethod = indexedWriteMethod; } public Method getIndexedReadMethod(){ return indexedReadMethod; } public Method getIndexedWriteMethod(){ return indexedWriteMethod; } @Override public Class getPropertyType(){ return propertyType; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy