use of org.apache.sling.scripting.jsp.jasper.JasperException in project sling 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;
}
use of org.apache.sling.scripting.jsp.jasper.JasperException in project sling 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.sling.scripting.jsp.jasper.JasperException in project sling by apache.
the class JspRuntimeLibrary method handleSetPropertyExpression.
// __end lookupReadMethodMethod
// handles <jsp:setProperty> with EL expression for 'value' attribute
/** Use proprietaryEvaluate
public static void handleSetPropertyExpression(Object bean,
String prop, String expression, PageContext pageContext,
VariableResolver variableResolver, FunctionMapper functionMapper )
throws JasperException
{
try {
Method method = getWriteMethod(bean.getClass(), prop);
method.invoke(bean, new Object[] {
pageContext.getExpressionEvaluator().evaluate(
expression,
method.getParameterTypes()[0],
variableResolver,
functionMapper,
null )
});
} catch (Exception ex) {
throw new JasperException(ex);
}
}
**/
public static void handleSetPropertyExpression(Object bean, String prop, String expression, PageContext pageContext, ProtectedFunctionMapper functionMapper) throws JasperException {
try {
Method method = getWriteMethod(bean.getClass(), prop);
method.invoke(bean, new Object[] { PageContextImpl.proprietaryEvaluate(expression, method.getParameterTypes()[0], pageContext, functionMapper, false) });
} catch (Exception ex) {
throw new JasperException(ex);
}
}
use of org.apache.sling.scripting.jsp.jasper.JasperException in project sling by apache.
the class JspRuntimeLibrary method handleGetProperty.
// __begin lookupReadMethodMethod
public static Object handleGetProperty(Object o, String prop) throws JasperException {
if (o == null) {
throw new JasperException(Localizer.getMessage("jsp.error.beans.nullbean"));
}
Object value = null;
try {
Method method = getReadMethod(o.getClass(), prop);
value = method.invoke(o, (Object[]) null);
} catch (Exception ex) {
throw new JasperException(ex);
}
return value;
}
use of org.apache.sling.scripting.jsp.jasper.JasperException in project sling 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[] { new Double(value) });
} catch (Exception ex) {
throw new JasperException(ex);
}
}
Aggregations