View Javadoc

1   /**********************************************************************
2    * AssistedRemotingHandler.java
3    * created on 23.07.2006 by netseeker
4    * $Id: AssistedRemotingHandler.java,v 1.7 2007/11/17 10:56:59 netseeker Exp $
5    * $Log: AssistedRemotingHandler.java,v $
6    * Revision 1.7  2007/11/17 10:56:59  netseeker
7    * *** empty log message ***
8    *
9    * Revision 1.6  2006/11/06 08:50:30  netseeker
10   * fixed java 1.4 support
11   *
12   * Revision 1.5  2006/11/05 16:59:31  netseeker
13   * added support for remote reflection via usage of RemotingHandlers
14   *
15   * Revision 1.4  2006/08/09 20:13:54  netseeker
16   * *** empty log message ***
17   *
18   * Revision 1.3  2006/07/29 00:17:56  netseeker
19   * *** empty log message ***
20   *
21   * Revision 1.2  2006/07/27 20:35:15  netseeker
22   * *** empty log message ***
23   *
24   *
25   * ====================================================================
26   *
27   *  Copyright 2006 netseeker aka Michael Manske
28   *
29   *  Licensed under the Apache License, Version 2.0 (the "License");
30   *  you may not use this file except in compliance with the License.
31   *  You may obtain a copy of the License at
32   *
33   *      http://www.apache.org/licenses/LICENSE-2.0
34   *
35   *  Unless required by applicable law or agreed to in writing, software
36   *  distributed under the License is distributed on an "AS IS" BASIS,
37   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
38   *  See the License for the specific language governing permissions and
39   *  limitations under the License.
40   * ====================================================================
41   *
42   * This file is part of the EJOE framework.
43   * For more information on the author, please see
44   * <http://www.manskes.de/>.
45   *
46   *********************************************************************/
47  
48  package de.netseeker.ejoe.handler;
49  
50  import de.netseeker.ejoe.handler.gen.DynProxyGenerator;
51  import de.netseeker.ejoe.handler.gen.IDynAccess;
52  import de.netseeker.ejoe.handler.gen.IProxyGenerator;
53  
54  /***
55   * A remoting handler which does use dynamically generated proxies instead of reflection for method invocations. A
56   * underlying implementation of {@link de.netseeker.ejoe.handler.gen.DynProxyGenerator} will create a new proxy class
57   * for each class-method-arguments combination and reuse that proxy class for all following invocations of that method
58   * (or constructor).
59   * 
60   * @author netseeker
61   * @since 0.3.9.1
62   */
63  public class AssistedRemotingHandler extends BaseRemotingHandler
64  {
65      /***
66       * 
67       */
68      private static final long serialVersionUID = 1L;
69      
70      private IProxyGenerator   generator;
71  
72      /***
73       * Creates a new AssistedRemotingHandler using the Javassist based DynProxyGenerator
74       * 
75       * @see de.netseeker.ejoe.handler.gen.DynProxyGenerator
76       */
77      public AssistedRemotingHandler()
78      {
79          this( new DynProxyGenerator() );
80      }
81  
82      /***
83       * Creates a new AssistedRemotingHandler using a custom IProxyGenerator
84       * 
85       * @param generator the proxy generator to use
86       */
87      public AssistedRemotingHandler(IProxyGenerator generator)
88      {
89          this.generator = generator;
90      }
91  
92      Object handle( Class target, String method, Object[] args ) throws Exception
93      {
94          IDynAccess proxy = generator.getDynAccessProxy( target, method, args );
95  
96          if ( proxy != null )
97          {
98              // proxy.setDynTarget( target );
99              return proxy.invokeDynMethod( method, args );
100         }
101         else
102         {
103             throw new ClassNotFoundException( "Proxy for " + target.getName() + '#' + method
104                     + "(...) could not be created!" );
105         }
106     }
107 }