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.context;
43 import org.apache.avalon.framework.logger.Logger;
44 import tweed.action.ActionPerformer;
45 import tweed.binding.InputValidationHub;
46 import tweed.invocation.CommandInvoker;
47 import tweed.system.bus.EventBus;
48
49 /***
50 * Use this class to provide a modified version of a
51 * {@link tweed.context.Context} instance, without modifying the original.
52 * <p>
53 * <b>Limitations:</b><br>
54 * <ul>
55 * <li>
56 * This class does not patch <code>Context</code> subclass instances
57 * correctly yet, instead of returning a dynamic proxy it returns an
58 * instance of a nested class.
59 * </li><li>
60 * Event bus interconnexion is not supported.
61 * </li>
62 * </ul>
63 *
64 * @author Laurent Caillette
65 * @version $Id$
66 */
67 public class ContextPatcher {
68
69 private final Context original ;
70
71 public ContextPatcher( Context original ) {
72 this.original = original ;
73 }
74
75 private Logger newLogger = null ;
76 private boolean loggerModified = false ;
77
78 public void setNewLogger( Logger logger ) {
79 newLogger = logger ;
80 loggerModified = true ;
81 }
82
83 public Context getPatchedContext() {
84 Context patched = new PatchedContext( original ) ;
85
86 if( loggerModified) {
87 final Logger logger = newLogger ;
88 patched = new PatchedContext( patched ) {
89 public Logger getLogger() {
90 return logger ;
91 }
92 } ;
93 }
94
95 return patched ;
96 }
97
98
99 private static class PatchedContext implements Context {
100
101 private final Context delegate ;
102
103 public Context getContext() {
104 return this ;
105 }
106
107 public PatchedContext( Context original ) {
108 delegate = original ;
109 }
110
111 public CommandInvoker getInvoker() {
112 return delegate.getInvoker() ;
113 }
114
115 public boolean isClientSide() {
116 return delegate.isClientSide() ;
117 }
118
119 public boolean isServerSide() {
120 return delegate.isServerSide() ;
121 }
122
123 public Logger getLogger() {
124 return delegate.getLogger() ;
125 }
126
127 public InputValidationHub getInputValidationHub() {
128 return delegate.getInputValidationHub() ;
129 }
130
131 public EventBus getBus() {
132 return delegate.getBus() ;
133 }
134
135 public ActionPerformer getActionPerformer() {
136 return delegate.getActionPerformer() ;
137 }
138
139
140 }
141
142 }
This page was automatically generated by Maven