View Javadoc
1 /* 2 Copyright (c) 2003, Laurent Caillette. 3 All rights reserved. 4 5 Redistribution and use in source and binary forms, with or without modifica- 6 tion, are permitted provided that the following conditions are met: 7 8 1. Redistributions of source code must retain the above copyright notice, 9 this list of conditions and the following disclaimer. 10 11 2. Redistributions in binary form must reproduce the above copyright notice, 12 this list of conditions and the following disclaimer in the documentation 13 and/or other materials provided with the distribution. 14 15 3. The end-user documentation included with the redistribution, if any, must 16 include the following acknowledgment: "This product includes software 17 written by Laurent Caillette." 18 Alternately, this acknowledgment may appear in the software itself, if 19 and wherever such third-party acknowledgments normally appear. 20 21 4. The name "Laurent Caillette" must not be used to endorse or 22 promote products derived from this software without 23 prior written permission. For written permission, please contact 24 laurent.caillette@laposte.net 25 26 5. Products derived from this software may not be called 27 "Laurent Caillette", nor may "Laurent Caillette" appear 28 in their name, without prior written permission of the 29 author. 30 31 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 32 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 33 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 34 AUTHOR (LAURENT CAILLETTE) BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 35 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 36 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 37 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 38 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 39 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 40 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 41 */ 42 package tweed.invocation; 43 import java.io.IOException; 44 import org.apache.avalon.framework.logger.Logger; 45 import tweed.context.Context; 46 47 48 /*** 49 * A <code>CommandInvoker</code> is supposed to run client-side. 50 * It makes a <code>Command</code> instance execute server-side. 51 * Concrete implementations of an <code>CommandInvoker</code> will rely on 52 * a particular middleware. 53 * Command implementors should not manipulate this class directly. 54 * 55 * @author Laurent Caillette 56 * @version $Id$ 57 */ 58 public abstract class CommandInvoker { 59 60 public final static String CHILDLOGGER_NAME = "invoker" ; 61 62 private final Context context ; 63 private final Logger logger ; 64 65 public CommandInvoker( Context context ) { 66 if( context == null ) { 67 throw new IllegalArgumentException( "context == null" ) ; 68 } 69 this.context = context ; 70 logger = context.getLogger().getChildLogger( CHILDLOGGER_NAME ) ; 71 } 72 73 protected final Logger getLogger() { 74 return logger ; 75 } 76 77 protected final Context getContext() { 78 return context ; 79 } 80 81 public void invoke( Command command ) { 82 83 getLogger().debug( "Preparing execution of command " + command ) ; 84 ExternalizedCommand toExecute = new ExternalizedCommand() ; 85 toExecute.enableLogging( getLogger() ) ; 86 toExecute.prepareServerInvocationOnClient( command ) ; 87 88 getLogger().debug( 89 "Launching server-side execution of command " + command ) ; 90 91 toExecute.enableLogging( getLogger().getChildLogger( "ext-command" ) ) ; 92 ExternalizedCommand returned ; // = new ExternalizedCommand() ; 93 94 try { 95 returned = doInvoke( toExecute ) ; 96 } catch( IOException ex ) { 97 // TODO find something smarter than this 98 throw new RuntimeException( ex ) ; 99 } 100 101 returned.enableLogging( getLogger().getChildLogger( "ext-command" ) ) ; 102 getLogger().debug( 103 "Server-side execution complete for command " + command ) ; 104 105 returned.reconfigureOnClient( command ) ; 106 107 if( command.wasSuccess() ) { 108 getLogger().debug( "Execution successful for command " + command ) ; 109 } else { 110 getLogger().debug( 111 "Functional exception caught while executing command " + command, 112 command.getFunctionalException() 113 ) ; 114 } 115 } 116 117 protected abstract ExternalizedCommand doInvoke( 118 ExternalizedCommand externalizedCommand 119 ) throws IOException ; 120 121 }

This page was automatically generated by Maven