You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by to...@apache.org on 2006/11/06 14:21:35 UTC
svn commit: r471719 -
/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/PropertyResolverImpl.java
Author: tomsp
Date: Mon Nov 6 05:21:33 2006
New Revision: 471719
URL: http://svn.apache.org/viewvc?view=rev&rev=471719
Log:
MYFACES-1486 reverted (breaks JSF 1.1 compatibility)
Modified:
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/PropertyResolverImpl.java
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/PropertyResolverImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/PropertyResolverImpl.java?view=diff&rev=471719&r1=471718&r2=471719
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/PropertyResolverImpl.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/PropertyResolverImpl.java Mon Nov 6 05:21:33 2006
@@ -50,15 +50,16 @@
//~ Public PropertyResolver Methods ----------------------------------------
public Object getValue(Object base, Object property)
- throws EvaluationException {
+ throws EvaluationException, PropertyNotFoundException
+ {
try
{
if(base == null)
{
if(log.isDebugEnabled())
log.debug("property : "+property +" could not be retrieved as base was null.");
- throw new PropertyNotFoundException("Exception getting value of property " + property
- + " - base was null ");
+
+ return null;
}
//fix for myfaces-315 - empty string as key to a map-value is allowed
@@ -68,7 +69,7 @@
!(base instanceof Map)))
{
if(log.isDebugEnabled())
- log.debug("property for base with class: "+ getBaseType(base) +" could not be retrieved as property was null.");
+ log.debug("property for base with class: "+ base.getClass().getName() +" could not be retrieved as property was null.");
return null;
}
@@ -83,34 +84,31 @@
catch (PropertyNotFoundException e) {
if(log.isDebugEnabled())
- log.debug("Exception while retrieving property; base with class : "+
- getBaseType(base) +", property : "+property,e);
+ log.debug("Exception while retrieving property; base with class : "+base.getClass().getName()+", property : "+property,e);
throw e;
}
catch (RuntimeException e)
{
if(log.isDebugEnabled())
- log.debug("Exception while retrieving property; base : "+
- getBaseType(base) +", property : "+property,e);
+ log.debug("Exception while retrieving property; base : "+base.getClass().getName()+", property : "+property,e);
throw new EvaluationException("Exception getting value of property " + property
+ " of base of type : "
- + getBaseType(base), e);
+ + base.getClass().getName(), e);
}
}
public Object getValue(Object base, int index)
- throws EvaluationException {
+ throws EvaluationException, PropertyNotFoundException
+ {
try
{
- if(base == null)
- {
- if(log.isDebugEnabled())
- log.debug("index : "+index +" could not be retrieved as base was null.");
- throw new PropertyNotFoundException("Exception getting value for index " + index
- + " - base was null ");
- }
+ if (base == null)
+ {
+ log.debug("index : "+index+" not retrievable cause base is null.");
+ return null;
+ }
try
{
@@ -126,44 +124,42 @@
catch (IndexOutOfBoundsException e)
{
if(log.isDebugEnabled())
- log.debug("IndexOutOfBoundException while getting property; base with class: "+ getBaseType(base) +", index : "+index,e);
+ log.debug("IndexOutOfBoundException while getting property; base with class: "+base.getClass().getName()+", index : "+index,e);
// Note: ArrayIndexOutOfBoundsException also here
return null;
}
throw new ReferenceSyntaxException("Must be array or List. Bean with class: "
- + getBaseType(base) + ", index " + index);
+ + base.getClass().getName() + ", index " + index);
}
catch (RuntimeException e)
{
if(log.isDebugEnabled())
- log.debug("Exception while getting property; base with class: "+ getBaseType(base) +", index : "+index,e);
+ log.debug("Exception while getting property; base with class: "+base.getClass().getName()+", index : "+index,e);
throw new EvaluationException("Exception getting value for index " + index
+ " of bean "
- + base != null ? getBaseType(base) : "NULL", e);
+ + base != null ? base.getClass().getName() : "NULL", e);
}
}
public void setValue(Object base, Object property, Object newValue)
- throws EvaluationException {
+ throws EvaluationException, PropertyNotFoundException
+ {
try
{
- if(base == null)
- {
- if(log.isDebugEnabled())
- log.debug("property : "+property +" could not be set as base was null.");
- throw new PropertyNotFoundException("Exception setting value of property " + property
- + " - base was null ");
- }
-
+ if (base == null)
+ {
+ throw new PropertyNotFoundException(
+ "Null bean, property: " + property);
+ }
if (property == null ||
property instanceof String && ((String)property).length() == 0)
{
- throw new PropertyNotFoundException("Property in bean with class : "
- + getBaseType(base)
- + ", could not be retrieved - null or empty property name");
+ throw new PropertyNotFoundException("Bean with class : "
+ + base.getClass().getName()
+ + ", null or empty property name");
}
if (base instanceof Map)
@@ -178,35 +174,30 @@
}
catch (PropertyNotFoundException e) {
if(log.isDebugEnabled())
- log.debug("Exception while setting property; base with class : "+ getBaseType(base) +", property : "+property,e);
+ log.debug("Exception while setting property; base with class : "+base.getClass().getName()+", property : "+property,e);
throw e;
}
catch (RuntimeException e)
{
if(log.isDebugEnabled())
- log.debug("Exception while setting property; base with type : "+getBaseType(base)+", property : "+property,e);
+ log.debug("Exception while setting property; base : "+base.getClass().getName()+", property : "+property,e);
throw new EvaluationException("Exception setting property " + property
- + " of base with type : "
- + getBaseType(base), e);
+ + " of base with class "
+ + base.getClass().getName(), e);
}
}
- private static String getBaseType(Object base) {
- return (base==null?"null":base.getClass().getName());
- }
-
public void setValue(Object base, int index, Object newValue)
- throws EvaluationException {
+ throws EvaluationException, PropertyNotFoundException
+ {
try
{
- if(base == null)
- {
- if(log.isDebugEnabled())
- log.debug("value for index : "+index +" could not be set as base was null.");
- throw new PropertyNotFoundException("Exception setting value for index " + index
- + " - base was null ");
- }
+ if (base == null)
+ {
+ throw new PropertyNotFoundException(
+ "Null bean, index: " + index);
+ }
try
{
@@ -229,12 +220,12 @@
catch (IndexOutOfBoundsException e)
{
throw new PropertyNotFoundException("Base with class : "
- + getBaseType(base) + ", index " + index, e);
+ + base.getClass().getName() + ", index " + index, e);
}
throw new EvaluationException(
"Bean must be array or List. Base with class: "
- + getBaseType(base) + ", index " + index);
+ + base.getClass().getName() + ", index " + index);
}
catch (PropertyNotFoundException e) {
throw e;
@@ -242,7 +233,7 @@
catch (RuntimeException e)
{
throw new EvaluationException("Exception setting value of index " + index + " of bean "
- + getBaseType(base), e);
+ + base.getClass().getName(), e);
}
}
@@ -250,15 +241,7 @@
{
try
{
- if(base == null)
- {
- if(log.isDebugEnabled())
- log.debug("property : "+property +" could not be checked for read-only state as base was null.");
- throw new PropertyNotFoundException("Exception getting read-only state of property " + property
- + " - base was null ");
- }
-
- if (property == null ||
+ if (base == null || property == null ||
property instanceof String && ((String)property).length() == 0)
{
// Cannot determine read-only, return false (is this what the spec requires?)
@@ -289,12 +272,10 @@
try
{
/*todo: actually implement something here*/
- if(base == null)
+ if (base == null)
{
- if(log.isDebugEnabled())
- log.debug("index : "+index +" could not be checked for read-only state as base was null.");
- throw new PropertyNotFoundException("Exception getting read-only state of index " + index
- + " - base was null ");
+ // Cannot determine read-only, return false (is this what the spec requires?)
+ return false;
}
if (base instanceof List || base.getClass().isArray())
{
@@ -316,22 +297,17 @@
{
try
{
- if(base == null)
+ if (base == null)
{
- if(log.isDebugEnabled())
- log.debug("type for property : "+property +" could not be retrieved as base was null.");
- throw new PropertyNotFoundException("Exception getting type of property " + property
- + " - base was null ");
+ throw new PropertyNotFoundException("Base bean is null.");
}
else if (property == null)
{
- throw new PropertyNotFoundException("type for property could not be retrieved - property name for base : "+
- getBaseType(base)+"is null.");
+ throw new PropertyNotFoundException("Property name is null.");
}
else if (property instanceof String && ((String)property).length() == 0)
{
- throw new PropertyNotFoundException("type for property could not be retrieved - property name for base : "+
- getBaseType(base)+"is an empty string.");
+ throw new PropertyNotFoundException("Property name is an empty String.");
}
if (base instanceof Map)
@@ -353,19 +329,15 @@
}
catch (Exception e)
{
- throw new EvaluationException("Exception getting type of property " + property + " of bean with class : "
- + getBaseType(base), e);
+ return null;
}
}
public Class getType(Object base, int index)
{
- if(base == null)
+ if (base == null)
{
- if(log.isDebugEnabled())
- log.debug("type for value of index : "+index +" could not be retrieved as base was null.");
- throw new PropertyNotFoundException("Exception getting type for value of index " + index
- + " - base was null ");
+ throw new PropertyNotFoundException("Bean is null");
}
try
@@ -396,12 +368,12 @@
}
catch (IndexOutOfBoundsException e) {
throw new PropertyNotFoundException("Bean: "
- + getBaseType(base) + ", index " + index, e);
+ + base.getClass().getName() + ", index " + index, e);
}
catch (Exception e)
{
throw new EvaluationException("Exception getting type of index " + index + " of bean with class : "
- + getBaseType(base), e);
+ + base.getClass().getName(), e);
}
}
@@ -417,7 +389,7 @@
if (m == null)
{
throw new PropertyNotFoundException(
- getMessage(base, name)+ " (no write method for property!)");
+ getMessage(base, name)+ " (no write method for property!)");
}
// Check if the concrete class of this method is accessible and if not
@@ -443,7 +415,7 @@
private static String getMessage(Object base, String name, Object newValue, Method m)
{
return "Bean: "
- + getBaseType(base) + ", property: " + name +", newValue: "+(newValue==null?" null ":newValue)+
+ + base.getClass().getName() + ", property: " + name +", newValue: "+(newValue==null?" null ":newValue)+
",newValue class: "+(newValue==null?" null ":newValue.getClass().getName())+" method parameter class: "
+((m.getParameterTypes()!=null&&m.getParameterTypes().length>0)
?m.getParameterTypes()[0].getName():"null");
@@ -453,27 +425,19 @@
private static String getMessage(Object base, String name)
{
return "Bean: "
- + getBaseType(base) + ", property: " + name;
+ + base.getClass().getName() + ", property: " + name;
}
- public static Object getProperty(Object base, String property)
+ public static Object getProperty(Object base, String name)
{
- if(base == null)
- {
- if(log.isDebugEnabled())
- log.debug("property : "+property +" could not be retrieved as base was null.");
- throw new PropertyNotFoundException("Exception getting value of property " + property
- + " - base was null ");
- }
-
PropertyDescriptor propertyDescriptor =
- getPropertyDescriptor(base, property);
+ getPropertyDescriptor(base, name);
Method m = propertyDescriptor.getReadMethod();
if (m == null)
{
throw new PropertyNotFoundException(
- getMessage(base, property));
+ getMessage(base, name));
}
// Check if the concrete class of this method is accessible and if not
@@ -482,7 +446,7 @@
if (m == null)
{
throw new PropertyNotFoundException(
- getMessage(base, property) + " (not accessible!)");
+ getMessage(base, name) + " (not accessible!)");
}
try
@@ -491,48 +455,32 @@
}
catch (Throwable t)
{
- throw new EvaluationException(getMessage(base, property), t);
+ throw new EvaluationException(getMessage(base, name), t);
}
}
public static PropertyDescriptor getPropertyDescriptor(
- Object base, String property)
+ Object base, String name)
{
- if(base == null)
- {
- if(log.isDebugEnabled())
- log.debug("property : "+property +" could not be retrieved as base was null.");
- throw new PropertyNotFoundException("Exception getting value of property " + property
- + " - base was null ");
- }
-
PropertyDescriptor propertyDescriptor;
try
{
propertyDescriptor =
getPropertyDescriptor(
- Introspector.getBeanInfo(base.getClass()), property);
+ Introspector.getBeanInfo(base.getClass()), name);
}
catch (IntrospectionException e)
{
- throw new PropertyNotFoundException(getMessage(base, property), e);
+ throw new PropertyNotFoundException(getMessage(base, name), e);
}
return propertyDescriptor;
}
public static PropertyDescriptor getPropertyDescriptor(
- BeanInfo beanInfo, String property)
+ BeanInfo beanInfo, String propertyName)
{
- if(beanInfo == null)
- {
- if(log.isDebugEnabled())
- log.debug("property : "+property +" could not be retrieved as beanInfo was null.");
- throw new PropertyNotFoundException("Exception getting value of property " + property
- + " - beanInfo was null ");
- }
-
PropertyDescriptor[] propDescriptors =
beanInfo.getPropertyDescriptors();
@@ -541,14 +489,14 @@
// TODO: cache this in classLoader safe way
for (int i = 0, len = propDescriptors.length; i < len; i++)
{
- if (propDescriptors[i].getName().equals(property))
+ if (propDescriptors[i].getName().equals(propertyName))
return propDescriptors[i];
}
}
throw new PropertyNotFoundException("Bean: "
+ beanInfo.getBeanDescriptor().getBeanClass().getName()
- + ", property: " + property);
+ + ", property: " + propertyName);
}
}