Example usage for java.lang.reflect GenericSignatureFormatError GenericSignatureFormatError

List of usage examples for java.lang.reflect GenericSignatureFormatError GenericSignatureFormatError

Introduction

In this page you can find the example usage for java.lang.reflect GenericSignatureFormatError GenericSignatureFormatError.

Prototype

public GenericSignatureFormatError() 

Source Link

Document

Constructs a new GenericSignatureFormatError .

Usage

From source file:org.pentaho.platform.engine.services.solution.PojoComponent.java

protected void callMethods(List<Method> methods, Object value) throws Throwable {
    if (value instanceof String) {
        callMethodWithString(methods, value.toString());
        return;/*w w  w.j  ava2 s. c om*/
    }

    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("No implementation of method \"" + Method.class.getName() //$NON-NLS-1$
                    + "\" takes a " + value.getClass()); //$NON-NLS-1$
        }
    }
}

From source file:org.pentaho.platform.engine.services.solution.PojoComponent.java

protected void callMethodWithString(List<Method> methodList, String value) throws Throwable {
    boolean done = false;

    value = applyInputsToFormat(value);//from  w w w .jav a  2 s  .  c o  m

    // Search ALL instances of a given method for an implementation
    // 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();
    }
}