Example usage for java.lang NoSuchMethodException getMessage

List of usage examples for java.lang NoSuchMethodException getMessage

Introduction

In this page you can find the example usage for java.lang NoSuchMethodException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.genologics.ri.userdefined.UDF.java

/**
 * Helper method to get the collection of UDFs from an object.
 *
 * @param thing The object that should have the UDFs.
 *
 * @return The collection of UDFs from {@code thing}.
 *
 * @throws IllegalArgumentException if {@code thing} is null, or if {@code thing}
 * does not have a publicly visible "getUserDefinedFields" method returning a {@code Collection}.
 *///from ww  w .j  a  v a  2 s  .  c  o  m
static Collection<UDF> getUDFCollection(Object thing) {
    if (thing == null) {
        throw new IllegalArgumentException("thing cannot be null");
    }

    Method getPropsMethod = classUdfMethods.get(thing.getClass());
    if (getPropsMethod == null) {
        try {
            getPropsMethod = thing.getClass().getMethod(UDF_METHOD_NAME);
            if (!Collection.class.isAssignableFrom(getPropsMethod.getReturnType())) {
                throw new IllegalArgumentException(
                        MessageFormat.format("The \"{0}\" method on {1} does not return a Collection.",
                                UDF_METHOD_NAME, thing.getClass().getName()));
            }

            classUdfMethods.put(thing.getClass(), getPropsMethod);
        } catch (NoSuchMethodException e) {
            throw new IllegalArgumentException(MessageFormat.format("There is no method \"{0}\" method on {1}.",
                    UDF_METHOD_NAME, thing.getClass().getName()));
        }
    }

    try {
        @SuppressWarnings("unchecked")
        Collection<UDF> udfs = (Collection<UDF>) getPropsMethod.invoke(thing);

        return udfs;
    } catch (IllegalAccessException e) {
        throw new IllegalArgumentException(MessageFormat.format("Cannot call method \"{0}\" method on {1}: {2}",
                UDF_METHOD_NAME, thing.getClass().getName(), e.getMessage()));
    } catch (InvocationTargetException e) {
        throw new RuntimeException("Exception while fetching UDFs from " + thing.getClass().getName(),
                e.getTargetException());
    }
}

From source file:org.physical_web.physicalweb.FileBroadcastService.java

private void changeWifiName() {
    String deviceName = "PW-" + mTitle + "-" + mPort;
    if (deviceName.length() > MAX_DEVICE_NAME_LENGTH) {
        deviceName = DEFAULT_DEVICE_NAME + mPort;
    }/*from   ww  w . j a  va  2 s  . c o  m*/
    try {
        WifiP2pManager manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
        WifiP2pManager.Channel channel = manager.initialize(this, getMainLooper(), null);
        Class[] paramTypes = new Class[3];
        paramTypes[0] = WifiP2pManager.Channel.class;
        paramTypes[1] = String.class;
        paramTypes[2] = WifiP2pManager.ActionListener.class;
        Method setDeviceName = manager.getClass().getMethod("setDeviceName", paramTypes);
        setDeviceName.setAccessible(true);

        Object arglist[] = new Object[3];
        arglist[0] = channel;
        arglist[1] = deviceName;
        arglist[2] = new WifiP2pManager.ActionListener() {

            @Override
            public void onSuccess() {
                Log.d(TAG, "setDeviceName succeeded");
            }

            @Override
            public void onFailure(int reason) {
                Log.d(TAG, "setDeviceName failed");
            }
        };
        setDeviceName.invoke(manager, arglist);

    } catch (NoSuchMethodException e) {
        Log.d(TAG, e.getMessage());
    } catch (IllegalAccessException e) {
        Log.d(TAG, e.getMessage());
    } catch (IllegalArgumentException e) {
        Log.d(TAG, e.getMessage());
    } catch (InvocationTargetException e) {
        Log.d(TAG, e.getMessage());
    }
}

From source file:sorcer.launcher.JavaProcessBuilder.java

