Here you can find the source of invoke(Method method, Object data, Object... arguments)
Parameter | Description |
---|---|
method | a parameter |
data | a parameter |
arguments | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static Object invoke(Method method, Object data, Object... arguments) throws IOException
//package com.java2s; /*// w w w .java2 s .c om * Lightmare, Lightweight embedded EJB container (works for stateless session beans) with JPA / Hibernate support * * Copyright (c) 2013, Levan Tsinadze, or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class Main { /** * Common method to invoke {@link Method} with reflection * * @param method * @param data * @param arguments * @return {@link Object} * @throws IOException */ public static Object invoke(Method method, Object data, Object... arguments) throws IOException { Object value; try { value = method.invoke(data, arguments); } catch (IllegalAccessException ex) { throw new IOException(ex); } catch (IllegalArgumentException ex) { throw new IOException(ex); } catch (InvocationTargetException ex) { throw unwrap(ex); } return value; } /** * Gets target {@link Throwable} from passed * {@link InvocationTargetException} instance * * @param ex * @return {@link IOException} */ private static IOException unwrap(InvocationTargetException ex) { IOException exception; Throwable targetException = ex.getTargetException(); if (targetException == null) { exception = new IOException(ex.getMessage(), ex); } else { exception = new IOException(targetException.getMessage(), targetException); } return exception; } }