001 package com.sptci.echo2;
002
003 import java.io.Serializable;
004
005 import java.lang.reflect.InvocationTargetException;
006 import java.lang.reflect.Method;
007
008 import java.util.ArrayList;
009 import java.util.List;
010 import java.util.Map;
011 import java.util.logging.Logger;
012
013 import nextapp.echo2.app.ListBox;
014 import nextapp.echo2.app.SelectField;
015 import nextapp.echo2.app.button.ToggleButton;
016 import nextapp.echo2.app.list.DefaultListModel;
017
018 import com.sptci.ReflectionUtility;
019
020 /**
021 * An <code>updater</code> used to update JavaBean objects from
022 * their associated UI containers.
023 *
024 * <p>Copyright 2006 Sans Pareil Technologies, Inc.</p>
025 * @author Rakesh Vidyadharan 2006-02-08
026 * @version $Id: ModelUpdater.java,v 1.3 2006/02/15 00:48:26 rakesh Exp $
027 */
028 public class ModelUpdater extends Updater implements Serializable
029 {
030 /**
031 * The logger used to log errors/warnings to.
032 */
033 private static transient final Logger logger =
034 Logger.getLogger( "com.sptci.echo2.ModelUpdater" );
035
036 /**
037 * Create a new instance with the specified UI container and java
038 * bean.
039 *
040 * @param uiContainer The {@link #uiContainer} to use.
041 * @param bean The {@link #bean} to use.
042 */
043 public ModelUpdater( Object uiContainer, Object bean )
044 {
045 super( uiContainer, bean );
046 }
047
048 /**
049 * Update the fields of the {@link #bean} with the data in
050 * similarly named fields in {@link #uiContainer}.
051 *
052 * @see ReflectionUtility#fetchField
053 * @see ReflectionUtility#fetchMethod
054 * @throws BindingException If errors are encountered while
055 * accessing or setting the fields.
056 */
057 public void update()
058 {
059 try
060 {
061 for ( Map.Entry<String, Object> entry : uiValues().entrySet() )
062 {
063 try
064 {
065 Object object =
066 ReflectionUtility.fetchObject( entry.getKey(), bean );
067
068 Method method =
069 ReflectionUtility.fetchMutator( entry.getKey(), bean );
070 method.invoke( bean, entry.getValue() );
071 }
072 catch ( NoSuchFieldException nsfe )
073 {
074 logger.finer( org.rakeshv.utils.StringUtilities.stackTrace( nsfe ) );
075 }
076 }
077 }
078 catch ( Throwable t )
079 {
080 throw new BindingException( t );
081 }
082 }
083 }