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.rockagen.commons.util.ClassUtil.java

/**
 * obtain constructor list of specified class If recursively is true, obtain
 * constructor from all class hierarchy/*from w w w  .jav  a 2 s .  c  o m*/
 * 
 * 
 * @param clazz class
 *            where fields are searching
 * @param recursively
 *            param
 * @param parameterTypes parameter types
 * @return constructor
 */
public static Constructor<?> getDeclaredConstructor(Class<?> clazz, boolean recursively,
        Class<?>... parameterTypes) {

    try {
        return clazz.getDeclaredConstructor(parameterTypes);
    } catch (NoSuchMethodException e) {
        Class<?> superClass = clazz.getSuperclass();
        if (superClass != null && recursively) {
            return getDeclaredConstructor(superClass, true, parameterTypes);
        }
    } catch (SecurityException e) {
        log.error("{}", e.getMessage(), e);
    }
    return null;
}

From source file:com.rockagen.commons.util.ClassUtil.java

/**
 * obtain method list of specified class If recursively is true, obtain
 * method from all class hierarchy//w w  w . j ava2 s .  c  om
 * 
 * @param clazz class
 * @param recursively recursively
 * @param methodName method name
 * @param parameterTypes parameter types
 * @return method
 */
public static Method getDeclaredMethod(Class<?> clazz, boolean recursively, String methodName,
        Class<?>... parameterTypes) {

    try {
        return clazz.getDeclaredMethod(methodName, parameterTypes);
    } catch (NoSuchMethodException e) {
        Class<?> superClass = clazz.getSuperclass();
        if (superClass != null && recursively) {
            return getDeclaredMethod(superClass, true, methodName, parameterTypes);
        }
    } catch (SecurityException e) {
        log.error("{}", e.getMessage(), e);
    }
    return null;
}

From source file:org.jaffa.util.BeanHelper.java

/** This will inspect the specified java bean, and extract an Object from the beans
 * getXxx() method, where 'xxx' is the field name passed in.
 * A null will be returned in case there is any error in invoking the getter.
 * @param bean The Java Bean.// w w  w  .  j  ava 2 s  . c  o  m
 * @param field The field.
 * @throws NoSuchMethodException if there is no getter for the input field.
 * @return the output of the getter for the field.
 */
public static Object getField(Object bean, String field) throws NoSuchMethodException {
    java.lang.reflect.Method method = null;
    try {
        if (bean instanceof DynaBean) {
            try {
                return PropertyUtils.getProperty(bean, field);
            } catch (NoSuchMethodException e) {
                // If the bean is a FlexBean instance, then the field could exist on the associated persistentObject
                if (bean instanceof FlexBean && ((FlexBean) bean).getPersistentObject() != null)
                    return PropertyUtils.getProperty(((FlexBean) bean).getPersistentObject(), field);
                else
                    throw e;
            }
        } else {
            // Get the Java Bean Info
            java.beans.BeanInfo info = java.beans.Introspector.getBeanInfo(bean.getClass());
            if (info != null) {
                // Get all the properties
                java.beans.PropertyDescriptor[] pds = info.getPropertyDescriptors();
                if (pds != null) {
                    // Loop for a matching method
                    for (PropertyDescriptor pd : pds) {
                        if (StringHelper.equalsIgnoreCaseFirstChar(pd.getName(), field)) {
                            // Match found....
                            method = pd.getReadMethod();
                            break;
                        }
                    }
                }
            }
            if (method != null) {
                return method.invoke(bean, new Object[] {});
            }

            // Finally, check the FlexBean
            if (bean instanceof IFlexFields) {
                FlexBean flexBean = ((IFlexFields) bean).getFlexBean();
                if (flexBean != null && flexBean.get(field) != null) {
                    return flexBean.get(field);
                } else {
                    throw new NoSuchMethodException();
                }
            }
        }
    } catch (NoSuchMethodException ex) {
        throw ex;
    } catch (Exception ex) {
        log.error("Introspection of Property " + field + " on Bean " + bean + " failed. Reason : "
                + ex.getMessage(), ex);
        return null;
    }

    // If we reach here, the method was not found
    throw new NoSuchMethodException("Field Name = " + field);
}

From source file:BrowserLauncher.java

/**
 * Called by a static initializer to load any classes, fields, and methods required at runtime
 * to locate the user's web browser.//w w  w . j av a 2s. c  o  m
 * @return <code>true</code> if all intialization succeeded
 *         <code>false</code> if any portion of the initialization failed
 */
private static boolean loadClasses() {
    switch (jvm) {
    case MRJ_2_0:
        try {
            Class aeTargetClass = Class.forName("com.apple.MacOS.AETarget");
            Class osUtilsClass = Class.forName("com.apple.MacOS.OSUtils");
            Class appleEventClass = Class.forName("com.apple.MacOS.AppleEvent");
            Class aeClass = Class.forName("com.apple.MacOS.ae");
            aeDescClass = Class.forName("com.apple.MacOS.AEDesc");

            aeTargetConstructor = aeTargetClass.getDeclaredConstructor(new Class[] { int.class });
            appleEventConstructor = appleEventClass.getDeclaredConstructor(
                    new Class[] { int.class, int.class, aeTargetClass, int.class, int.class });
            aeDescConstructor = aeDescClass.getDeclaredConstructor(new Class[] { String.class });

            makeOSType = osUtilsClass.getDeclaredMethod("makeOSType", new Class[] { String.class });
            putParameter = appleEventClass.getDeclaredMethod("putParameter",
                    new Class[] { int.class, aeDescClass });
            sendNoReply = appleEventClass.getDeclaredMethod("sendNoReply", new Class[] {});

            Field keyDirectObjectField = aeClass.getDeclaredField("keyDirectObject");
            keyDirectObject = (Integer) keyDirectObjectField.get(null);
            Field autoGenerateReturnIDField = appleEventClass.getDeclaredField("kAutoGenerateReturnID");
            kAutoGenerateReturnID = (Integer) autoGenerateReturnIDField.get(null);
            Field anyTransactionIDField = appleEventClass.getDeclaredField("kAnyTransactionID");
            kAnyTransactionID = (Integer) anyTransactionIDField.get(null);
        } catch (ClassNotFoundException cnfe) {
            errorMessage = cnfe.getMessage();
            return false;
        } catch (NoSuchMethodException nsme) {
            errorMessage = nsme.getMessage();
            return false;
        } catch (NoSuchFieldException nsfe) {
            errorMessage = nsfe.getMessage();
            return false;
        } catch (IllegalAccessException iae) {
            errorMessage = iae.getMessage();
            return false;
        }
        break;
    case MRJ_2_1:
        try {
            mrjFileUtilsClass = Class.forName("com.apple.mrj.MRJFileUtils");
            mrjOSTypeClass = Class.forName("com.apple.mrj.MRJOSType");
            Field systemFolderField = mrjFileUtilsClass.getDeclaredField("kSystemFolderType");
            kSystemFolderType = systemFolderField.get(null);
            findFolder = mrjFileUtilsClass.getDeclaredMethod("findFolder", new Class[] { mrjOSTypeClass });
            getFileCreator = mrjFileUtilsClass.getDeclaredMethod("getFileCreator", new Class[] { File.class });
            getFileType = mrjFileUtilsClass.getDeclaredMethod("getFileType", new Class[] { File.class });
        } catch (ClassNotFoundException cnfe) {
            errorMessage = cnfe.getMessage();
            return false;
        } catch (NoSuchFieldException nsfe) {
            errorMessage = nsfe.getMessage();
            return false;
        } catch (NoSuchMethodException nsme) {
            errorMessage = nsme.getMessage();
            return false;
        } catch (SecurityException se) {
            errorMessage = se.getMessage();
            return false;
        } catch (IllegalAccessException iae) {
            errorMessage = iae.getMessage();
            return false;
        }
        break;
    case MRJ_3_0:
        try {
            Class linker = Class.forName("com.apple.mrj.jdirect.Linker");
            Constructor constructor = linker.getConstructor(new Class[] { Class.class });
            linkage = constructor.newInstance(new Object[] { BrowserLauncher.class });
        } catch (ClassNotFoundException cnfe) {
            errorMessage = cnfe.getMessage();
            return false;
        } catch (NoSuchMethodException nsme) {
            errorMessage = nsme.getMessage();
            return false;
        } catch (InvocationTargetException ite) {
            errorMessage = ite.getMessage();
            return false;
        } catch (InstantiationException ie) {
            errorMessage = ie.getMessage();
            return false;
        } catch (IllegalAccessException iae) {
            errorMessage = iae.getMessage();
            return false;
        }
        break;
    case MRJ_3_1:
        try {
            mrjFileUtilsClass = Class.forName("com.apple.mrj.MRJFileUtils");
            openURL = mrjFileUtilsClass.getDeclaredMethod("openURL", new Class[] { String.class });
        } catch (ClassNotFoundException cnfe) {
            errorMessage = cnfe.getMessage();
            return false;
        } catch (NoSuchMethodException nsme) {
            errorMessage = nsme.getMessage();
            return false;
        }
        break;
    default:
        break;
    }
    return true;
}

From source file:org.artifactory.maven.MavenMetadataCalculator.java

public static SnapshotComparator createSnapshotComparator() {
    SnapshotComparator comparator = BuildNumberSnapshotComparator.get();
    // Try to load costume comparator
    String comparatorFqn = ConstantValues.mvnMetadataSnapshotComparator.getString();
    if (!StringUtils.isBlank(comparatorFqn)) {
        try {/*w ww. j  av a 2  s .  co  m*/
            Class comparatorClass = Class.forName(comparatorFqn);
            Method get = comparatorClass.getMethod("get");
            comparator = (SnapshotComparator) get.invoke(null);
            log.debug("Using costume snapshot comparator '{}' to calculate the latest snapshot", comparatorFqn);
        } catch (NoSuchMethodException e1) {
            log.warn(
                    "Failed to create custom maven metadata snapshot comparator, the comparator should contain"
                            + " static get method to avoid unnecessary object creation '{}': {}",
                    comparatorFqn, e1.getMessage());
        } catch (Exception e) {
            log.warn("Failed to create custom maven metadata snapshot comparator '{}': {}", comparatorFqn,
                    e.getMessage());
        }
    }
    return comparator;
}

From source file:Browser.java

/**
 * Called by a static initializer to load any classes, fields, and methods 
 * required at runtime to locate the user's web browser.
 * @return <code>true</code> if all intialization succeeded
 *         <code>false</code> if any portion of the initialization failed
 *//*ww  w.jav  a2s  .  c om*/
private static boolean loadClasses() {
    switch (jvm) {
    case MRJ_2_0:
        try {
            Class aeTargetClass = Class.forName("com.apple.MacOS.AETarget");
            Class osUtilsClass = Class.forName("com.apple.MacOS.OSUtils");
            Class appleEventClass = Class.forName("com.apple.MacOS.AppleEvent");
            Class aeClass = Class.forName("com.apple.MacOS.ae");
            aeDescClass = Class.forName("com.apple.MacOS.AEDesc");

            aeTargetConstructor = aeTargetClass.getDeclaredConstructor(new Class[] { int.class });
            appleEventConstructor = appleEventClass.getDeclaredConstructor(
                    new Class[] { int.class, int.class, aeTargetClass, int.class, int.class });
            aeDescConstructor = aeDescClass.getDeclaredConstructor(new Class[] { String.class });

            makeOSType = osUtilsClass.getDeclaredMethod("makeOSType", new Class[] { String.class });
            putParameter = appleEventClass.getDeclaredMethod("putParameter",
                    new Class[] { int.class, aeDescClass });
            sendNoReply = appleEventClass.getDeclaredMethod("sendNoReply", new Class[] {});

            Field keyDirectObjectField = aeClass.getDeclaredField("keyDirectObject");
            keyDirectObject = (Integer) keyDirectObjectField.get(null);
            Field autoGenerateReturnIDField = appleEventClass.getDeclaredField("kAutoGenerateReturnID");
            kAutoGenerateReturnID = (Integer) autoGenerateReturnIDField.get(null);
            Field anyTransactionIDField = appleEventClass.getDeclaredField("kAnyTransactionID");
            kAnyTransactionID = (Integer) anyTransactionIDField.get(null);
        } catch (ClassNotFoundException cnfe) {
            errorMessage = cnfe.getMessage();
            return false;
        } catch (NoSuchMethodException nsme) {
            errorMessage = nsme.getMessage();
            return false;
        } catch (NoSuchFieldException nsfe) {
            errorMessage = nsfe.getMessage();
            return false;
        } catch (IllegalAccessException iae) {
            errorMessage = iae.getMessage();
            return false;
        }
        break;

    case MRJ_2_1:
        try {
            mrjFileUtilsClass = Class.forName("com.apple.mrj.MRJFileUtils");
            mrjOSTypeClass = Class.forName("com.apple.mrj.MRJOSType");
            Field systemFolderField = mrjFileUtilsClass.getDeclaredField("kSystemFolderType");
            kSystemFolderType = systemFolderField.get(null);
            findFolder = mrjFileUtilsClass.getDeclaredMethod("findFolder", new Class[] { mrjOSTypeClass });
            getFileCreator = mrjFileUtilsClass.getDeclaredMethod("getFileCreator", new Class[] { File.class });
            getFileType = mrjFileUtilsClass.getDeclaredMethod("getFileType", new Class[] { File.class });
        } catch (ClassNotFoundException cnfe) {
            errorMessage = cnfe.getMessage();
            return false;
        } catch (NoSuchFieldException nsfe) {
            errorMessage = nsfe.getMessage();
            return false;
        } catch (NoSuchMethodException nsme) {
            errorMessage = nsme.getMessage();
            return false;
        } catch (SecurityException se) {
            errorMessage = se.getMessage();
            return false;
        } catch (IllegalAccessException iae) {
            errorMessage = iae.getMessage();
            return false;
        }
        break;

    case MRJ_3_0:
        try {
            Class linker = Class.forName("com.apple.mrj.jdirect.Linker");
            Constructor constructor = linker.getConstructor(new Class[] { Class.class });
            linkage = constructor.newInstance(new Object[] { Browser.class });
        } catch (ClassNotFoundException cnfe) {
            errorMessage = cnfe.getMessage();
            return false;
        } catch (NoSuchMethodException nsme) {
            errorMessage = nsme.getMessage();
            return false;
        } catch (InvocationTargetException ite) {
            errorMessage = ite.getMessage();
            return false;
        } catch (InstantiationException ie) {
            errorMessage = ie.getMessage();
            return false;
        } catch (IllegalAccessException iae) {
            errorMessage = iae.getMessage();
            return false;
        }
        break;

    case MRJ_3_1:
        try {
            mrjFileUtilsClass = Class.forName("com.apple.mrj.MRJFileUtils");
            openURL = mrjFileUtilsClass.getDeclaredMethod("openURL", new Class[] { String.class });
        } catch (ClassNotFoundException cnfe) {
            errorMessage = cnfe.getMessage();
            return false;
        } catch (NoSuchMethodException nsme) {
            errorMessage = nsme.getMessage();
            return false;
        }
        break;

    default:
        break;
    }
    return true;
}

From source file:fxts.stations.util.BrowserLauncher.java

/**
 * Called by a static initializer to load any classes, fields, and methods required at runtime
 * to locate the user's web browser.//from   w w  w .  j  a v a  2s .  co  m
 *
 * @return <code>true</code> if all intialization succeeded
 *         <code>false</code> if any portion of the initialization failed
 */
private static boolean loadClasses() {
    switch (jvm) {
    case MRJ_2_0:
        try {
            Class aeTargetClass = Class.forName("com.apple.MacOS.AETarget");
            Class osUtilsClass = Class.forName("com.apple.MacOS.OSUtils");
            Class appleEventClass = Class.forName("com.apple.MacOS.AppleEvent");
            Class aeClass = Class.forName("com.apple.MacOS.ae");
            aeDescClass = Class.forName("com.apple.MacOS.AEDesc");
            aeTargetConstructor = aeTargetClass.getDeclaredConstructor(new Class[] { int.class });
            appleEventConstructor = appleEventClass.getDeclaredConstructor(
                    new Class[] { int.class, int.class, aeTargetClass, int.class, int.class });
            aeDescConstructor = aeDescClass.getDeclaredConstructor(new Class[] { String.class });
            makeOSType = osUtilsClass.getDeclaredMethod("makeOSType", new Class[] { String.class });
            putParameter = appleEventClass.getDeclaredMethod("putParameter",
                    new Class[] { int.class, aeDescClass });
            sendNoReply = appleEventClass.getDeclaredMethod("sendNoReply", new Class[] {});
            Field keyDirectObjectField = aeClass.getDeclaredField("keyDirectObject");
            keyDirectObject = (Integer) keyDirectObjectField.get(null);
            Field autoGenerateReturnIDField = appleEventClass.getDeclaredField("kAutoGenerateReturnID");
            kAutoGenerateReturnID = (Integer) autoGenerateReturnIDField.get(null);
            Field anyTransactionIDField = appleEventClass.getDeclaredField("kAnyTransactionID");
            kAnyTransactionID = (Integer) anyTransactionIDField.get(null);
        } catch (ClassNotFoundException cnfe) {
            errorMessage = cnfe.getMessage();
            return false;
        } catch (NoSuchMethodException nsme) {
            errorMessage = nsme.getMessage();
            return false;
        } catch (NoSuchFieldException nsfe) {
            errorMessage = nsfe.getMessage();
            return false;
        } catch (IllegalAccessException iae) {
            errorMessage = iae.getMessage();
            return false;
        }
        break;
    case MRJ_2_1:
        try {
            mrjFileUtilsClass = Class.forName("com.apple.mrj.MRJFileUtils");
            mrjOSTypeClass = Class.forName("com.apple.mrj.MRJOSType");
            Field systemFolderField = mrjFileUtilsClass.getDeclaredField("kSystemFolderType");
            kSystemFolderType = systemFolderField.get(null);
            findFolder = mrjFileUtilsClass.getDeclaredMethod("findFolder", new Class[] { mrjOSTypeClass });
            getFileCreator = mrjFileUtilsClass.getDeclaredMethod("getFileCreator", new Class[] { File.class });
            getFileType = mrjFileUtilsClass.getDeclaredMethod("getFileType", new Class[] { File.class });
        } catch (ClassNotFoundException cnfe) {
            errorMessage = cnfe.getMessage();
            return false;
        } catch (NoSuchFieldException nsfe) {
            errorMessage = nsfe.getMessage();
            return false;
        } catch (NoSuchMethodException nsme) {
            errorMessage = nsme.getMessage();
            return false;
        } catch (SecurityException se) {
            errorMessage = se.getMessage();
            return false;
        } catch (IllegalAccessException iae) {
            errorMessage = iae.getMessage();
            return false;
        }
        break;
    case MRJ_3_0:
        try {
            Class linker = Class.forName("com.apple.mrj.jdirect.Linker");
            Constructor constructor = linker.getConstructor(new Class[] { Class.class });
            linkage = constructor.newInstance(new Object[] { BrowserLauncher.class });
        } catch (ClassNotFoundException cnfe) {
            errorMessage = cnfe.getMessage();
            return false;
        } catch (NoSuchMethodException nsme) {
            errorMessage = nsme.getMessage();
            return false;
        } catch (InvocationTargetException ite) {
            errorMessage = ite.getMessage();
            return false;
        } catch (InstantiationException ie) {
            errorMessage = ie.getMessage();
            return false;
        } catch (IllegalAccessException iae) {
            errorMessage = iae.getMessage();
            return false;
        }
        break;
    case MRJ_3_1:
        try {
            mrjFileUtilsClass = Class.forName("com.apple.mrj.MRJFileUtils");
            openURL = mrjFileUtilsClass.getDeclaredMethod("openURL", new Class[] { String.class });
        } catch (ClassNotFoundException cnfe) {
            errorMessage = cnfe.getMessage();
            return false;
        } catch (NoSuchMethodException nsme) {
            errorMessage = nsme.getMessage();
            return false;
        }
        break;
    default:
        break;
    }
    return true;
}

From source file:org.apache.tinkerpop.gremlin.structure.io.util.IoRegistryHelper.java

