Java Code Examples for org.codehaus.groovy.runtime.InvokerInvocationException#getCause()

The following examples show how to use org.codehaus.groovy.runtime.InvokerInvocationException#getCause() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractTask.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void execute(Task task) {
    closure.setDelegate(task);
    closure.setResolveStrategy(Closure.DELEGATE_FIRST);
    ClassLoader original = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(closure.getClass().getClassLoader());
    try {
        if (closure.getMaximumNumberOfParameters() == 0) {
            closure.call();
        } else {
            closure.call(task);
        }
    } catch (InvokerInvocationException e) {
        Throwable cause = e.getCause();
        if (cause instanceof RuntimeException) {
            throw (RuntimeException) cause;
        }
        throw e;
    } finally {
        Thread.currentThread().setContextClassLoader(original);
    }
}
 
Example 2
Source File: BeanDynamicObject.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Object getProperty(String name) throws MissingPropertyException {
    if (!includeProperties) {
        throw propertyMissingException(name);
    }

    MetaProperty property = getMetaClass().hasProperty(bean, name);
    if (property == null) {
        return getMetaClass().invokeMissingProperty(bean, name, null, true);
    }
    if (property instanceof MetaBeanProperty && ((MetaBeanProperty) property).getGetter() == null) {
        throw new GroovyRuntimeException(String.format(
                "Cannot get the value of write-only property '%s' on %s.", name, getDisplayName()));
    }

    try {
        return property.getProperty(bean);
    } catch (InvokerInvocationException e) {
        if (e.getCause() instanceof RuntimeException) {
            throw (RuntimeException) e.getCause();
        }
        throw e;
    }
}
 
Example 3
Source File: BeanDynamicObject.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Object getProperty(String name) throws MissingPropertyException {
    if (!includeProperties) {
        throw propertyMissingException(name);
    }

    MetaProperty property = getMetaClass().hasProperty(bean, name);
    if (property == null) {
        return getMetaClass().invokeMissingProperty(bean, name, null, true);
    }
    if (property instanceof MetaBeanProperty && ((MetaBeanProperty) property).getGetter() == null) {
        throw new GroovyRuntimeException(String.format(
                "Cannot get the value of write-only property '%s' on %s.", name, getDisplayName()));
    }

    try {
        return property.getProperty(bean);
    } catch (InvokerInvocationException e) {
        if (e.getCause() instanceof RuntimeException) {
            throw (RuntimeException) e.getCause();
        }
        throw e;
    }
}
 
Example 4
Source File: AbstractTask.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void execute(Task task) {
    closure.setDelegate(task);
    closure.setResolveStrategy(Closure.DELEGATE_FIRST);
    ClassLoader original = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(closure.getClass().getClassLoader());
    try {
        if (closure.getMaximumNumberOfParameters() == 0) {
            closure.call();
        } else {
            closure.call(task);
        }
    } catch (InvokerInvocationException e) {
        Throwable cause = e.getCause();
        if (cause instanceof RuntimeException) {
            throw (RuntimeException) cause;
        }
        throw e;
    } finally {
        Thread.currentThread().setContextClassLoader(original);
    }
}
 
Example 5
Source File: AbstractTask.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void execute(Task task) {
    closure.setDelegate(task);
    closure.setResolveStrategy(Closure.DELEGATE_FIRST);
    ClassLoader original = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(closure.getClass().getClassLoader());
    try {
        if (closure.getMaximumNumberOfParameters() == 0) {
            closure.call();
        } else {
            closure.call(task);
        }
    } catch (InvokerInvocationException e) {
        Throwable cause = e.getCause();
        if (cause instanceof RuntimeException) {
            throw (RuntimeException) cause;
        }
        throw e;
    } finally {
        Thread.currentThread().setContextClassLoader(original);
    }
}
 
Example 6
Source File: AbstractTask.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void execute(Task task) {
    closure.setDelegate(task);
    closure.setResolveStrategy(Closure.DELEGATE_FIRST);
    ClassLoader original = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(closure.getClass().getClassLoader());
    try {
        if (closure.getMaximumNumberOfParameters() == 0) {
            closure.call();
        } else {
            closure.call(task);
        }
    } catch (InvokerInvocationException e) {
        Throwable cause = e.getCause();
        if (cause instanceof RuntimeException) {
            throw (RuntimeException) cause;
        }
        throw e;
    } finally {
        Thread.currentThread().setContextClassLoader(original);
    }
}
 
