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.antsdb.saltedfish.util.UberUtil.java

@SuppressWarnings("unchecked")
public static <T> T clone(final T obj) throws CloneNotSupportedException {
    if (obj == null) {
        return null;
    }/*from   ww  w  .  j  a v  a2  s.  co  m*/
    if (obj instanceof Cloneable) {
        Class<?> clazz = obj.getClass();
        Method m;
        try {
            m = clazz.getMethod("clone", (Class[]) null);
        } catch (NoSuchMethodException ex) {
            throw new NoSuchMethodError(ex.getMessage());
        }
        try {
            return (T) m.invoke(obj, (Object[]) null);
        } catch (InvocationTargetException ex) {
            Throwable cause = ex.getCause();
            if (cause instanceof CloneNotSupportedException) {
                throw ((CloneNotSupportedException) cause);
            } else {
                throw new Error("Unexpected exception", cause);
            }
        } catch (IllegalAccessException ex) {
            throw new IllegalAccessError(ex.getMessage());
        }
    } else {
        throw new CloneNotSupportedException();
    }
}

From source file:grails.util.GrailsMetaClassUtils.java

/**
 * Copies the ExpandoMetaClass dynamic methods and properties from one Class to another.
 *
 * @param fromClass The source class//from w w w  . j a va 2  s. co m
 * @param toClass  The destination class
 * @param removeSource Whether to remove the source class after completion. True if yes
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void copyExpandoMetaClass(Class<?> fromClass, Class<?> toClass, boolean removeSource) {

    MetaClassRegistry registry = getRegistry();

    MetaClass oldMetaClass = registry.getMetaClass(fromClass);

    AdaptingMetaClass adapter = null;
    ExpandoMetaClass emc;

    if (oldMetaClass instanceof AdaptingMetaClass) {
        adapter = ((AdaptingMetaClass) oldMetaClass);
        emc = (ExpandoMetaClass) adapter.getAdaptee();
        if (LOG.isDebugEnabled()) {
            LOG.debug("Obtained adapted MetaClass [" + emc + "] from AdapterMetaClass instance [" + adapter
                    + "]");
        }

        if (removeSource) {
            registry.removeMetaClass(fromClass);
        }
    } else {
        emc = (ExpandoMetaClass) oldMetaClass;
        if (LOG.isDebugEnabled()) {
            LOG.debug("No adapter MetaClass found, using original [" + emc + "]");
        }
    }

    ExpandoMetaClass replacement = new ExpandoMetaClass(toClass, true, true);

    for (Object obj : emc.getExpandoMethods()) {
        if (obj instanceof ClosureInvokingMethod) {
            ClosureInvokingMethod cim = (ClosureInvokingMethod) obj;
            Closure callable = cim.getClosure();
            if (!cim.isStatic()) {
                replacement.setProperty(cim.getName(), callable);
            } else {
                ((GroovyObject) replacement.getProperty(ExpandoMetaClass.STATIC_QUALIFIER))
                        .setProperty(cim.getName(), callable);
            }
        }
    }

    for (Object o : emc.getExpandoProperties()) {
        if (o instanceof ThreadManagedMetaBeanProperty) {
            ThreadManagedMetaBeanProperty mbp = (ThreadManagedMetaBeanProperty) o;
            replacement.setProperty(mbp.getName(), mbp.getInitialValue());
        }
    }
    replacement.initialize();

    if (adapter == null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Adding MetaClass for class [" + toClass + "] MetaClass [" + replacement + "]");
        }
        registry.setMetaClass(toClass, replacement);
    } else {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Adding MetaClass for class [" + toClass + "] MetaClass [" + replacement
                    + "] with adapter [" + adapter + "]");
        }
        try {
            Constructor c = adapter.getClass().getConstructor(new Class[] { MetaClass.class });
            MetaClass newAdapter = (MetaClass) BeanUtils.instantiateClass(c, new Object[] { replacement });
            registry.setMetaClass(toClass, newAdapter);
        } catch (NoSuchMethodException e) {
            if (LOG.isDebugEnabled()) {
                LOG.debug(
                        "Exception thrown constructing new MetaClass adapter when reloading: " + e.getMessage(),
                        e);
            }
        }
    }
}

From source file:org.bigmouth.nvwa.pay.service.prepay.wx.WxPrepayInsideRequest.java

public static List<String> $arguments(PrepayInsideRequest obj) {
    Class<?> cls = obj.getClass();
    Field[] fields = cls.getDeclaredFields();
    List<String> parameters = Lists.newArrayList();
    for (Field field : fields) {
        String name = field.getName();
        try {/* w ww. j  a  v a 2 s  .c om*/
            StringBuilder str = new StringBuilder();
            String invokeName = StringUtils.join(new String[] { "get", StringUtils.capitalize(name) });
            Method method = cls.getMethod(invokeName);
            Object result = method.invoke(obj);
            if (null == result || (result instanceof String && StringUtils.isBlank(result.toString()))) {
                continue;
            }
            str.append(name).append("=").append(result.toString());
            parameters.add(str.toString());
        } catch (NoSuchMethodException e) {
            ;
        } catch (Exception e) {
            LOGGER.warn("$arguments-(" + name + "):" + e.getMessage());
        }
    }
    return parameters;
}

