Example usage for java.lang.reflect InvocationTargetException toString

List of usage examples for java.lang.reflect InvocationTargetException toString

Introduction

In this page you can find the example usage for java.lang.reflect InvocationTargetException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:uk.co.modularaudio.util.hibernate.ReflectionUtils.java

public static void copyOverGetAttributes(final Class<?> interfaceListingAttributes, final Object src,
        final Object dest) throws DatastoreException {
    try {//from ww w  .jav  a2 s .  c om
        final Method methods[] = interfaceListingAttributes.getMethods();

        for (int i = 0; i < methods.length; i++) {
            final Method getMethod = methods[i];
            final String methodName = getMethod.getName();

            if (methodName.startsWith("get")) {
                final Class<?> returnType = getMethod.getReturnType();

                final Object result = getMethod.invoke(src);

                final String setMethodName = methodName.replaceFirst("get", "set");

                final Method setMethod = interfaceListingAttributes.getDeclaredMethod(setMethodName,
                        new Class[] { returnType });

                setMethod.invoke(dest, result);
            }
        }
    } catch (final IllegalAccessException iae) {
        throw new DatastoreException("iae: " + iae.toString());
    } catch (final InvocationTargetException ite) {
        throw new DatastoreException("ite: " + ite.toString());
    } catch (final NoSuchMethodException nsme) {
        throw new DatastoreException("nsme: " + nsme.toString());
    }
}

From source file:org.apache.hadoop.hbase.client.coprocessor.Batch.java

/**
 * Creates a new {@link Batch.Call} instance that invokes a method
 * with the given parameters and returns the result.
 *
 * @param method the method reference to invoke
 * @param args zero or more arguments to be passed to the method
 * @param <T> the class type of the protocol implementation being invoked
 * @param <R> the return type for the method call
 * @return a {@code Callable} instance that will invoke the given method and
 * return the results// w w  w .j  ava 2 s  .  c om
 * @see org.apache.hadoop.hbase.client.HTable#coprocessorExec(Class, byte[], byte[], org.apache.hadoop.hbase.client.coprocessor.Batch.Call, org.apache.hadoop.hbase.client.coprocessor.Batch.Callback)
 */
public static <T extends CoprocessorProtocol, R> Call<T, R> forMethod(final Method method,
        final Object... args) {
    return new Call<T, R>() {
        public R call(T instance) throws IOException {
            try {
                if (Proxy.isProxyClass(instance.getClass())) {
                    InvocationHandler invoker = Proxy.getInvocationHandler(instance);
                    return (R) invoker.invoke(instance, method, args);
                } else {
                    LOG.warn("Non proxied invocation of method '" + method.getName() + "'!");
                    return (R) method.invoke(instance, args);
                }
            } catch (IllegalAccessException iae) {
                throw new IOException("Unable to invoke method '" + method.getName() + "'", iae);
            } catch (InvocationTargetException ite) {
                throw new IOException(ite.toString(), ite);
            } catch (Throwable t) {
                throw new IOException(t.toString(), t);
            }
        }
    };
}

From source file:com.jaspersoft.jasperserver.remote.dbservices.impl.BeanConnectionServiceImpl.java

/**
  */* www. j a v  a2  s.  com*/
  * @param resource
  * @return Connection object, guaranteed to be non-null (not found or not supported resource indicated by exception)
  * @throws ResourceNotFoundException if no resource found 
  * @throws RemoteException in case of unclassified error
  */
public Connection getConnection(Resource resource) {
    Connection result = null;
    long startTime = System.currentTimeMillis();
    try {
        if (logger.isDebugEnabled()) {
            logger.debug("Enter getConnection .. Start Time" + System.currentTimeMillis());
        }
        if (resource instanceof BeanReportDataSource) {
            BeanReportDataSource beanDataSource = (BeanReportDataSource) resource;
            applicationContext = StaticApplicationContext.getApplicationContext();
            Object bean = this.applicationContext.getBean(beanDataSource.getBeanName());
            Method serviceMethod = bean.getClass().getMethod(beanDataSource.getBeanMethod(), null);
            JdbcDataSourceService service = (JdbcDataSourceService) serviceMethod.invoke(bean, null);
            result = service.getDataSource().getConnection();
        } else {
            throw new RemoteException("Invalid Resource: Please check datasource url");
        }
    } catch (InvocationTargetException ex) {
        logger.error(ex.getMessage(), ex);
        throw new RemoteException("Cannot get bean datasource connection:" + ex.toString());
    } catch (Exception ex) {
        logger.error(ex.getMessage(), ex);
        throw new RemoteException("Cannot get bean datasource connection:" + ex.getMessage());
    } finally {
        if (logger.isDebugEnabled()) {
            long elapsedTime = System.currentTimeMillis() - startTime;
            logger.debug("Exit getConnection .. Total Time Spent: " + elapsedTime);
        }
    }
    return result;

}

