
hudson.util.InterceptingProxy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hudson-core Show documentation
Show all versions of hudson-core Show documentation
Contains the core Hudson code and view files to render HTML.
The newest version!
/*******************************************************************************
*
* Copyright (c) 2004-2010 Oracle Corporation.
*
* 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:
*
*
*******************************************************************************/
package hudson.util;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
/**
* Creates a proxy that traps every method call.
*
* @author Kohsuke Kawaguchi
*/
public abstract class InterceptingProxy {
/**
* Intercepts every method call.
*/
protected abstract Object call(Object o, Method m, Object[] args) throws Throwable;
public final T wrap(Class type, final T object) {
return type.cast(Proxy.newProxyInstance(type.getClassLoader(), new Class[]{type}, new InvocationHandler() {
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
try {
return call(object,method,args);
} catch (InvocationTargetException e) {
throw e.getTargetException();
}
}
}));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy