Java Code Examples for org.apache.commons.jexl3.JexlException#tryFailed()

The following examples show how to use org.apache.commons.jexl3.JexlException#tryFailed() . 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: ConstructorMethod.java    From commons-jexl with Apache License 2.0 6 votes vote down vote up
@Override
public Object tryInvoke(String name, Object obj, Object... params) {
    try {
        Class<?> ctorClass = ctor.getDeclaringClass();
        boolean invoke = true;
        if (obj != null) {
            if (obj instanceof Class<?>) {
                invoke = ctorClass.equals(obj);
            } else {
                invoke = ctorClass.getName().equals(obj.toString());
            }
        }
        invoke &= name == null || ctorClass.getName().equals(name);
        if (invoke) {
            return ctor.newInstance(params);
        }
    } catch (InstantiationException | IllegalArgumentException | IllegalAccessException xinstance) {
        return Uberspect.TRY_FAILED;
    } catch (InvocationTargetException xinvoke) {
        throw JexlException.tryFailed(xinvoke); // throw
    }
    return Uberspect.TRY_FAILED;
}
 
Example 2
Source File: DuckSetExecutor.java    From commons-jexl with Apache License 2.0 6 votes vote down vote up
@Override
public Object tryInvoke(Object obj, Object key, Object value) {
    if (obj != null
        && objectClass.equals(obj.getClass())
        && method !=  null
        && ((property != null && property.equals(key))
            || (property == null && key == null))
        && valueClass.equals(classOf(value))) {
        try {
            Object[] args = {property, value};
            method.invoke(obj, args);
            return value;
        } catch (IllegalAccessException | IllegalArgumentException xill) {
            return TRY_FAILED;// fail
        } catch (InvocationTargetException xinvoke) {
            throw JexlException.tryFailed(xinvoke); // throw
        } 
    }
    return TRY_FAILED;
}
 
Example 3
Source File: PropertySetExecutor.java    From commons-jexl with Apache License 2.0 6 votes vote down vote up
@Override
public Object tryInvoke(Object o, Object identifier, Object value) {
    if (o != null && method != null
        // ensure method name matches the property name
        && property.equals(castString(identifier))
        // object class should be same as executor's method declaring class
        && objectClass.equals(o.getClass())
        // argument class should be eq
        && valueClass.equals(classOf(value))) {
        try {
            return invoke(o, value);
        } catch (IllegalAccessException | IllegalArgumentException xill) {
            return TRY_FAILED;// fail
        } catch (InvocationTargetException xinvoke) {
            throw JexlException.tryFailed(xinvoke); // throw
        } 
    }
    return TRY_FAILED;
}
 
Example 4
Source File: DuckGetExecutor.java    From commons-jexl with Apache License 2.0 6 votes vote down vote up
@Override
public Object tryInvoke(Object obj, Object key) {
    if (obj != null
            && objectClass.equals(obj.getClass())
            // ensure method name matches the property name
            && method != null
            && ((property == null && key == null)
            || (property != null && property.equals(key)))) {
        try {
            Object[] args = {property};
            return method.invoke(obj, args);
        } catch (IllegalAccessException | IllegalArgumentException xill) {
            return TRY_FAILED;// fail
        } catch (InvocationTargetException xinvoke) {
            throw JexlException.tryFailed(xinvoke); // throw
        }  
    }
    return TRY_FAILED;
}
 
Example 5
Source File: MethodExecutor.java    From commons-jexl with Apache License 2.0 6 votes vote down vote up
@Override
public Object tryInvoke(String name, Object obj, Object... args) {
    MethodKey tkey = new MethodKey(name, args);
    // let's assume that invocation will fly if the declaring class is the
    // same and arguments have the same type
    if (objectClass.equals(obj.getClass()) && tkey.equals(key)) {
        try {
            return invoke(obj, args);
        } catch (IllegalAccessException | IllegalArgumentException xill) {
            return TRY_FAILED;// fail
        } catch (InvocationTargetException xinvoke) {
            throw JexlException.tryFailed(xinvoke); // throw
        }
    }
    return JexlEngine.TRY_FAILED;
}
 
Example 6
Source File: BooleanGetExecutor.java    From commons-jexl with Apache License 2.0 6 votes vote down vote up
@Override
public Object tryInvoke(Object obj, Object key) {
    if (obj != null && method !=  null
        // ensure method name matches the property name
        && property.equals(key)
        && objectClass.equals(obj.getClass())) {
        try {
            return method.invoke(obj, (Object[]) null);
        } catch (IllegalAccessException xill) {
            return TRY_FAILED;// fail
        } catch (InvocationTargetException xinvoke) {
            throw JexlException.tryFailed(xinvoke); // throw
        }
    }
    return TRY_FAILED;
}
 
Example 7
Source File: PropertyGetExecutor.java    From commons-jexl with Apache License 2.0 5 votes vote down vote up
@Override
public Object tryInvoke(Object o, Object identifier) {
    if (o != null && method != null
        && property.equals(castString(identifier))
        && objectClass.equals(o.getClass())) {
        try {
            return method.invoke(o, (Object[]) null);
        } catch (IllegalAccessException | IllegalArgumentException xill) {
            return TRY_FAILED;// fail
        } catch (InvocationTargetException xinvoke) {
            throw JexlException.tryFailed(xinvoke); // throw
        } 
    }
    return TRY_FAILED;
}