use of org.apache.jasper.JasperException in project tomcat70 by apache.
the class JspRuntimeLibrary method handleSetProperty.
public static void handleSetProperty(Object bean, String prop, double value) throws JasperException {
try {
Method method = getWriteMethod(bean.getClass(), prop);
method.invoke(bean, new Object[] { Double.valueOf(value) });
} catch (Exception ex) {
Throwable thr = ExceptionUtils.unwrapInvocationTargetException(ex);
ExceptionUtils.handleThrowable(thr);
throw new JasperException(ex);
}
}
use of org.apache.jasper.JasperException in project tomcat70 by apache.
the class JspRuntimeLibrary method createTypedArray.
// __end toStringMethod
/**
* Create a typed array.
* This is a special case where params are passed through
* the request and the property is indexed.
*/
public static void createTypedArray(String propertyName, Object bean, Method method, String[] values, Class<?> t, Class<?> propertyEditorClass) throws JasperException {
try {
if (propertyEditorClass != null) {
Object[] tmpval = new Integer[values.length];
for (int i = 0; i < values.length; i++) {
tmpval[i] = getValueFromBeanInfoPropertyEditor(t, propertyName, values[i], propertyEditorClass);
}
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(Integer.class)) {
Integer[] tmpval = new Integer[values.length];
for (int i = 0; i < values.length; i++) tmpval[i] = Integer.valueOf(values[i]);
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(Byte.class)) {
Byte[] tmpval = new Byte[values.length];
for (int i = 0; i < values.length; i++) tmpval[i] = Byte.valueOf(values[i]);
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(Boolean.class)) {
Boolean[] tmpval = new Boolean[values.length];
for (int i = 0; i < values.length; i++) tmpval[i] = Boolean.valueOf(values[i]);
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(Short.class)) {
Short[] tmpval = new Short[values.length];
for (int i = 0; i < values.length; i++) tmpval[i] = Short.valueOf(values[i]);
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(Long.class)) {
Long[] tmpval = new Long[values.length];
for (int i = 0; i < values.length; i++) tmpval[i] = Long.valueOf(values[i]);
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(Double.class)) {
Double[] tmpval = new Double[values.length];
for (int i = 0; i < values.length; i++) tmpval[i] = Double.valueOf(values[i]);
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(Float.class)) {
Float[] tmpval = new Float[values.length];
for (int i = 0; i < values.length; i++) tmpval[i] = Float.valueOf(values[i]);
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(Character.class)) {
Character[] tmpval = new Character[values.length];
for (int i = 0; i < values.length; i++) tmpval[i] = Character.valueOf(values[i].charAt(0));
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(int.class)) {
int[] tmpval = new int[values.length];
for (int i = 0; i < values.length; i++) tmpval[i] = Integer.parseInt(values[i]);
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(byte.class)) {
byte[] tmpval = new byte[values.length];
for (int i = 0; i < values.length; i++) tmpval[i] = Byte.parseByte(values[i]);
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(boolean.class)) {
boolean[] tmpval = new boolean[values.length];
for (int i = 0; i < values.length; i++) tmpval[i] = Boolean.parseBoolean(values[i]);
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(short.class)) {
short[] tmpval = new short[values.length];
for (int i = 0; i < values.length; i++) tmpval[i] = Short.parseShort(values[i]);
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(long.class)) {
long[] tmpval = new long[values.length];
for (int i = 0; i < values.length; i++) tmpval[i] = Long.parseLong(values[i]);
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(double.class)) {
double[] tmpval = new double[values.length];
for (int i = 0; i < values.length; i++) tmpval[i] = Double.parseDouble(values[i]);
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(float.class)) {
float[] tmpval = new float[values.length];
for (int i = 0; i < values.length; i++) tmpval[i] = Float.parseFloat(values[i]);
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(char.class)) {
char[] tmpval = new char[values.length];
for (int i = 0; i < values.length; i++) tmpval[i] = values[i].charAt(0);
method.invoke(bean, new Object[] { tmpval });
} else {
Object[] tmpval = new Integer[values.length];
for (int i = 0; i < values.length; i++) {
tmpval[i] = getValueFromPropertyEditorManager(t, propertyName, values[i]);
}
method.invoke(bean, new Object[] { tmpval });
}
} catch (Exception ex) {
Throwable thr = ExceptionUtils.unwrapInvocationTargetException(ex);
ExceptionUtils.handleThrowable(thr);
throw new JasperException("error in invoking method", ex);
}
}
use of org.apache.jasper.JasperException in project tomcat70 by apache.
the class JspRuntimeLibrary method handleSetProperty.
public static void handleSetProperty(Object bean, String prop, long value) throws JasperException {
try {
Method method = getWriteMethod(bean.getClass(), prop);
method.invoke(bean, new Object[] { Long.valueOf(value) });
} catch (Exception ex) {
Throwable thr = ExceptionUtils.unwrapInvocationTargetException(ex);
ExceptionUtils.handleThrowable(thr);
throw new JasperException(ex);
}
}
use of org.apache.jasper.JasperException in project tomcat70 by apache.
the class JspRuntimeLibrary method getReadMethod.
public static Method getReadMethod(Class<?> beanClass, String prop) throws JasperException {
Method method = null;
Class<?> type = null;
try {
java.beans.BeanInfo info = java.beans.Introspector.getBeanInfo(beanClass);
if (info != null) {
java.beans.PropertyDescriptor[] pd = info.getPropertyDescriptors();
for (int i = 0; i < pd.length; i++) {
if (pd[i].getName().equals(prop)) {
method = pd[i].getReadMethod();
type = pd[i].getPropertyType();
break;
}
}
} else {
// just in case introspection silently fails.
throw new JasperException(Localizer.getMessage("jsp.error.beans.nobeaninfo", beanClass.getName()));
}
} catch (Exception ex) {
throw new JasperException(ex);
}
if (method == null) {
if (type == null) {
throw new JasperException(Localizer.getMessage("jsp.error.beans.noproperty", prop, beanClass.getName()));
} else {
throw new JasperException(Localizer.getMessage("jsp.error.beans.nomethod", prop, beanClass.getName()));
}
}
return method;
}
use of org.apache.jasper.JasperException in project tomcat70 by apache.
the class JspRuntimeLibrary method getWriteMethod.
public static Method getWriteMethod(Class<?> beanClass, String prop) throws JasperException {
Method method = null;
Class<?> type = null;
try {
java.beans.BeanInfo info = java.beans.Introspector.getBeanInfo(beanClass);
if (info != null) {
java.beans.PropertyDescriptor[] pd = info.getPropertyDescriptors();
for (int i = 0; i < pd.length; i++) {
if (pd[i].getName().equals(prop)) {
method = pd[i].getWriteMethod();
type = pd[i].getPropertyType();
break;
}
}
} else {
// just in case introspection silently fails.
throw new JasperException(Localizer.getMessage("jsp.error.beans.nobeaninfo", beanClass.getName()));
}
} catch (Exception ex) {
throw new JasperException(ex);
}
if (method == null) {
if (type == null) {
throw new JasperException(Localizer.getMessage("jsp.error.beans.noproperty", prop, beanClass.getName()));
} else {
throw new JasperException(Localizer.getMessage("jsp.error.beans.nomethod.setproperty", prop, type.getName(), beanClass.getName()));
}
}
return method;
}
Aggregations