Example 7
Source File: BeanDynamicObject.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Object getProperty(String name) throws MissingPropertyException {
    if (!includeProperties) {
        throw propertyMissingException(name);
    }

    MetaProperty property = getMetaClass().hasProperty(bean, name);
    if (property == null) {
        return getMetaClass().invokeMissingProperty(bean, name, null, true);
    }
    if (property instanceof MetaBeanProperty && ((MetaBeanProperty) property).getGetter() == null) {
        throw new GroovyRuntimeException(String.format(
                "Cannot get the value of write-only property '%s' on %s.", name, getDisplayName()));
    }

    try {
        return property.getProperty(bean);
    } catch (InvokerInvocationException e) {
        if (e.getCause() instanceof RuntimeException) {
            throw (RuntimeException) e.getCause();
        }
        throw e;
    }
}
 
Example 8
Source File: BeanDynamicObject.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Object getProperty(String name) throws MissingPropertyException {
    if (!includeProperties) {
        throw propertyMissingException(name);
    }

    MetaProperty property = getMetaClass().hasProperty(bean, name);
    if (property == null) {
        return getMetaClass().invokeMissingProperty(bean, name, null, true);
    }
    if (property instanceof MetaBeanProperty && ((MetaBeanProperty) property).getGetter() == null) {
        throw new GroovyRuntimeException(String.format(
                "Cannot get the value of write-only property '%s' on %s.", name, getDisplayName()));
    }

    try {
        return property.getProperty(bean);
    } catch (InvokerInvocationException e) {
        if (e.getCause() instanceof RuntimeException) {
            throw (RuntimeException) e.getCause();
        }
        throw e;
    }
}
 
Example 9
Source File: PropertyBinding.java    From groovy with Apache License 2.0 5 votes vote down vote up
private void setBeanProperty(Object newValue) {
    try {
        propertyAccessor().write(bean, propertyName, newValue);
    } catch (InvokerInvocationException iie) {
        if (!(iie.getCause() instanceof PropertyVetoException)) {
            throw iie;
        }
        // ignore veto exceptions, just let the binding fail like a validation does
    }
}
 
Example 10
Source File: BeanDynamicObject.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public Object invokeMethod(String name, Object... arguments) throws MissingMethodException {
    try {
        return groovyObject.invokeMethod(name, arguments);
    } catch (InvokerInvocationException e) {
        if (e.getCause() instanceof RuntimeException) {
            throw (RuntimeException) e.getCause();
        }
        throw e;
    }
}
 
Example 11
Source File: BeanDynamicObject.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Object invokeMethod(final String name, final Object... arguments) throws MissingMethodException {
    try {
        return getMetaClass().invokeMethod(bean, name, arguments);
    } catch (InvokerInvocationException e) {
        if (e.getCause() instanceof RuntimeException) {
            throw (RuntimeException) e.getCause();
        }
        throw e;
    }
}
 
Example 12
Source File: BeanDynamicObject.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void setProperty(final String name, Object value) throws MissingPropertyException {
    if (!includeProperties) {
        throw propertyMissingException(name);
    }

    MetaClass metaClass = getMetaClass();
    MetaProperty property = metaClass.hasProperty(bean, name);
    if (property == null) {
        getMetaClass().invokeMissingProperty(bean, name, null, false);
    }

    if (property instanceof MetaBeanProperty && ((MetaBeanProperty) property).getSetter() == null) {
        throw new ReadOnlyPropertyException(name, bean.getClass()) {
            @Override
            public String getMessage() {
                return String.format("Cannot set the value of read-only property '%s' on %s.", name,
                        getDisplayName());
            }
        };
    }
    try {

        // Attempt type coercion before trying to set the property
        value = argsTransformer.transform(bean, MetaProperty.getSetterName(name), value)[0];

        metaClass.setProperty(bean, name, value);
    } catch (InvokerInvocationException e) {
        if (e.getCause() instanceof RuntimeException) {
            throw (RuntimeException) e.getCause();
        }
        throw e;
    }
}
 
Example 13
Source File: BeanDynamicObject.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Object invokeMethod(final String name, final Object... arguments) throws MissingMethodException {
    try {
        return getMetaClass().invokeMethod(bean, name, arguments);
    } catch (InvokerInvocationException e) {
        if (e.getCause() instanceof RuntimeException) {
            throw (RuntimeException) e.getCause();
        }
        throw e;
    }
}
 
