Search in sources :

Example 1 with GenericSignatureFormatError

use of java.lang.reflect.GenericSignatureFormatError in project leopard by tanhaichao.

the class ErrorUtil method parseMessage.

/**
 * 获取异常信息.
 *
 * @param e
 * @return
 */
public static String parseMessage(Throwable e) {
    if (e == null) {
        throw new IllegalArgumentException("exception不能为空?");
    }
    String className = e.getClass().getName();
    String message = MESSAGE_MAP.get(className);
    if (message != null) {
        return message;
    }
    if (e instanceof GenericSignatureFormatError) {
        printStartupTime();
        return "更新程序后,还没有重启服务.";
    }
    if (e instanceof NoSuchMethodError) {
        printStartupTime();
        return "NoSuchMethodError:方法找不到.";
    }
    if (e instanceof SQLException) {
        return "操作数据库出错,请稍后重试.";
    }
    if (e instanceof DataIntegrityViolationException) {
        Exception exception = (Exception) e.getCause();
        if (exception instanceof MysqlDataTruncation) {
            return MessageParserImpl.parse((MysqlDataTruncation) exception);
        } else {
            return "操作数据库出错,请稍后重试.";
        }
    // try {
    // return parseDataIntegrityViolationException((DataIntegrityViolationException) e);
    // }
    // catch (Exception e1) {
    // e1.printStackTrace();
    // return "字段太长,请稍后重试.";
    // }
    }
    message = e.getMessage();
    if (message == null) {
        return null;
    }
    return fillterDebugInfo(message);
}
Also used : GenericSignatureFormatError(java.lang.reflect.GenericSignatureFormatError) MysqlDataTruncation(com.mysql.jdbc.MysqlDataTruncation) SQLException(java.sql.SQLException) SQLException(java.sql.SQLException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Example 2 with GenericSignatureFormatError

use of java.lang.reflect.GenericSignatureFormatError in project pentaho-platform by pentaho.

the class PojoComponent method callMethods.

protected void callMethods(List<Method> methods, Object value) throws Throwable {
    if (value instanceof String) {
        callMethodWithString(methods, value.toString());
        return;
    }
    boolean done = false;
    for (Method method : methods) {
        Class<?>[] paramClasses = method.getParameterTypes();
        if (paramClasses.length != 1) {
            // we don't know how to handle this
            throw new GenericSignatureFormatError();
        }
        Class<?> paramclass = paramClasses[0];
        // do some type safety. this would be the point to do automatic type conversions
        if (value instanceof IPentahoResultSet && paramclass.equals(IPentahoResultSet.class)) {
            done = true;
            method.invoke(pojo, new Object[] { (IPentahoResultSet) value });
            break;
        } else if (value instanceof java.lang.Boolean && (paramclass.equals(Boolean.class) || paramclass.equals(boolean.class))) {
            done = true;
            method.invoke(pojo, new Object[] { value });
            break;
        } else if (value instanceof java.lang.Integer && (paramclass.equals(Integer.class) || paramclass.equals(int.class))) {
            done = true;
            method.invoke(pojo, new Object[] { value });
            break;
        } else if (value instanceof java.lang.Long && (paramclass.equals(Long.class) || paramclass.equals(long.class))) {
            done = true;
            method.invoke(pojo, new Object[] { value });
            break;
        } else if (value instanceof java.lang.Double && (paramclass.equals(Double.class) || paramclass.equals(double.class))) {
            done = true;
            method.invoke(pojo, new Object[] { value });
            break;
        } else if (value instanceof java.lang.Float && (paramclass.equals(Float.class) || paramclass.equals(float.class))) {
            done = true;
            method.invoke(pojo, new Object[] { value });
            break;
        } else if (value instanceof IPentahoStreamSource && paramclass.equals(IPentahoStreamSource.class)) {
            done = true;
            method.invoke(pojo, new Object[] { value });
            break;
        } else if (value instanceof Date && paramclass.equals(Date.class)) {
            done = true;
            method.invoke(pojo, new Object[] { value });
            break;
        } else if (value instanceof BigDecimal && paramclass.equals(BigDecimal.class)) {
            done = true;
            method.invoke(pojo, new Object[] { value });
            break;
        } else if (value instanceof IContentItem && paramclass.equals(IContentItem.class)) {
            done = true;
            method.invoke(pojo, new Object[] { value });
            break;
        } else if (value instanceof IContentItem && paramclass.equals(String.class)) {
            done = true;
            method.invoke(pojo, new Object[] { value.toString() });
            break;
        } else if (paramclass.equals(IPentahoSession.class)) {
            done = true;
            method.invoke(pojo, new Object[] { (IPentahoSession) value });
            break;
        } else if (paramclass.equals(Log.class)) {
            done = true;
            method.invoke(pojo, new Object[] { (Log) value });
            break;
        }
    }
    if (!done) {
        // Try invoking the first instance with what we have
        try {
            methods.get(0).invoke(pojo, new Object[] { value });
        } catch (Exception ex) {
            throw new IllegalArgumentException(// $NON-NLS-1$ //$NON-NLS-2$
            "No implementation of method \"" + Method.class.getName() + "\" takes a " + value.getClass());
        }
    }
}
Also used : IPentahoStreamSource(org.pentaho.commons.connection.IPentahoStreamSource) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Method(java.lang.reflect.Method) Date(java.util.Date) BigDecimal(java.math.BigDecimal) PluginBeanException(org.pentaho.platform.api.engine.PluginBeanException) GenericSignatureFormatError(java.lang.reflect.GenericSignatureFormatError) IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) IContentItem(org.pentaho.platform.api.repository.IContentItem)

