/*********************************************************************
* AssistedRemotingHandler.java
* created on 23.07.2006 by netseeker
* $Id: AssistedRemotingHandler.java,v 1.7 2007/11/17 10:56:59 netseeker Exp $
* $Log: AssistedRemotingHandler.java,v $
* Revision 1.7 2007/11/17 10:56:59 netseeker
* *** empty log message ***
*
* Revision 1.6 2006/11/06 08:50:30 netseeker
* fixed java 1.4 support
*
* Revision 1.5 2006/11/05 16:59:31 netseeker
* added support for remote reflection via usage of RemotingHandlers
*
* Revision 1.4 2006/08/09 20:13:54 netseeker
* *** empty log message ***
*
* Revision 1.3 2006/07/29 00:17:56 netseeker
* *** empty log message ***
*
* Revision 1.2 2006/07/27 20:35:15 netseeker
* *** empty log message ***
*
*
* ====================================================================
*
* Copyright 2006 netseeker aka Michael Manske
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*
* This file is part of the EJOE framework.
* For more information on the author, please see
* <http://www.manskes.de/>.
*
*********************************************************************/
package de.netseeker.ejoe.handler;
import de.netseeker.ejoe.handler.gen.DynProxyGenerator;
import de.netseeker.ejoe.handler.gen.IDynAccess;
import de.netseeker.ejoe.handler.gen.IProxyGenerator;
/**
* A remoting handler which does use dynamically generated proxies instead of reflection for method invocations. A
* underlying implementation of {@link de.netseeker.ejoe.handler.gen.DynProxyGenerator} will create a new proxy class
* for each class-method-arguments combination and reuse that proxy class for all following invocations of that method
* (or constructor).
*
* @author netseeker
* @since 0.3.9.1
*/
public class AssistedRemotingHandler extends BaseRemotingHandler
{
/**
*
*/
private static final long serialVersionUID = 1L;
private IProxyGenerator generator;
/**
* Creates a new AssistedRemotingHandler using the Javassist based DynProxyGenerator
*
* @see de.netseeker.ejoe.handler.gen.DynProxyGenerator
*/
public AssistedRemotingHandler()
{
this( new DynProxyGenerator() );
}
/**
* Creates a new AssistedRemotingHandler using a custom IProxyGenerator
*
* @param generator the proxy generator to use
*/
public AssistedRemotingHandler(IProxyGenerator generator)
{
this.generator = generator;
}
Object handle( Class target, String method, Object[] args ) throws Exception
{
IDynAccess proxy = generator.getDynAccessProxy( target, method, args );
if ( proxy != null )
{
// proxy.setDynTarget( target );
return proxy.invokeDynMethod( method, args );
}
else
{
throw new ClassNotFoundException( "Proxy for " + target.getName() + '#' + method
+ "(...) could not be created!" );
}
}
}