From source file:Command.java

/**
 * This method implements the ActionListener interface. It is like invoke()
 * except that it catches the exceptions thrown by that method and rethrows
 * them as an unchecked RuntimeException
 */// w w w  . j a  v a2s .  c  o m
public void actionPerformed(ActionEvent e) {
    try {
        invoke(); // Call the invoke method
    } catch (InvocationTargetException ex) { // but handle the exceptions
        throw new RuntimeException("Command: " + ex.getTargetException().toString());
    } catch (IllegalAccessException ex) {
        throw new RuntimeException("Command: " + ex.toString());
    }
}

From source file:com.facebook.stetho.inspector.MethodDispatcher.java

public JSONObject dispatch(JsonRpcPeer peer, String methodName, @Nullable JSONObject params)
        throws JsonRpcException {
    MethodDispatchHelper dispatchHelper = findMethodDispatcher(methodName);
    if (dispatchHelper == null) {
        throw new JsonRpcException(new JsonRpcError(JsonRpcError.ErrorCode.METHOD_NOT_FOUND,
                "Not implemented: " + methodName, null /* data */));
    }/* w  w  w. j a va 2 s  . c  o m*/
    try {
        return dispatchHelper.invoke(peer, params);
    } catch (InvocationTargetException e) {
        Throwable cause = e.getCause();
        ExceptionUtil.propagateIfInstanceOf(cause, JsonRpcException.class);
        throw ExceptionUtil.propagate(cause);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    } catch (JSONException e) {
        throw new JsonRpcException(
                new JsonRpcError(JsonRpcError.ErrorCode.INTERNAL_ERROR, e.toString(), null /* data */));
    }
}

From source file:org.callimachusproject.setup.WebappArchiveImporter.java

private boolean deleteComponents(String folder) {
    try {//from w  ww. j a  v  a  2s. c  om
        try {
            repository.setSchemaGraphType(webapp + SCHEMA_GRAPH);
            repository.setCompileRepository(true);
            ObjectConnection con = repository.getConnection();
            try {
                con.begin();
                RDFObject obj = (RDFObject) con.getObject(folder);
                Method DeleteComponents = findDeleteComponents(obj);
                try {
                    logger.info("Removing {}", folder);
                    invokeAndRemove(DeleteComponents, obj, con);
                    con.commit();
                    return true;
                } catch (InvocationTargetException e) {
                    try {
                        throw e.getCause();
                    } catch (Exception cause) {
                        logger.warn(cause.toString());
                    } catch (Error cause) {
                        logger.warn(cause.toString());
                    } catch (Throwable cause) {
                        logger.warn(cause.toString());
                    }
                    con.rollback();
                    return false;
                }
            } catch (IllegalAccessException e) {
                logger.debug(e.toString());
            } catch (NoSuchMethodException e) {
                logger.debug(e.toString());
            } finally {
                con.rollback();
                repository.setCompileRepository(false);
                con.close();
            }
        } finally {
            repository.setCompileRepository(false);
        }
    } catch (RDFObjectException e) {
        logger.debug(e.toString());
    } catch (OpenRDFException e) {
        logger.debug(e.toString());
    }
    return false;
}

From source file:com.example.android.network.sync.basicsyncadapter.SyncAdapter.java

/**
 * Called by the Android system in response to a request to run the sync adapter. The work
 * required to read data from the network, parse it, and store it in the content provider is
 * done here. Extending AbstractThreadedSyncAdapter ensures that all methods within SyncAdapter
 * run on a background thread. For this reason, blocking I/O and other long-running tasks can be
 * run <em>in situ</em>, and you don't have to set up a separate thread for them.
 .
 *
 * <p>This is where we actually perform any work required to perform a sync.
 * {@link AbstractThreadedSyncAdapter} guarantees that this will be called on a non-UI thread,
 * so it is safe to peform blocking I/O here.
 *
 * <p>The syncResult argument allows you to pass information back to the method that triggered
 * the sync./*from   w w w  . jav  a 2 s .c o  m*/
 */