Example 14
Source File: BeanDynamicObject.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void setProperty(final String name, Object value) throws MissingPropertyException {
    if (!includeProperties) {
        throw propertyMissingException(name);
    }

    MetaClass metaClass = getMetaClass();
    MetaProperty property = metaClass.hasProperty(bean, name);
    if (property == null) {
        getMetaClass().invokeMissingProperty(bean, name, null, false);
    }

    if (property instanceof MetaBeanProperty && ((MetaBeanProperty) property).getSetter() == null) {
        throw new ReadOnlyPropertyException(name, bean.getClass()) {
            @Override
            public String getMessage() {
                return String.format("Cannot set the value of read-only property '%s' on %s.", name,
                        getDisplayName());
            }
        };
    }
    try {

        // Attempt type coercion before trying to set the property
        value = argsTransformer.transform(bean, MetaProperty.getSetterName(name), value)[0];

        metaClass.setProperty(bean, name, value);
    } catch (InvokerInvocationException e) {
        if (e.getCause() instanceof RuntimeException) {
            throw (RuntimeException) e.getCause();
        }
        throw e;
    }
}
 
Example 15
Source File: BeanDynamicObject.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public Object invokeMethod(String name, Object... arguments) throws MissingMethodException {
    try {
        return groovyObject.invokeMethod(name, arguments);
    } catch (InvokerInvocationException e) {
        if (e.getCause() instanceof RuntimeException) {
            throw (RuntimeException) e.getCause();
        }
        throw e;
    }
}
 
Example 16
Source File: BeanDynamicObject.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Object invokeMethod(final String name, final Object... arguments) throws MissingMethodException {
    try {
        return getMetaClass().invokeMethod(bean, name, arguments);
    } catch (InvokerInvocationException e) {
        if (e.getCause() instanceof RuntimeException) {
            throw (RuntimeException) e.getCause();
        }
        throw e;
    }
}
 
Example 17
Source File: BeanDynamicObject.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void setProperty(final String name, Object value) throws MissingPropertyException {
    if (!includeProperties) {
        throw propertyMissingException(name);
    }

    MetaClass metaClass = getMetaClass();
    MetaProperty property = metaClass.hasProperty(bean, name);
    if (property == null) {
        getMetaClass().invokeMissingProperty(bean, name, null, false);
    }

    if (property instanceof MetaBeanProperty && ((MetaBeanProperty) property).getSetter() == null) {
        throw new ReadOnlyPropertyException(name, bean.getClass()) {
            @Override
            public String getMessage() {
                return String.format("Cannot set the value of read-only property '%s' on %s.", name,
                        getDisplayName());
            }
        };
    }
    try {

        // Attempt type coercion before trying to set the property
        value = argsTransformer.transform(bean, MetaProperty.getSetterName(name), value)[0];

        metaClass.setProperty(bean, name, value);
    } catch (InvokerInvocationException e) {
        if (e.getCause() instanceof RuntimeException) {
            throw (RuntimeException) e.getCause();
        }
        throw e;
    }
}
 
Example 18
Source File: BeanDynamicObject.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public Object invokeMethod(String name, Object... arguments) throws MissingMethodException {
    try {
        return groovyObject.invokeMethod(name, arguments);
    } catch (InvokerInvocationException e) {
        if (e.getCause() instanceof RuntimeException) {
            throw (RuntimeException) e.getCause();
        }
        throw e;
    }
}
 
Example 19
Source File: BeanDynamicObject.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Object invokeMethod(final String name, final Object... arguments) throws MissingMethodException {
    try {
        return getMetaClass().invokeMethod(bean, name, arguments);
    } catch (InvokerInvocationException e) {
        if (e.getCause() instanceof RuntimeException) {
            throw (RuntimeException) e.getCause();
        }
        throw e;
    }
}
 
Example 20
Source File: BeanDynamicObject.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void setProperty(final String name, Object value) throws MissingPropertyException {
    if (!includeProperties) {
        throw propertyMissingException(name);
    }

    MetaClass metaClass = getMetaClass();
    MetaProperty property = metaClass.hasProperty(bean, name);
    if (property == null) {
        getMetaClass().invokeMissingProperty(bean, name, null, false);
    }

    if (property instanceof MetaBeanProperty && ((MetaBeanProperty) property).getSetter() == null) {
        throw new ReadOnlyPropertyException(name, bean.getClass()) {
            @Override
            public String getMessage() {
                return String.format("Cannot set the value of read-only property '%s' on %s.", name,
                        getDisplayName());
            }
        };
    }
    try {

        // Attempt type coercion before trying to set the property
        value = argsTransformer.transform(bean, MetaProperty.getSetterName(name), value)[0];

        metaClass.setProperty(bean, name, value);
    } catch (InvokerInvocationException e) {
        if (e.getCause() instanceof RuntimeException) {
            throw (RuntimeException) e.getCause();
        }
        throw e;
    }
}