Example 3 with GenericSignatureFormatError

use of java.lang.reflect.GenericSignatureFormatError in project pentaho-platform by pentaho.

the class PojoComponent method callMethodWithString.

protected void callMethodWithString(List<Method> methodList, String value) throws Throwable {
    boolean done = false;
    value = applyInputsToFormat(value);
    // that takes a single string
    for (Method method : methodList) {
        Class<?>[] paramClasses = method.getParameterTypes();
        if (paramClasses.length != 1) {
            // we don't know how to handle this
            throw new GenericSignatureFormatError();
        }
        Class<?> paramclass = paramClasses[0];
        if (paramclass.equals(String.class)) {
            done = true;
            method.invoke(pojo, new Object[] { value });
            break;
        }
    }
    if (!done) {
        for (Method method : methodList) {
            Class<?>[] paramClasses = method.getParameterTypes();
            if (paramClasses.length != 1) {
                // we don't know how to handle this
                throw new GenericSignatureFormatError();
            }
            Class<?> paramclass = paramClasses[0];
            if (paramclass.equals(Boolean.class) || paramclass.equals(boolean.class)) {
                done = true;
                method.invoke(pojo, new Object[] { new Boolean(value) });
                break;
            } else if (paramclass.equals(Integer.class) || paramclass.equals(int.class)) {
                done = true;
                method.invoke(pojo, new Object[] { new Integer(value) });
                break;
            } else if (paramclass.equals(Long.class) || paramclass.equals(long.class)) {
                done = true;
                method.invoke(pojo, new Object[] { new Long(value) });
                break;
            } else if (paramclass.equals(Double.class) || paramclass.equals(double.class)) {
                done = true;
                method.invoke(pojo, new Object[] { new Double(value) });
                break;
            } else if (paramclass.equals(Float.class) || paramclass.equals(float.class)) {
                done = true;
                method.invoke(pojo, new Object[] { new Float(value) });
                break;
            } else if (paramclass.equals(BigDecimal.class)) {
                done = true;
                method.invoke(pojo, new Object[] { new BigDecimal(value) });
                break;
            }
        }
    }
    if (!done) {
        throw new GenericSignatureFormatError();
    }
}
Also used : Method(java.lang.reflect.Method) BigDecimal(java.math.BigDecimal) GenericSignatureFormatError(java.lang.reflect.GenericSignatureFormatError)

Aggregations

GenericSignatureFormatError (java.lang.reflect.GenericSignatureFormatError)3 Method (java.lang.reflect.Method)2 BigDecimal (java.math.BigDecimal)2 MysqlDataTruncation (com.mysql.jdbc.MysqlDataTruncation)1 SQLException (java.sql.SQLException)1 Date (java.util.Date)1 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)1 IPentahoStreamSource (org.pentaho.commons.connection.IPentahoStreamSource)1 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)1 PluginBeanException (org.pentaho.platform.api.engine.PluginBeanException)1 IContentItem (org.pentaho.platform.api.repository.IContentItem)1 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)1