package com.ora.jsp.tags.sql.value;
import java.lang.reflect.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import com.ora.jsp.sql.value.*;
import com.ora.jsp.tags.sql.ValueTagParent;
/**
* This class is a custom action intended to be used in the body of
* a sqlQuery or an sqlUpdate action element. It adds the specified
* value to its parent's value list.
*
* @author Hans Bergsten, Gefion software <hans@gefionsoftware.com>
* @version 1.0
*/
public class ObjectValueTag extends ValueTag {
private Object value;
/**
* Sets the value property.
*/
public void setValue(Object value) {
this.value = value;
}
/**
* Gets the value, specified by the value attribute, the stringValue
* attribute, the param attribute, or the name and property attributes,
* and adds it to the parent's value list.
*/
public int doEndTag() throws JspException {
if (stringValue != null) {
value = stringValue;
}
else if (param != null) {
String paramValue = getParameter(param);
value = paramValue;
}
else if (name != null) {
value = getObject(name, property);
}
ValueTagParent parent =
(ValueTagParent) findAncestorWithClass(this, ValueTagParent.class);
if (parent == null) {
throw new JspException("The sqlObjectValue action is not " +
"enclosed by a supported action type");
}
parent.addValue(new ObjectValue(value));
return EVAL_PAGE;
}
/**
* Releases all instance variables.
*/
public void release() {
value = null;
super.release();
}
private Object getObject(String beanName, String propertyName)
throws JspException {
String stringValue = null;
Object bean = getBean(beanName);
Method readMethod = getPropertyReadMethod(bean, propertyName);
Class returnType = readMethod.getReturnType();
return getValue(bean, readMethod, propertyName);
}
} |