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

org.apache.ibatis.ognl.ObjectIndexedPropertyDescriptor Maven / Gradle / Ivy

Go to download

The MyBatis SQL mapper framework makes it easier to use a relational database with object-oriented applications. MyBatis couples objects with stored procedures or SQL statements using a XML descriptor or annotations. Simplicity is the biggest advantage of the MyBatis data mapper over object relational mapping tools.

The 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.ibatis.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. *
*/ public class ObjectIndexedPropertyDescriptor extends PropertyDescriptor { private final Method indexedReadMethod; private final Method indexedWriteMethod; private final 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; } public synchronized Class getPropertyType() { return propertyType; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy