Example usage for org.springframework.beans PropertyAccessException getCause

List of usage examples for org.springframework.beans PropertyAccessException getCause

Introduction

In this page you can find the example usage for org.springframework.beans PropertyAccessException 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:ru.org.linux.util.ExceptionBindingErrorProcessor.java

@Override
public void processPropertyAccessException(PropertyAccessException e, BindingResult bindingResult) {
    if (e.getCause() instanceof IllegalArgumentException
            && (e.getCause().getCause() instanceof ScriptErrorException
                    || e.getCause().getCause() instanceof UserNotFoundException)) {
        bindingResult.rejectValue(e.getPropertyChangeEvent().getPropertyName(), null,
                e.getCause().getCause().getMessage());
    } else {/*from ww w.ja va 2  s.  c om*/
        super.processPropertyAccessException(e, bindingResult);
    }
}

From source file:org.trpr.platform.impl.validation.ExpressionBasedValidator.java

/**
 * Interface method implementation. Note that this validator handles  NullPointerException that may be thrown during expression evaluation i.e.
 * when accessing property values defined in the expression and treats it as a validation failure with FATAL severity.
 * /*from   w  w  w .  j  a va2s.  c o  m*/
 * @see Validator#validate(String, ResultCode, Object)
 */
public ValidationResult[] validate(String mvelExpression, ResultCode resultCode, Object inputObject) {
    boolean mvelResult = false;
    try {
        Serializable compiled = MVEL.compileExpression(mvelExpression, CTX);
        mvelResult = ((Boolean) MVEL.executeExpression(compiled, inputObject)).booleanValue();
    } catch (PropertyAccessException pae) {
        if (pae.getCause() instanceof NullPointerException) {
            LOGGER.warn(
                    "Null pointer exception occurred in property access during expression evaluation in validator",
                    pae.getCause());
            return new ValidationResult[] {
                    new ValidationResult(Severity.FATAL, resultCode, NPE_MESSAGE, this.label) };
        } else {
            // throw it back as it could be a development time error in expression
            throw pae;
        }
    }
    if (!mvelResult) {
        String message = this.defaultMessage;
        // TODO : get the local specific message using the messageID. Default message is currently used.
        return new ValidationResult[] { new ValidationResult(resultCode, message) };
    }
    return null;
}