at.spardat.xma.component.ProxyHandler Maven / Gradle / Ivy
/*******************************************************************************
* Copyright (c) 2003, 2007 s IT Solutions AT Spardat GmbH .
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* s IT Solutions AT Spardat GmbH - initial API and implementation
*******************************************************************************/
package at.spardat.xma.component;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
/**
* This class makes it possible to fully integrate components of different server side applications
* in one client side application. It is used internally by the runtime.
*
* @author s2877
*/
public class ProxyHandler implements InvocationHandler {
/** the object which implements the interfaces */
Object impl;
/**
* Creates a ProxyHandler for a given object.
* @param obj The object for which a proxy is needed
*/
public ProxyHandler(Object obj) {
impl=obj;
}
/* (non-Javadoc)
* @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
*/
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
try {
// handle equals: call it allways with the original object
if(method.getName().equals("equals")) {
Class[] paramTypes = method.getParameterTypes();
if(paramTypes.length==1&¶mTypes[0].equals(Object.class)) {
if(Proxy.isProxyClass(args[0].getClass())) {
Object other = Proxy.getInvocationHandler(args[0]);
if(other instanceof ProxyHandler) {
return method.invoke(impl,new Object[]{((ProxyHandler)other).impl});
}
}
}
}
// handle all other methods
Class[] paramTypes = method.getParameterTypes();
for(int i=0;i nothing to do.
}
}
}
if(needProxy) {
Class[] interfaces = new Class[ints.size()];
for(int i=0;i