public static List<IoRegistry> createRegistries(final List<Object> registryNamesClassesOrInstances) {
    if (registryNamesClassesOrInstances.isEmpty())
        return Collections.emptyList();

    final List<IoRegistry> registries = new ArrayList<>();
    for (final Object object : registryNamesClassesOrInstances) {
        if (object instanceof IoRegistry)
            registries.add((IoRegistry) object);
        else if (object instanceof String || object instanceof Class) {
            try {
                final Class<?> clazz = object instanceof String ? Class.forName((String) object)
                        : (Class) object;
                Method instanceMethod = null;
                try {
                    instanceMethod = clazz.getDeclaredMethod("instance"); // try for getInstance() ??
                } catch (final NoSuchMethodException e) {
                    try {
                        instanceMethod = clazz.getDeclaredMethod("getInstance"); // try for getInstance() ??
                    } catch (final NoSuchMethodException e2) {
                        // no instance() or getInstance() methods
                    }//from   w  w w  .  j a v a  2 s  . c  om
                }
                if (null != instanceMethod && IoRegistry.class.isAssignableFrom(instanceMethod.getReturnType()))
                    registries.add((IoRegistry) instanceMethod.invoke(null));
                else
                    registries.add((IoRegistry) clazz.newInstance()); // no instance() or getInstance() methods, try instantiate class
            } catch (final Exception e) {
                throw new IllegalStateException(e.getMessage(), e);
            }
        } else {
            throw new IllegalArgumentException(
                    "The provided registry object can not be resolved to an instance: " + object);
        }
    }
    return registries;
}

From source file:org.apache.cassandra.io.compress.CompressionParameters.java

private static ICompressor createCompressor(Class<?> compressorClass, Map<String, String> compressionOptions)
        throws ConfigurationException {
    if (compressorClass == null) {
        if (!compressionOptions.isEmpty())
            throw new ConfigurationException("Unknown compression options (" + compressionOptions.keySet()
                    + ") since no compression class found");
        return null;
    }//from  w  w  w  . j  a v a2 s.c om

    try {
        Method method = compressorClass.getMethod("create", Map.class);
        ICompressor compressor = (ICompressor) method.invoke(null, compressionOptions);
        // Check for unknown options
        AbstractSet<String> supportedOpts = Sets.union(compressor.supportedOptions(), GLOBAL_OPTIONS);
        for (String provided : compressionOptions.keySet())
            if (!supportedOpts.contains(provided))
                throw new ConfigurationException("Unknown compression options " + provided);
        return compressor;
    } catch (NoSuchMethodException e) {
        throw new ConfigurationException("create method not found", e);
    } catch (SecurityException e) {
        throw new ConfigurationException("Access forbiden", e);
    } catch (IllegalAccessException e) {
        throw new ConfigurationException("Cannot access method create in " + compressorClass.getName(), e);
    } catch (InvocationTargetException e) {
        Throwable cause = e.getCause();
        throw new ConfigurationException(String.format("%s.create() threw an error: %s",
                compressorClass.getSimpleName(), cause == null ? e.getClass().getName() + " " + e.getMessage()
                        : cause.getClass().getName() + " " + cause.getMessage()),
                e);
    } catch (ExceptionInInitializerError e) {
        throw new ConfigurationException("Cannot initialize class " + compressorClass.getName());
    }
}

From source file:nl.nn.adapterframework.util.Misc.java

public static String getFileSystemTotalSpace() {
    try {//from  w w w .  j  a  v  a 2 s  .c  om
        Method getTotalSpace = File.class.getMethod("getTotalSpace", (java.lang.Class[]) null);
        String dirName = System.getProperty("APPSERVER_ROOT_DIR");
        if (dirName == null) {
            dirName = System.getProperty("user.dir");
            if (dirName == null) {
                return null;
            }
        }
        File file = new File(dirName);
        long l = ((Long) getTotalSpace.invoke(file, (java.lang.Object[]) null)).longValue();
        return toFileSize(l);
    } catch (NoSuchMethodException e) {
        log.debug("Caught NoSuchMethodException, just not on JDK 1.6: " + e.getMessage());
        return null;
    } catch (Exception e) {
        log.debug("Caught Exception", e);
        return null;
    }
}