From source file:com.acrutiapps.browser.ui.components.CustomWebView.java

private static void loadMethods() {
    try {//ww w . ja va  2  s.co  m

        // 15 is ICS 2nd release.
        if (android.os.Build.VERSION.SDK_INT > 15) {
            // WebSettings became abstract in JB, and "setProperty" moved to the concrete class, WebSettingsClassic,
            // not present in the SDK. So we must look for the class first, then for the methods.
            ClassLoader classLoader = CustomWebView.class.getClassLoader();
            Class<?> webSettingsClassicClass = classLoader.loadClass("android.webkit.WebSettingsClassic");
            sWebSettingsSetProperty = webSettingsClassicClass.getMethod("setProperty",
                    new Class[] { String.class, String.class });
        } else {
            sWebSettingsSetProperty = WebSettings.class.getMethod("setProperty",
                    new Class[] { String.class, String.class });
        }

    } catch (NoSuchMethodException e) {
        Log.e("CustomWebView", "loadMethods(): " + e.getMessage());
        sWebSettingsSetProperty = null;
    } catch (ClassNotFoundException e) {
        Log.e("CustomWebView", "loadMethods(): " + e.getMessage());
        sWebSettingsSetProperty = null;
    }

    sMethodsLoaded = true;
}

From source file:com.armon.test.quartz.QuartzConfiguration.java

/**
 * Get the password from the Configuration instance using the
 * getPassword method if it exists. If not, then fall back to the
 * general get method for configuration elements.
 * @param conf configuration instance for accessing the passwords
 * @param alias the name of the password element
 * @param defPass the default password/*w ww.ja  v a  2 s.  c om*/
 * @return String password or default password
 * @throws IOException
 */
public static String getPassword(Configuration conf, String alias, String defPass) throws IOException {
    String passwd = null;
    try {
        Method m = Configuration.class.getMethod("getPassword", String.class);
        char[] p = (char[]) m.invoke(conf, alias);
        if (p != null) {
            LOG.debug(String.format(
                    "Config option \"%s\" was found through" + " the Configuration getPassword method.",
                    alias));
            passwd = new String(p);
        } else {
            LOG.debug(String.format("Config option \"%s\" was not found. Using provided default value", alias));
            passwd = defPass;
        }
    } catch (NoSuchMethodException e) {
        // this is a version of Hadoop where the credential
        //provider API doesn't exist yet
        LOG.debug(String
                .format("Credential.getPassword method is not available." + " Falling back to configuration."));
        passwd = conf.get(alias, defPass);
    } catch (SecurityException e) {
        throw new IOException(e.getMessage(), e);
    } catch (IllegalAccessException e) {
        throw new IOException(e.getMessage(), e);
    } catch (IllegalArgumentException e) {
        throw new IOException(e.getMessage(), e);
    } catch (InvocationTargetException e) {
        throw new IOException(e.getMessage(), e);
    }
    return passwd;
}

From source file:org.ajax4jsf.renderkit.ComponentUtils.java