@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider,
        SyncResult syncResult) {
    Log.i(TAG, "Beginning network synchronization");
    try {
        final URL location = new URL(FEED_URL);
        InputStream stream = null;

        try {
            Log.i(TAG, "Streaming data from network: " + location);
            downloadAllObjectsForRegisteredModels(syncResult);
            //stream = downloadUrl(location);
            //updateLocalFeedData(stream, syncResult);
            // Makes sure that the InputStream is closed after the app is
            // finished using it.
        } finally {
            if (stream != null) {
                stream.close();
            }
        }
    }

    catch (InvocationTargetException e) {

    }

    catch (IllegalAccessException e) {

    }

    catch (MalformedURLException e) {
        Log.wtf(TAG, "Feed URL is malformed", e);
        syncResult.stats.numParseExceptions++;
        return;
    } catch (IOException e) {
        Log.e(TAG, "Error reading from network: " + e.toString());
        syncResult.stats.numIoExceptions++;
        return;
    } /*catch (XmlPullParserException e) {
      Log.e(TAG, "Error parsing feed: " + e.toString());
      syncResult.stats.numParseExceptions++;
      return;
      } catch (ParseException e) {
      Log.e(TAG, "Error parsing feed: " + e.toString());
      syncResult.stats.numParseExceptions++;
      return;
      } catch (RemoteException e) {
      Log.e(TAG, "Error updating database: " + e.toString());
      syncResult.databaseError = true;
      return;
      } catch (OperationApplicationException e) {
      Log.e(TAG, "Error updating database: " + e.toString());
      syncResult.databaseError = true;
      return;
      }*/
    Log.i(TAG, "Network synchronization complete");
}

From source file:com.actionbarsherlock.internal.nineoldandroids.animation.PropertyValuesHolder.java

/**
 * Utility function to set the value stored in a particular Keyframe. The value used is
 * whatever the value is for the property name specified in the keyframe on the target object.
 *
 * @param target The target object from which the current value should be extracted.
 * @param kf The keyframe which holds the property name and value.
 */// w w  w.  j a  v  a2 s .c  o m
private void setupValue(Object target, Keyframe kf) {
    //if (mProperty != null) {
    //    kf.setValue(mProperty.get(target));
    //}
    try {
        if (mGetter == null) {
            Class targetClass = target.getClass();
            setupGetter(targetClass);
        }
        kf.setValue(mGetter.invoke(target));
    } catch (InvocationTargetException e) {
        Log.e("PropertyValuesHolder", e.toString());
    } catch (IllegalAccessException e) {
        Log.e("PropertyValuesHolder", e.toString());
    }
}

From source file:com.actionbarsherlock.internal.nineoldandroids.animation.PropertyValuesHolder.java

/**
 * Internal function to set the value on the target object, using the setter set up
 * earlier on this PropertyValuesHolder object. This function is called by ObjectAnimator
 * to handle turning the value calculated by ValueAnimator into a value set on the object
 * according to the name of the property.
 * @param target The target object on which the value is set
 *//*www . j a v a2  s .  c  o  m*/
void setAnimatedValue(Object target) {
    //if (mProperty != null) {
    //    mProperty.set(target, getAnimatedValue());
    //}
    if (mSetter != null) {
        try {
            mTmpValueArray[0] = getAnimatedValue();
            mSetter.invoke(target, mTmpValueArray);
        } catch (InvocationTargetException e) {
            Log.e("PropertyValuesHolder", e.toString());
        } catch (IllegalAccessException e) {
            Log.e("PropertyValuesHolder", e.toString());
        }
    }
}

From source file:com.actionbarsherlock.internal.nineoldandroids.animation.PropertyValuesHolder.java

/**
 * Internal function (called from ObjectAnimator) to set up the setter and getter
 * prior to running the animation. If the setter has not been manually set for this
 * object, it will be derived automatically given the property name, target object, and
 * types of values supplied. If no getter has been set, it will be supplied iff any of the
 * supplied values was null. If there is a null value, then the getter (supplied or derived)
 * will be called to set those null values to the current value of the property
 * on the target object.//from   ww  w  . j  a  v a2 s .  co  m
 * @param target The object on which the setter (and possibly getter) exist.
 */
void setupSetterAndGetter(Object target) {
    //if (mProperty != null) {
    //    // check to make sure that mProperty is on the class of target
    //    try {
    //        Object testValue = mProperty.get(target);
    //        for (Keyframe kf : mKeyframeSet.mKeyframes) {
    //            if (!kf.hasValue()) {
    //                kf.setValue(mProperty.get(target));
    //            }
    //        }
    //        return;
    //    } catch (ClassCastException e) {
    //        Log.e("PropertyValuesHolder","No such property (" + mProperty.getName() +
    //                ") on target object " + target + ". Trying reflection instead");
    //        mProperty = null;
    //    }
    //}
    Class targetClass = target.getClass();
    if (mSetter == null) {
        setupSetter(targetClass);
    }
    for (Keyframe kf : mKeyframeSet.mKeyframes) {
        if (!kf.hasValue()) {
            if (mGetter == null) {
                setupGetter(targetClass);
            }
            try {
                kf.setValue(mGetter.invoke(target));
            } catch (InvocationTargetException e) {
                Log.e("PropertyValuesHolder", e.toString());
            } catch (IllegalAccessException e) {
                Log.e("PropertyValuesHolder", e.toString());
            }
        }
    }
}