Example usage for java.lang NoSuchMethodException getCause

List of usage examples for java.lang NoSuchMethodException getCause

Introduction

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

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:Main.java

public static Object clone(final Object obj) throws CloneNotSupportedException {
    if (obj == null) {
        return null;
    }/*from  w w  w.ja  v a2s . c  o 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 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:com.xpfriend.fixture.cast.temp.PojoUtil.java

public static Object getPropertyValue(Object object, String propertyName, Table table, Row row) {
    try {//from w  ww  .  j  a  v a  2 s  .  c o m
        String name = find(propertyName, object);
        return TypeConverter.getBeanUtils().getPropertyUtils().getProperty(object, name);
    } catch (NoSuchMethodException e) {
        throw createNoSuchPropertyException(object, propertyName, table, row);
    } catch (InvocationTargetException e) {
        throw new ConfigException(e.getCause());
    } catch (IllegalAccessException e) {
        throw new ConfigException(e);
    }
}

From source file:com.xpfriend.fixture.cast.temp.PojoUtil.java

public static Class<?> getPropertyType(Object object, String propertyName, Table table, Row row) {
    try {//  w w w  . ja va  2s. c o m
        String name = find(propertyName, object);
        PropertyUtilsBean propertyUtils = TypeConverter.getBeanUtils().getPropertyUtils();
        if (object instanceof DynaBean) {
            return ((DynaBean) object).getDynaClass().getDynaProperty(name).getType();
        }
        Class<?> type = propertyUtils.getPropertyType(object, name);
        if (type == null) {
            throw createNoSuchPropertyException(object, name, table, row);
        }
        return type;
    } catch (NoSuchMethodException e) {
        throw createNoSuchPropertyException(object, propertyName, table, row);
    } catch (InvocationTargetException e) {
        throw new ConfigException(e.getCause());
    } catch (IllegalAccessException e) {
        throw new ConfigException(e);
    }
}

From source file:com.xpfriend.fixture.cast.temp.PojoUtil.java

public static Class<?> getPropertyComponentType(Object object, Column column, Table table, Row row) {
    String propertyName = column.getName();
    try {/*from www  .  ja v a 2s  . c  o m*/
        String name = find(propertyName, object);
        PropertyDescriptor descriptor = TypeConverter.getBeanUtils().getPropertyUtils()
                .getPropertyDescriptor(object, name);
        Method method = descriptor.getWriteMethod();
        Type genericType = method.getGenericParameterTypes()[0];
        if (genericType != null) {
            if (genericType instanceof Class) {
                genericType = ((Class<?>) genericType).getGenericSuperclass();
            }
            if (genericType instanceof ParameterizedType) {
                Type[] es = ((ParameterizedType) genericType).getActualTypeArguments();
                if (es != null && es.length > 0 && es[0] instanceof Class) {
                    return (Class<?>) es[0];
                }
            }
        }
        return String.class;
    } catch (NoSuchMethodException e) {
        throw createNoSuchPropertyException(object, propertyName, table, row);
    } catch (InvocationTargetException e) {
        throw new ConfigException(e.getCause());
    } catch (IllegalAccessException e) {
        throw new ConfigException(e);
    }
}

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/*from   w w w.j a  va 2  s .c  om*/
 */
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:org.apache.ibatis.cache.TransactionalCacheManager.java

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

From source file:Main.java

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

From source file:Main.java

/**
 * @since 4.3//  w ww. j av  a  2 s  . c  o  m
 */
public static <T> T cloneObject(final T obj) throws CloneNotSupportedException {
    if (obj == null) {
        return null;
    }
    if (obj instanceof Cloneable) {
        final Class<?> clazz = obj.getClass();
        final Method m;
        try {
            m = clazz.getMethod("clone", (Class<?>[]) null);
        } catch (final NoSuchMethodException ex) {
            throw new NoSuchMethodError(ex.getMessage());
        }
        try {
            @SuppressWarnings("unchecked")
            // OK because clone() preserves the class
            final T result = (T) m.invoke(obj, (Object[]) null);
            return result;
        } catch (final InvocationTargetException ex) {
            final Throwable cause = ex.getCause();
            if (cause instanceof CloneNotSupportedException) {
                throw ((CloneNotSupportedException) cause);
            } else {
                throw new Error("Unexpected exception", cause);
            }
        } catch (final IllegalAccessException ex) {
            throw new IllegalAccessError(ex.getMessage());
        }
    } else {
        throw new CloneNotSupportedException();
    }
}

From source file:de.micromata.genome.gwiki.utils.ClassUtils.java

@SuppressWarnings("unchecked")
public static <T> T invokeDefaultStaticMethod(Class<T> expectedClass, String className, String methodName) {
    Class<?> cls = classForName(className);
    try {//w ww  .  ja  v  a  2 s. co  m
        Method m = cls.getMethod(methodName, new Class[] {});
        T t = (T) m.invoke(null, new Object[] {});
        if (t == null) {
            return t;
        }
        if (expectedClass.isAssignableFrom(t.getClass()) == false) {
            throw new RuntimeException("method: " + methodName + " from class: " + className
                    + " does not return correct class type: " + expectedClass + " but: " + t.getClass());
        }
        return t;
    } catch (NoSuchMethodException ex) {
        throw new RuntimeException("Cannot find method: " + methodName + " in class: " + className);
    } catch (IllegalArgumentException ex) {
        throw new RuntimeException(ex);
    } catch (IllegalAccessException ex) {
        throw new RuntimeException(ex);
    } catch (InvocationTargetException ex) {
        Throwable nex = ex.getCause();
        if (nex instanceof RuntimeException) {
            throw (RuntimeException) nex;
        }
        throw new RuntimeException(ex);
    }
}

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.  ja  v a2s  . 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();
    }
}