/**
 * Invoke a named method whose parameter type matches the object type.
 * @param objects - invoke method on this object
 * @param methodName - get method with this name
 * @param arrayParameters - use these arguments - treat null as empty array
 * @return//  w ww. j  av  a2  s .co  m
 */
private static Object invokeMethod(Object object, String methodName, Object[][] arrayParameters) {

    try {
        for (int iParameter = 0; iParameter < arrayParameters.length; iParameter++) {
            try {
                return MethodUtils.invokeMethod(object, methodName, arrayParameters[iParameter]);
            } catch (NoSuchMethodException e) {
                continue;
            }
        }
    } catch (InvocationTargetException e) {
        throw new FacesException(
                Messages.getMessage(Messages.METHOD_CALL_ERROR_2b, methodName, e.getCause().getMessage()), e);
    } catch (IllegalAccessException e) {
        throw new FacesException(Messages.getMessage(Messages.METHOD_CALL_ERROR_4b, methodName, e.getMessage()),
                e);
    }
    throw new MethodNotFoundException(Messages.getMessage(Messages.METHOD_CALL_ERROR_6b, methodName, object));
}

From source file:hu.javaforum.util.internal.ReflectionHelper.java

/**
 * Returns the getter method of the field. It is recursive method.
 *
 * @param instanceClass The bean class/*from w  w w.  j  a  v  a  2  s.c o  m*/
 * @param instance The bean instance
 * @param fieldName The field name
 * @return The getter method, if it is exists
 * null, if the getter method is not exists
 */
protected static Method getGetterMethod(final Class instanceClass, final Object instance,
        final String fieldName) {
    PerfLogger logger = new PerfLogger(LOGGER);

    if ("java.lang.Object".equals(instanceClass.getName())) {
        return null;
    }

    try {
        StringBuilder sb = new StringBuilder(fieldName.length() + GET_WORD.length());
        sb.append(GET_WORD);
        sb.append(fieldName);
        sb.setCharAt(GET_WORD.length(), Character.toUpperCase(sb.charAt(GET_WORD.length())));
        return instanceClass.getDeclaredMethod(sb.toString());
    } catch (NoSuchMethodException except) {
        logger.debug("Invoking %1$s.%2$s() because %3$s", instanceClass.getSuperclass().getName(), fieldName,
                except.getMessage());
        return getGetterMethod(instanceClass.getSuperclass(), instance, fieldName);
    }
}

From source file:org.apache.struts.taglib.tiles.util.TagUtils.java

/**
 * Locate and return the specified property of the specified bean, from
 * an optionally specified scope, in the specified page context.
 *
 * @param pageContext Page context to be searched.
 * @param beanName Name of the bean to be retrieved.
 * @param beanProperty Name of the property to be retrieved, or
 *  <code>null</code> to retrieve the bean itself.
 * @param beanScope Scope to be searched (page, request, session, application)
 *  or <code>null</code> to use <code>findAttribute()</code> instead.
 *
 * @exception JspException Scope name is not recognized as a valid scope
 * @exception JspException if the specified bean is not found
 * @exception JspException if accessing this property causes an
 *  IllegalAccessException, IllegalArgumentException,
 *  InvocationTargetException, or NoSuchMethodException
 *//* ww w.java2 s  .  co m*/
public static Object getRealValueFromBean(String beanName, String beanProperty, String beanScope,
        PageContext pageContext) throws JspException {

    try {
        Object realValue;
        Object bean = retrieveBean(beanName, beanScope, pageContext);
        if (bean != null && beanProperty != null) {
            realValue = PropertyUtils.getProperty(bean, beanProperty);
        } else {
            realValue = bean; // value can be null
        }
        return realValue;

    } catch (NoSuchMethodException ex) {
        throw new JspException("Error - component.PutAttributeTag : Error while retrieving value from bean '"
                + beanName + "' with property '" + beanProperty + "' in scope '" + beanScope
                + "'. (exception : " + ex.getMessage());

    } catch (InvocationTargetException ex) {
        throw new JspException("Error - component.PutAttributeTag : Error while retrieving value from bean '"
                + beanName + "' with property '" + beanProperty + "' in scope '" + beanScope
                + "'. (exception : " + ex.getMessage());

    } catch (IllegalAccessException ex) {
        throw new JspException("Error - component.PutAttributeTag : Error while retrieving value from bean '"
                + beanName + "' with property '" + beanProperty + "' in scope '" + beanScope
                + "'. (exception : " + ex.getMessage());
    }
}

