webwork/src/main/webwork/util BeanUtil.java,1.19,1.20
[email protected] Sat, 29 Jun 2002 18:27:11 -0700
| Newsgroups | gmane.comp.java.webwork.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/webwork/webwork/src/main/webwork/util
In directory usw-pr-cvs1:/tmp/cvs-serv15301
Modified Files:
BeanUtil.java
Log Message:
added toStringValue
Index: BeanUtil.java
===================================================================
RCS file: /cvsroot/webwork/webwork/src/main/webwork/util/BeanUtil.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- BeanUtil.java 23 Jun 2002 23:50:01 -0000 1.19
+++ BeanUtil.java 30 Jun 2002 01:27:09 -0000 1.20
@@ -7,6 +7,7 @@
package webwork.util;
import webwork.action.IllegalArgumentAware;
+import webwork.action.ValidationEditorSupport;
import webwork.util.editor.*;
import java.beans.*;
@@ -33,7 +34,8 @@
static Map objectMap = new WeakHashMap();
static final Category log = LoggerUtil.getLogger(BeanUtil.class);
- static {
+ static
+ {
PropertyEditorManager.registerEditor(Integer.class, IntegerEditor.class);
PropertyEditorManager.registerEditor(Double.class, DoubleEditor.class);
PropertyEditorManager.registerEditor(Byte.class, ByteEditor.class);
@@ -53,7 +55,7 @@
* @exception IllegalArgumentException thrown if the copy fails for some reason
*/
public static void copy(Object from, Object to)
- throws IllegalArgumentException
+ throws IllegalArgumentException
{
copy(from, to, true);
}
@@ -67,40 +69,34 @@
* @exception IllegalArgumentException thrown if the copy fails for some reason
*/
public static void copy(Object from, Object to, boolean includeNull)
- throws IllegalArgumentException
- {
- try
- {
- Object[] readParameters = new Object[0];
- Object[] writeParameters = new Object[1];
- PropertyDescriptor[] propertiesFrom = getPropertyDescriptors(from.getClass());
- PropertyDescriptor[] propertiesTo = getPropertyDescriptors(to.getClass());
- for (int i = 0; i < propertiesFrom.length; i++)
- {
- PropertyDescriptor pdFrom = propertiesFrom[i];
- for (int j = 0; j < propertiesTo.length; j++)
- {
- PropertyDescriptor pdTo = propertiesTo[j];
- if (pdFrom.getName().equals(pdTo.getName()))
- {
- Method readMethod = pdFrom.getReadMethod();
- Method writeMethod = pdTo.getWriteMethod();
- if (writeMethod != null && readMethod != null)
- {
- writeParameters[0] = pdFrom.getReadMethod().invoke(from, readParameters);
- if (!(!includeNull && writeParameters[0] == null))
- pdTo.getWriteMethod().invoke(to, writeParameters);
- }
- break;
+ throws IllegalArgumentException
+ {
+ try {
+ Object[] readParameters = new Object[0];
+ Object[] writeParameters = new Object[1];
+ PropertyDescriptor[] propertiesFrom = getPropertyDescriptors(from.getClass());
+ PropertyDescriptor[] propertiesTo = getPropertyDescriptors(to.getClass());
+ for(int i = 0; i < propertiesFrom.length; i++) {
+ PropertyDescriptor pdFrom = propertiesFrom[i];
+ for(int j = 0; j < propertiesTo.length; j++) {
+ PropertyDescriptor pdTo = propertiesTo[j];
+ if(pdFrom.getName().equals(pdTo.getName())) {
+ Method readMethod = pdFrom.getReadMethod();
+ Method writeMethod = pdTo.getWriteMethod();
+ if(writeMethod != null && readMethod != null) {
+ writeParameters[0] = pdFrom.getReadMethod().invoke(from, readParameters);
+ if(!(!includeNull && writeParameters[0] == null))
+ pdTo.getWriteMethod().invoke(to, writeParameters);
}
+ break;
}
}
- } catch (Exception e)
- {
- log.warn("Bean copy failed:+e" , e);
- throw new IllegalArgumentException("Bean copy failed:"+e);
}
+ } catch(Exception e) {
+ log.warn("Bean copy failed:+e", e);
+ throw new IllegalArgumentException("Bean copy failed:" + e);
}
+ }
/**
@@ -117,32 +113,22 @@
{
String key = null;
- try
- {
+ try {
Iterator keys = from.keySet().iterator();
- while (keys.hasNext())
- {
+ while(keys.hasNext()) {
key = (String)keys.next();
setProperty(key, from.get(key), to);
}
- }
- catch (Throwable e)
- {
- if (e instanceof IllegalArgumentException)
- {
+ } catch(Throwable e) {
+ if(e instanceof IllegalArgumentException) {
// Handle actions specially
IllegalArgumentException ex = (IllegalArgumentException)e;
- if (to instanceof IllegalArgumentAware)
- {
+ if(to instanceof IllegalArgumentAware) {
((IllegalArgumentAware)to).addIllegalArgumentException(key, ex);
- }
- else
- {
+ } else {
throw ex;
}
- }
- else
- {
+ } else {
log.warn("Could not set parameter \"" + key + "\":" + e, e);
throw new IllegalArgumentException("Could not set parameter \"" + key + "\":" + e);
}
@@ -169,138 +155,123 @@
int totalNumberOfSegments = findTheActualNumberOfSegments(segments);
- for (int i = 0; i < totalNumberOfSegments; ++i)
- {
- if(curObject==null)
- {
- throw new IllegalArgumentException("The target object for property '"+propertyName+"'. The target object needs to be initialized to a non-null value in order to set this property.");
- }
+ for(int i = 0; i < totalNumberOfSegments; ++i) {
+ if(curObject == null) {
+ throw new IllegalArgumentException("The target object for property '" + propertyName + "'. The target object needs to be initialized to a non-null value in order to set this property.");
+ }
QuerySegment curSegment = segments[i];
PropertyDescriptor descriptor = getPropertyDescriptor(curSegment.getId(), curObject);
- if (descriptor == null && curSegment.getType() != QuerySegment.COLLECTION)
- {
+ if(descriptor == null && curSegment.getType() != QuerySegment.COLLECTION) {
return;
- }
- else if (curSegment.getType() == QuerySegment.COLLECTION)
- {
+ } else if(curSegment.getType() == QuerySegment.COLLECTION) {
String key = curSegment.getId();
// Map
- if (Map.class.isAssignableFrom (curObject.getClass()))
- {
- curObject = ((Map) curObject).get(key.toString());
+ if(Map.class.isAssignableFrom(curObject.getClass())) {
+ curObject = ((Map)curObject).get(key.toString());
}
// Resource Bundle
- else if (ResourceBundle.class.isAssignableFrom(curObject.getClass()))
- {
+ else if(ResourceBundle.class.isAssignableFrom(curObject.getClass())) {
curObject = ((ResourceBundle)curObject).getObject(key.toString());
}
// Array
- else if (curObject.getClass().isArray())
- {
- curObject = ((Object[]) curObject)[Integer.parseInt(key)];
+ else if(curObject.getClass().isArray()) {
+ curObject = ((Object[])curObject)[Integer.parseInt(key)];
}
// List
- else if (List.class.isAssignableFrom(curObject.getClass()))
- {
- curObject = ((List) curObject).get(Integer.parseInt(key));
+ else if(List.class.isAssignableFrom(curObject.getClass())) {
+ curObject = ((List)curObject).get(Integer.parseInt(key));
}
// Collection
- else if (Collection.class.isAssignableFrom(curObject.getClass()))
- {
+ else if(Collection.class.isAssignableFrom(curObject.getClass())) {
// Not very efficient, but at least it works
curObject = ((Collection)curObject).toArray()[Integer.parseInt(key)];
}
- }
- else if (curSegment.getType() == QuerySegment.PROPERTY) //regular properties
+ } else if(curSegment.getType() == QuerySegment.PROPERTY) //regular properties
{
- try
- {
- if (descriptor instanceof IndexedPropertyDescriptor)
- {
+ try {
+ if(descriptor instanceof IndexedPropertyDescriptor) {
throw new IllegalArgumentException("Attempting to set a indexed field " + curSegment.getId() + "as an non-indexed field");
}
//if here then we are setting the property directly
- if ((i + 1) == totalNumberOfSegments)
- {
+ if((i + 1) == totalNumberOfSegments) {
setValue(curObject, descriptor, val);
return;
}
//if here then read a property to continue on...
- else
- {
+ else {
Method m = descriptor.getReadMethod();
- if (m == null)
- {
+ if(m == null) {
throw new IllegalArgumentException("Read Method " + descriptor.getName() + " for " + curObject.getClass().getName() + " was not found");
}
curObject = m.invoke(curObject, new Object[0]);
}
- }
- catch(IllegalArgumentException iae) {
+ } catch(IllegalArgumentException iae) {
throw iae;
- }
- catch(Exception e)
- {
+ } catch(Exception e) {
log.warn("Error executing read method for " + descriptor.getName() + " on " + curObject.getClass().getName(), e);
throw new IllegalArgumentException("Error executing read method for " + descriptor.getName() + " on " + curObject.getClass().getName());
}
}
//indexed properties
- else if (curSegment.getType() == QuerySegment.METHOD)
- {
+ else if(curSegment.getType() == QuerySegment.METHOD) {
Integer index = getIndexedPropertyIndex(curSegment);
- try
- {
+ try {
//if here then we are setting an indexed property directly
- if ((i + 1) == totalNumberOfSegments)
- {
- if (descriptor instanceof IndexedPropertyDescriptor)
- {
+ if((i + 1) == totalNumberOfSegments) {
+ if(descriptor instanceof IndexedPropertyDescriptor) {
setIndexedValue(curObject, (IndexedPropertyDescriptor)descriptor, val, index);
return;
- }
- else
- {
+ } else {
throw new IllegalArgumentException("Attempting to set non-indexed field \"" + curSegment.getId() + "\" as an indexed field");
}
}
//if here then get next object in the chain
- else
- {
- if (descriptor instanceof IndexedPropertyDescriptor)
- {
+ else {
+ if(descriptor instanceof IndexedPropertyDescriptor) {
Method m = ((IndexedPropertyDescriptor)descriptor).getIndexedReadMethod();
- if (m == null)
- {
+ if(m == null) {
throw new IllegalArgumentException("Indexed Read Method " + descriptor.getName() + " for " + curObject.getClass().getName() + " was not found");
}
curObject = m.invoke(curObject, new Object[]{index});
- }
- else
- {
+ } else {
throw new IllegalArgumentException("Attempting to access non-indexed field \"" + curSegment.getId() + "\" as an indexed field");
}
}
- }
- catch(IllegalArgumentException iae)
- {
+ } catch(IllegalArgumentException iae) {
throw iae;
- }
- catch(Exception e)
- {
- throw new IllegalArgumentException("Error executing index read method for "+((descriptor!=null)?descriptor.getName():"<null>")+" on "+((curObject!=null)?curObject.getClass().getName():"<null>"));
+ } catch(Exception e) {
+ throw new IllegalArgumentException("Error executing index read method for " + ((descriptor != null)?descriptor.getName():"<null>") + " on " + ((curObject != null)?curObject.getClass().getName():"<null>"));
}
}
}
}
/**
+ * Call toString on object. If object has an associated ValidationEditorSupport
+ * property editor then its getAsText will be called. This allows you to associate
+ * a common toString algorithm to call types.
+ */
+ public static String toStringValue(Object obj) {
+ String result = "";
+ if (obj!=null) {
+ PropertyEditor pd = PropertyEditorManager.findEditor(obj.getClass());
+ if (pd != null && pd instanceof ValidationEditorSupport) {
+ ((ValidationEditorSupport)pd).setValue(obj);
+ result = pd.getAsText();
+ } else {
+ result = obj.toString();
+ }
+ }
+ return result;
+ }
+
+ /**
* Get the value of the Index for indexed Properties.
*
* @param curSegment QuerySegment of type METHOD that we need the index from
@@ -309,17 +280,13 @@
private static Integer getIndexedPropertyIndex(QuerySegment curSegment)
{
Integer index = null;
- try
- {
+ try {
List values = curSegment.getValues();
- if (values.size() != 1)
- {
+ if(values.size() != 1) {
throw new IllegalArgumentException("Only Indexed properties allowed!");
}
index = new Integer(values.get(0).toString());
- }
- catch(Exception e)
- {
+ } catch(Exception e) {
throw new IllegalArgumentException("Only Indexed properties allowed! - Parameter must be an integer ");
}
return index;
@@ -333,10 +300,8 @@
*/
private static int findTheActualNumberOfSegments(QuerySegment[] segments)
{
- for(int i = 0; i < segments.length; ++i)
- {
- if (segments[i] == null)
- {
+ for(int i = 0; i < segments.length; ++i) {
+ if(segments[i] == null) {
return i;
}
}
@@ -356,30 +321,26 @@
*/
static protected boolean setValue(Object obj, PropertyDescriptor descriptor, Object val) throws IllegalArgumentException
{
- if (descriptor == null || descriptor.getWriteMethod() == null)
- {
+ if(descriptor == null || descriptor.getWriteMethod() == null) {
log.warn("No descriptor found for. Unable to set value. ");
return false;
}
//no value, so don't set it.
- if (val==null) return false;
+ if(val == null) return false;
Method m = descriptor.getWriteMethod();
Class valueClass = val.getClass();
Class parameterClass = m.getParameterTypes()[0];
- if (!valueClass.equals(String.class) && !valueClass.equals(String[].class) && !parameterClass.equals(String.class))
- {
+ if(!valueClass.equals(String.class) && !valueClass.equals(String[].class) && !parameterClass.equals(String.class)) {
return setObjectDirectly(parameterClass, valueClass, val, m, obj);
}
String[] value = convertObjectToStringArray(val);
- if (value != null)
- {
- if (descriptor.getPropertyEditorClass() == null) // No property editor given -> try default conversions
+ if(value != null) {
+ if(descriptor.getPropertyEditorClass() == null) // No property editor given -> try default conversions
{
- if (setStringValueDirectly(obj, descriptor, value))
- {
+ if(setStringValueDirectly(obj, descriptor, value)) {
return true;
}
}
@@ -399,17 +360,15 @@
{
Class valueClass = val.getClass();
- if (valueClass.equals(String.class))
- {
- return new String[]{ (String)val };
+ if(valueClass.equals(String.class)) {
+ return new String[]{(String)val};
}
- if (valueClass.equals(String[].class))
- {
+ if(valueClass.equals(String[].class)) {
return (String[])val;
}
- return new String[]{ val.toString() };
+ return new String[]{val.toString()};
}
/**
@@ -425,8 +384,7 @@
*/
static protected boolean setIndexedValue(Object obj, IndexedPropertyDescriptor descriptor, Object val, Integer index)
{
- if (descriptor == null)
- {
+ if(descriptor == null) {
log.info("no descriptor found");
return false;
}
@@ -434,19 +392,16 @@
Method m = descriptor.getIndexedWriteMethod();
Class valueClass = val.getClass();
Class parameterClass = m.getParameterTypes()[1];
- if (!valueClass.equals(String.class) && !valueClass.equals(String[].class) && !parameterClass.equals(String.class))
- {
+ if(!valueClass.equals(String.class) && !valueClass.equals(String[].class) && !parameterClass.equals(String.class)) {
return setIndexedObjectDirectly(parameterClass, valueClass, val, m, obj, index);
}
String[] value = convertObjectToStringArray(val);
- if (value != null)
- {
- if (descriptor.getPropertyEditorClass() == null) // No property editor given -> try default conversions
+ if(value != null) {
+ if(descriptor.getPropertyEditorClass() == null) // No property editor given -> try default conversions
{
- if (setIndexedStringValueDirectly(obj, descriptor, value, index))
- {
+ if(setIndexedStringValueDirectly(obj, descriptor, value, index)) {
return true;
}
}
@@ -471,32 +426,24 @@
private static boolean setIndexedObjectDirectly(Class parameterClass, Class valueClass, Object val, Method m, Object obj, Integer index)
{
// Try setting it directly
- if (!parameterClass.isAssignableFrom(valueClass))
- {
+ if(!parameterClass.isAssignableFrom(valueClass)) {
// Convert numbers
//Category.getInstance(this.getClass()).debug("Assignable:"+Number.class.isAssignableFrom(valueClass)+" "+Number.class.isAssignableFrom(parameterClass)+" "+parameterClass);
- if (Number.class.isAssignableFrom(valueClass) && Number.class.isAssignableFrom(parameterClass))
- {
- if (Long.class.isAssignableFrom(parameterClass))
- {
+ if(Number.class.isAssignableFrom(valueClass) && Number.class.isAssignableFrom(parameterClass)) {
+ if(Long.class.isAssignableFrom(parameterClass)) {
val = new Long(((Number)val).longValue());
- }
- else if (Integer.class.isAssignableFrom(parameterClass))
- {
+ } else if(Integer.class.isAssignableFrom(parameterClass)) {
val = new Integer(((Number)val).intValue());
}
}
// throw new IllegalArgumentException("Parameter type of "+descriptor.getName()+"("+aMethod.getParameterTypes()[0].getName()+") does not match property type "+aValue.getClass().getName());
}
- try
- {
+ try {
Object[] writeParameter = new Object[]{index, val};
m.invoke(obj, writeParameter);
return true;
- }
- catch(Exception e)
- {
+ } catch(Exception e) {
// Ignore and continue
return false;
}
@@ -516,35 +463,27 @@
private static boolean setObjectDirectly(Class parameterClass, Class valueClass, Object val, Method m, Object obj)
{
// Try setting it directly
- if (!parameterClass.isAssignableFrom(valueClass))
- {
+ if(!parameterClass.isAssignableFrom(valueClass)) {
// Convert numbers
//Category.getInstance(this.getClass()).debug("Assignable:"+Number.class.isAssignableFrom(valueClass)+" "+Number.class.isAssignableFrom(parameterClass)+" "+parameterClass);
- if (Number.class.isAssignableFrom(valueClass) && Number.class.isAssignableFrom(parameterClass))
- {
- if (Long.class.isAssignableFrom(parameterClass))
- {
+ if(Number.class.isAssignableFrom(valueClass) && Number.class.isAssignableFrom(parameterClass)) {
+ if(Long.class.isAssignableFrom(parameterClass)) {
val = new Long(((Number)val).longValue());
- }
- else if (Integer.class.isAssignableFrom(parameterClass))
- {
+ } else if(Integer.class.isAssignableFrom(parameterClass)) {
val = new Integer(((Number)val).intValue());
}
}
// throw new IllegalArgumentException("Parameter type of "+descriptor.getName()+"("+aMethod.getParameterTypes()[0].getName()+") does not match property type "+aValue.getClass().getName());
}
- try
- {
- Object[] writeParameter = new Object[]{ val };
+ try {
+ Object[] writeParameter = new Object[]{val};
m.invoke(obj, writeParameter);
return true;
- }
- catch(Exception e)
- {
- if (e instanceof InvocationTargetException) {
+ } catch(Exception e) {
+ if(e instanceof InvocationTargetException) {
Throwable t = ((InvocationTargetException)e).getTargetException();
- if (t instanceof IllegalArgumentException) {
+ if(t instanceof IllegalArgumentException) {
throw (IllegalArgumentException)t;
}
}
@@ -565,26 +504,20 @@
*/
static protected boolean setStringValueDirectly(Object obj, PropertyDescriptor descriptor, String[] values) throws IllegalArgumentException
{
- try
- {
+ try {
Method m = descriptor.getWriteMethod();
- if (descriptor.getPropertyType().equals(String.class) ||
- descriptor.getPropertyType().equals(Object.class))
- {
- m.invoke(obj, new Object[]{ values[0] });
+ if(descriptor.getPropertyType().equals(String.class) ||
+ descriptor.getPropertyType().equals(Object.class)) {
+ m.invoke(obj, new Object[]{values[0]});
return true;
- }
- else if (descriptor.getPropertyType().equals(String[].class))
- {
- m.invoke(obj, new Object[]{ values });
+ } else if(descriptor.getPropertyType().equals(String[].class)) {
+ m.invoke(obj, new Object[]{values});
return true;
}
- }
- catch(Exception e)
- {
- if (e instanceof InvocationTargetException) {
+ } catch(Exception e) {
+ if(e instanceof InvocationTargetException) {
Throwable t = ((InvocationTargetException)e).getTargetException();
- if (t instanceof IllegalArgumentException) {
+ if(t instanceof IllegalArgumentException) {
throw (IllegalArgumentException)t;
}
}
@@ -604,40 +537,31 @@
*/
static protected void setStringValueWithPropertyEditor(Object obj, PropertyDescriptor descriptor, String[] values) throws IllegalArgumentException
{
- try
- {
+ try {
PropertyEditor pe = getPropertyEditor(descriptor);
Method m = descriptor.getWriteMethod();
- if (pe == null)
- {
+ if(pe == null) {
throw new IllegalArgumentException("No property editor registered for this type"); // No editor for this parameter type
}
- try
- {
+ try {
try {
pe.setAsText(values[0]);
Object realValue = pe.getValue();
- m.invoke(obj, new Object[]{ realValue });
- } catch (NumberFormatException nfe) { //need this for Sun's Editor's
+ m.invoke(obj, new Object[]{realValue});
+ } catch(NumberFormatException nfe) { //need this for Sun's Editor's
throw new IllegalArgumentException("Unable to set value for " + values[0]);
}
- } catch (IllegalArgumentException ex)
- {
- if (obj instanceof IllegalArgumentAware)
- {
+ } catch(IllegalArgumentException ex) {
+ if(obj instanceof IllegalArgumentAware) {
((IllegalArgumentAware)obj).addIllegalArgumentException(descriptor.getName(), ex);
}
}
- }
- catch(IllegalArgumentException iae)
- {
+ } catch(IllegalArgumentException iae) {
throw iae;
- }
- catch(Exception e)
- {
- if (e instanceof InvocationTargetException) {
+ } catch(Exception e) {
+ if(e instanceof InvocationTargetException) {
Throwable t = ((InvocationTargetException)e).getTargetException();
- if (t instanceof IllegalArgumentException) {
+ if(t instanceof IllegalArgumentException) {
throw (IllegalArgumentException)t;
}
}
@@ -657,27 +581,21 @@
*/
static protected void setIndexedStringValueWithPropertyEditor(Object obj, IndexedPropertyDescriptor descriptor, String[] values, Integer index) throws IllegalArgumentException
{
- try
- {
+ try {
PropertyEditor pe = getPropertyEditor(descriptor);
Method m = descriptor.getIndexedWriteMethod();
- if (pe == null)
- {
+ if(pe == null) {
throw new IllegalArgumentException("No property editor registered for this type"); // No editor for this parameter type
}
pe.setAsText(values[0]);
Object realValue = pe.getValue();
- m.invoke(obj, new Object[]{ index, realValue });
- }
- catch(IllegalArgumentException iae)
- {
+ m.invoke(obj, new Object[]{index, realValue});
+ } catch(IllegalArgumentException iae) {
throw iae;
- }
- catch(Exception e)
- {
- if (e instanceof InvocationTargetException) {
+ } catch(Exception e) {
+ if(e instanceof InvocationTargetException) {
Throwable t = ((InvocationTargetException)e).getTargetException();
- if (t instanceof IllegalArgumentException) {
+ if(t instanceof IllegalArgumentException) {
throw (IllegalArgumentException)t;
}
}
@@ -697,25 +615,19 @@
*/
static protected boolean setIndexedStringValueDirectly(Object obj, IndexedPropertyDescriptor descriptor, String[] values, Integer index) throws IllegalArgumentException
{
- try
- {
+ try {
Method m = descriptor.getIndexedWriteMethod();
- if ((descriptor.getIndexedPropertyType().equals(String.class)) || (descriptor.getIndexedPropertyType().equals(Object.class)))
- {
- m.invoke(obj, new Object[]{ index, values[0] });
+ if((descriptor.getIndexedPropertyType().equals(String.class)) || (descriptor.getIndexedPropertyType().equals(Object.class))) {
+ m.invoke(obj, new Object[]{index, values[0]});
return true;
- }
- else if (descriptor.getIndexedPropertyType().equals(String[].class))
- {
- m.invoke(obj, new Object[]{ index, values });
+ } else if(descriptor.getIndexedPropertyType().equals(String[].class)) {
+ m.invoke(obj, new Object[]{index, values});
return true;
}
- }
- catch(Exception e)
- {
- if (e instanceof InvocationTargetException) {
+ } catch(Exception e) {
+ if(e instanceof InvocationTargetException) {
Throwable t = ((InvocationTargetException)e).getTargetException();
- if (t instanceof IllegalArgumentException) {
+ if(t instanceof IllegalArgumentException) {
throw (IllegalArgumentException)t;
}
}
@@ -746,11 +658,9 @@
static protected Map getFieldMapForClass(Class objClass)
{
Map fieldMap = (Map)objectMap.get(objClass);
- if (fieldMap == null)
- {
+ if(fieldMap == null) {
fieldMap = buildFieldMap(objClass);
- if (fieldMap != null)
- {
+ if(fieldMap != null) {
objectMap.put(objClass, fieldMap);
}
}
@@ -767,10 +677,8 @@
{
Map fieldMap = new WeakHashMap();
PropertyDescriptor[] descriptors = getPropertyDescriptors(objClass);
- if (descriptors != null)
- {
- for(int i = 0; i < descriptors.length; ++i)
- {
+ if(descriptors != null) {
+ for(int i = 0; i < descriptors.length; ++i) {
fieldMap.put(descriptors[i].getName(), descriptors[i]);
}
return fieldMap;
@@ -787,26 +695,17 @@
static protected PropertyEditor getPropertyEditor(PropertyDescriptor descriptor)
{
Class peClass = descriptor.getPropertyEditorClass();
- try
- {
- if (peClass == null)
- {
- if (descriptor instanceof IndexedPropertyDescriptor)
- {
+ try {
+ if(peClass == null) {
+ if(descriptor instanceof IndexedPropertyDescriptor) {
return PropertyEditorManager.findEditor(((IndexedPropertyDescriptor)descriptor).getIndexedPropertyType());
- }
- else
- {
+ } else {
return PropertyEditorManager.findEditor(descriptor.getPropertyType());
}
- }
- else
- {
+ } else {
return (PropertyEditor)peClass.newInstance();
}
- }
- catch(Exception e)
- {
+ } catch(Exception e) {
throw new IllegalArgumentException(e.toString());
}
}
@@ -824,15 +723,11 @@
PropertyDescriptor[] descriptors = (PropertyDescriptor[])propertyDescriptors.get(objClass);
// Check if available
- if (descriptors == null)
- {
+ if(descriptors == null) {
BeanInfo beanInfo;
- try
- {
+ try {
beanInfo = Introspector.getBeanInfo(objClass, Object.class);
- }
- catch(IntrospectionException e)
- {
+ } catch(IntrospectionException e) {
// We're in trouble
// Let it try again on next request, but return "nothing" for now
return new PropertyDescriptor[0];
@@ -841,27 +736,21 @@
// Get list of descriptors that are ok
descriptors = beanInfo.getPropertyDescriptors();
List list = new ArrayList(descriptors.length);
- for(int i = 0; i < descriptors.length; i++)
- {
+ for(int i = 0; i < descriptors.length; i++) {
PropertyDescriptor descriptor = descriptors[i];
- if (descriptor instanceof IndexedPropertyDescriptor)
- {
+ if(descriptor instanceof IndexedPropertyDescriptor) {
Method readMethod = ((IndexedPropertyDescriptor)descriptor).getIndexedReadMethod();
Method writeMethod = ((IndexedPropertyDescriptor)descriptor).getIndexedWriteMethod();
//make sure it is not from Object
- if (verifyNotObjectProperty(readMethod, writeMethod))
- {
+ if(verifyNotObjectProperty(readMethod, writeMethod)) {
list.add(descriptor);
}
- }
- else
- {
+ } else {
Method readMethod = descriptor.getReadMethod();
Method writeMethod = descriptor.getWriteMethod();
- if (verifyNotObjectProperty(readMethod, writeMethod))
- {
+ if(verifyNotObjectProperty(readMethod, writeMethod)) {
list.add(descriptor);
}
}
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
No, I will not fix your computer.
http://thinkgeek.com/sf