001    /*
002     * Copyright 2002-2004 the original author or authors.
003     * 
004     * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005     * use this file except in compliance with the License. You may obtain a copy of
006     * the License at
007     * 
008     * http://www.apache.org/licenses/LICENSE-2.0
009     * 
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012     * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013     * License for the specific language governing permissions and limitations under
014     * the License.
015     */
016    package org.springframework.richclient.command.support;
017    
018    import org.apache.commons.logging.Log;
019    import org.apache.commons.logging.LogFactory;
020    import org.springframework.beans.factory.InitializingBean;
021    import org.springframework.beans.support.ArgumentConvertingMethodInvoker;
022    import org.springframework.richclient.command.ActionCommandExecutor;
023    
024    /**
025     * An implementation of <code>ActionCommandExecutor</code> that delegates
026     * job execution to a specified (static or non-static) method for command 
027     * execution.
028     *   
029     * @author Oliver Hutchison
030     * @see org.springframework.beans.support.MethodInvoker
031     */
032    public class MethodInvokingActionCommandExecutor extends ArgumentConvertingMethodInvoker implements
033            ActionCommandExecutor, InitializingBean {
034    
035        protected static final Log logger = LogFactory.getLog(MethodInvokingActionCommandExecutor.class);
036    
037        public void afterPropertiesSet() throws Exception {
038            prepare();
039        }
040    
041        public void execute() {
042            try {
043                invoke();
044            }
045            catch (RuntimeException e) {
046                throw e;
047            }
048            catch (Exception e) {
049                logger.warn("Could not invoke method '" + getTargetMethod() + "' on target object [" + getTargetObject()
050                        + "]", e);
051            }
052        }
053    
054    }