protected Object invokeIgnoreErrors(Object target, String methodName, Class[] argTypes, Object... args) {
    try {/*from  w  w w  .java  2  s  .c o m*/
        Method method = target.getClass().getDeclaredMethod(methodName, argTypes);
        return method.invoke(target, args);
    } catch (NoSuchMethodException e) {
        // looks like we're not in jdk1.7
        log.warn(e.getMessage(), e);
        return null;
    } catch (InvocationTargetException e) {
        throw new RuntimeException(e.getMessage(), e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:org.kuali.coeus.common.budget.framework.query.operator.RelationalOperator.java

/**Compares this object with the specified object for order.
 *Returns a negative integer, zero, or a positive integer as this object
 *is less than, equal to, or greater than the specified object.
 *//*  w  ww  .ja v a 2 s.  c o m*/
protected int compare(Object baseBean) {
    int compareValue = 0;

    if (dataClass == null || !dataClass.equals(baseBean.getClass())) {

        dataClass = baseBean.getClass();

        try {
            field = dataClass.getDeclaredField(fieldName);
            if (!field.isAccessible()) {
                throw new NoSuchFieldException();
            }
        } catch (NoSuchFieldException noSuchFieldException) {
            try {
                String methodName = "";

                if (isBoolean) {
                    methodName = "is" + (fieldName.charAt(0) + "").toUpperCase() + fieldName.substring(1);
                } else {
                    methodName = "get" + (fieldName.charAt(0) + "").toUpperCase() + fieldName.substring(1);
                }
                method = dataClass.getMethod(methodName, null);
            } catch (NoSuchMethodException noSuchMethodException) {
                LOG.error(noSuchMethodException.getMessage(), noSuchMethodException);
            }
        }
    } //End if field==null && method==null

    try {
        if (field != null && field.isAccessible()) {

            if (!isBoolean) {
                Comparable comparable = (Comparable) field.get(baseBean);
                if (comparable == null && fixedData == null) {
                    compareValue = 0;
                } else if (comparable == null) {
                    throw new UnsupportedOperationException();
                } else {
                    compareValue = comparable.compareTo(fixedData);
                }

            } else {
                if (((Boolean) field.get(baseBean)).booleanValue() == booleanFixedData)
                    compareValue = 0;
                else
                    compareValue = 1;
            }
        } else {
            if (!isBoolean) {
                Comparable comparable = (Comparable) method.invoke(baseBean, null);
                if (comparable == null && fixedData == null) {
                    compareValue = 0;
                } else if (comparable == null) {
                    throw new UnsupportedOperationException();
                } else if (comparable != null && fixedData == null) {
                    compareValue = -1;
                } else {
                    compareValue = comparable.compareTo(fixedData);
                }
            } else {
                Boolean booleanObj = (Boolean) method.invoke(baseBean, null);
                if (booleanObj == null) {
                    compareValue = -1;
                } else {
                    if (booleanObj.booleanValue() == booleanFixedData)
                        compareValue = 0;
                    else
                        compareValue = 1;
                }
            }
        }
    } catch (IllegalAccessException illegalAccessException) {
        LOG.error(illegalAccessException.getMessage(), illegalAccessException);
    } catch (InvocationTargetException invocationTargetException) {
        LOG.error(invocationTargetException.getMessage(), invocationTargetException);
    }
    return compareValue;
}

From source file:com.madrobot.di.wizard.json.JSONSerializer.java

/**
 * Serialize a specific java object recursively.
 * /*w  w w  .  j  a v  a2 s  .c o  m*/
 * @param jsonObject
 *            Object whose fields need to be set
 * 
 * @param stack
 *            Stack of {@link ClassInfo} - entity type under consideration
 * 
 * @throws JSONException
 *             If an exception occurs during parsing
 */
private void serializer(JSONObject jsonObject, final Stack<Object> stack) throws JSONException {

    Object userObject = stack.peek();
    Class<?> userClass = userObject.getClass();
    Field[] fields = userClass.getDeclaredFields();

    for (Field field : fields) {

        String fieldName = field.getName();
        Class<?> classType = field.getType();
        String jsonKeyName = getKeyName(field);

        try {

            String getMethodName = getGetMethodName(fieldName, classType);
            Method getMethod = userClass.getDeclaredMethod(getMethodName);
            Object returnValue = getMethod.invoke(userObject, new Object[] {});

            if (Converter.isPseudoPrimitive(classType)) {
                Converter.storeValue(jsonObject, jsonKeyName, returnValue, field);
            } else if (Converter.isCollectionType(classType)) {

                JSONArray jsonArray = new JSONArray();
                boolean canAdd = true;

                if (returnValue instanceof Collection) {
                    Collection<?> userCollectionObj = (Collection<?>) returnValue;

                    if (userCollectionObj.size() != 0) {

                        Iterator<?> iterator = userCollectionObj.iterator();

                        while (iterator.hasNext()) {
                            Object itemObject = iterator.next();
                            JSONObject object = new JSONObject();
                            stack.push(itemObject);
                            serializer(object, stack);
                            jsonArray.put(object);
                        }
                    } else if (field.isAnnotationPresent(ItemType.class)) {
                        ItemType itemType = field.getAnnotation(ItemType.class);
                        canAdd = itemType.canEmpty();
                    }

                    if (canAdd)
                        jsonObject.put(jsonKeyName, jsonArray);
                } else if (returnValue instanceof Map) {
                    Map<?, ?> userMapObj = (Map<?, ?>) returnValue;
                    JSONObject object = new JSONObject(userMapObj);
                    jsonArray.put(object);
                    jsonObject.put(jsonKeyName, jsonArray);
                }
            } else {
                stack.push(returnValue);
                JSONObject object = new JSONObject();
                serializer(object, stack);
                jsonObject.put(jsonKeyName, object);
            }

        } catch (NoSuchMethodException e) {
            Log.e(TAG, e.getMessage());
        } catch (IllegalAccessException e) {
            Log.e(TAG, e.getMessage());
        } catch (InvocationTargetException e) {
            Log.e(TAG, e.getMessage());
        }
    }
}

From source file:com.sun.faces.el.MethodBindingImpl.java

private Method method(Object base) {
    if (null == base) {
        throw new MethodNotFoundException(name);
    }//  www. j a  va2 s.com

    Class clazz = base.getClass();
    try {
        return (clazz.getMethod(name, args));
    } catch (NoSuchMethodException e) {
        throw new MethodNotFoundException(name + ": " + e.getMessage());
    }

}

From source file:org.gbif.portal.web.view.WidgetControllerSupport.java

/**
 * @see org.gbif.portal.web.view.WidgetController#doPerform(java.lang.String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 *///w  w w .j  a v a2  s . co m
public void doPerform(String widgetName, HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    Object[] args = new Object[] { request, response };
    widgetName = StringUtils.capitalize(widgetName);
    try {
        if (logger.isDebugEnabled())
            logger.debug("widget name:" + widgetName);
        MethodUtils.invokeMethod(this, "add" + widgetName, args);
    } catch (NoSuchMethodException e) {
        logger.error("Unable to find method for widget: " + widgetName);
        logger.error("Missing method: add" + widgetName);
        logger.error(e.getMessage(), e);
    }
}

From source file:org.openadaptor.auxil.processor.map.AttributeMapProcessor.java

protected Object cloneMap(Map incoming) {
    if (incoming instanceof IOrderedMap) {
        return ((IOrderedMap) incoming).clone();
    }/*  w w  w  .j av a2 s  .  c om*/
    if (incoming instanceof MapFacade) {
        return ((MapFacade) incoming).clone();
    }
    if (incoming instanceof HashMap) {
        return ((HashMap) incoming).clone();
    }
    try {
        Method cloneMethod = incoming.getClass().getMethod(mapCloneMethod, (Class[]) null);
        return (cloneMethod.invoke(incoming, (Object[]) null));
    } catch (NoSuchMethodException nsme) {
        log.warn("Unable to find clone method  " + mapCloneMethod + "(). " + nsme.getMessage());
    } catch (InvocationTargetException ite) {
        log.warn("Unable to invoke clone method " + mapCloneMethod + "(). " + ite.getMessage());
    } catch (IllegalAccessException iae) {
        log.warn("Failed to invoke clone method " + mapCloneMethod + "(). " + iae.getMessage());
    }
    log.warn("Unable to clone incoming map - the original might get modified!");
    return incoming;
}

From source file:com.jaspersoft.jasperserver.util.JasperJdbcContainer.java

/**
 *  This method is a hack, using reflection invokes a private method on the CachedRowSet object to 
 *  extract the parameter payload. //from  w w  w . ja va  2 s .  com
 * @param crs CachedRowSet 
 * @return
 */
private Object[] getParameters(CachedRowSet crs) {
    Object[] params = null;
    try {
        Method method = crs.getClass().getMethod("getParams", (Class[]) null);
        method.setAccessible(true);
        params = (Object[]) method.invoke(crs, (Object[]) null);
    } catch (NoSuchMethodException e) {
        logger.error(e.getMessage(), e);
        throw new RemoteException("Can't get method name." + e.getMessage());
    } catch (SecurityException e) {
        logger.error(e.getMessage(), e);
        throw new RemoteException("Can't get method name." + e.getMessage());
    } catch (IllegalAccessException e) {
        logger.error(e.getMessage(), e);
        throw new RemoteException("Can't get method name." + e.getMessage());
    } catch (IllegalArgumentException e) {
        logger.error(e.getMessage(), e);
        throw new RemoteException("Can't get method name." + e.getMessage());
    } catch (InvocationTargetException e) {
        logger.error(e.getMessage(), e);
        throw new RemoteException("Can't get method name." + e.getMessage());
    }

    return params;

}

From source file:net.padaf.preflight.AbstractValidator.java

/**
 * Instantiate a ValidationHelper using the given class.
 * /*from  w  ww.j  a  v a  2s .  c o m*/
 * @param avhCls
 * @param cfg
 * @return
 * @throws ValidationException
 */
private AbstractValidationHelper instantiateHelper(Class<? extends AbstractValidationHelper> avhCls,
        ValidatorConfig cfg) throws ValidationException {
    try {
        Constructor<? extends AbstractValidationHelper> construct = avhCls
                .getConstructor(ValidatorConfig.class);
        return construct.newInstance(cfg);
    } catch (NoSuchMethodException e) {
        throw new ValidationException("Unable to create an instance of ValidationHelper : " + e.getMessage(),
                e);
    } catch (InvocationTargetException e) {
        throw new ValidationException("Unable to create an instance of ValidationHelper : " + e.getMessage(),
                e);
    } catch (IllegalAccessException e) {
        throw new ValidationException("Unable to create an instance of ValidationHelper : " + e.getMessage(),
                e);
    } catch (InstantiationException e) {
        throw new ValidationException("Unable to create an instance of ValidationHelper : " + e.getMessage(),
                e);
    }
}