From source file:org.apache.struts.tiles.taglib.util.TagUtils.java

/**
 * Locate and return the specified property of the specified bean, from
 * an optionally specified scope, in the specified page context.
 *
 * @param pageContext Page context to be searched.
 * @param beanName Name of the bean to be retrieved.
 * @param beanProperty Name of the property to be retrieved, or
 *  <code>null</code> to retrieve the bean itself.
 * @param beanScope Scope to be searched (page, request, session, application)
 *  or <code>null</code> to use <code>findAttribute()</code> instead.
 *
 * @exception JspException Scope name is not recognized as a valid scope
 * @exception JspException if the specified bean is not found
 * @exception JspException if accessing this property causes an
 *  IllegalAccessException, IllegalArgumentException,
 *  InvocationTargetException, or NoSuchMethodException
 *///from   w  w w.j a va2s.c om
public static Object getRealValueFromBean(String beanName, String beanProperty, String beanScope,
        PageContext pageContext) throws JspException {

    try {
        Object realValue;
        Object bean = retrieveBean(beanName, beanScope, pageContext);
        if (bean != null && beanProperty != null) {
            realValue = PropertyUtils.getProperty(bean, beanProperty);
        } else {
            realValue = bean; // value can be null
        }
        return realValue;

    } catch (NoSuchMethodException ex) {
        throw new JspException("Error - component.PutAttributeTag : Error while retrieving value from bean '"
                + beanName + "' with property '" + beanProperty + "' in scope '" + beanScope
                + "'. (exception : " + ex.getMessage(), ex);

    } catch (InvocationTargetException ex) {
        throw new JspException("Error - component.PutAttributeTag : Error while retrieving value from bean '"
                + beanName + "' with property '" + beanProperty + "' in scope '" + beanScope
                + "'. (exception : " + ex.getMessage(), ex);

    } catch (IllegalAccessException ex) {
        throw new JspException("Error - component.PutAttributeTag : Error while retrieving value from bean '"
                + beanName + "' with property '" + beanProperty + "' in scope '" + beanScope
                + "'. (exception : " + ex.getMessage(), ex);
    }
}

From source file:org.apache98.hadoop.hbase.HBaseConfiguration.java

/**
 * Get the password from the Configuration instance using the
 * getPassword method if it exists. If not, then fall back to the
 * general get method for configuration elements.
 * //from  www . j  a  v  a  2 s .  c o m
 * @param conf
 *            configuration instance for accessing the passwords
 * @param alias
 *            the name of the password element
 * @param defPass
 *            the default password
 * @return String password or default password
 * @throws IOException
 */
public static String getPassword(Configuration conf, String alias, String defPass) throws IOException {
    String passwd = null;
    try {
        Method m = Configuration.class.getMethod("getPassword", String.class);
        char[] p = (char[]) m.invoke(conf, alias);
        if (p != null) {
            LOG.debug(String.format(
                    "Config option \"%s\" was found through" + " the Configuration getPassword method.",
                    alias));
            passwd = new String(p);
        } else {
            LOG.debug(String.format("Config option \"%s\" was not found. Using provided default value", alias));
            passwd = defPass;
        }
    } catch (NoSuchMethodException e) {
        // this is a version of Hadoop where the credential
        // provider API doesn't exist yet
        LOG.debug(String
                .format("Credential.getPassword method is not available." + " Falling back to configuration."));
        passwd = conf.get(alias, defPass);
    } catch (SecurityException e) {
        throw new IOException(e.getMessage(), e);
    } catch (IllegalAccessException e) {
        throw new IOException(e.getMessage(), e);
    } catch (IllegalArgumentException e) {
        throw new IOException(e.getMessage(), e);
    } catch (InvocationTargetException e) {
        throw new IOException(e.getMessage(), e);
    }
    return passwd;
}