@SuppressWarnings("unchecked") @Override public <T extends Path.Node> T as(final Class<T> nodeType) throws ClassCastException { // NOPMD if (this.kind == ElementKind.BEAN && nodeType == BeanNode.class || this.kind == ElementKind.CONSTRUCTOR && nodeType == ConstructorNode.class || this.kind == ElementKind.CROSS_PARAMETER && nodeType == CrossParameterNode.class || this.kind == ElementKind.METHOD && nodeType == MethodNode.class || this.kind == ElementKind.PARAMETER && nodeType == ParameterNode.class || this.kind == ElementKind.PROPERTY && (nodeType == PropertyNode.class || nodeType == org.hibernate.validator.path.PropertyNode.class) || this.kind == ElementKind.RETURN_VALUE && nodeType == ReturnValueNode.class || this.kind == ElementKind.CONTAINER_ELEMENT && (nodeType == ContainerElementNode.class || nodeType == org.hibernate.validator.path.ContainerElementNode.class)) { return (T) this; } throw LOG.getUnableToNarrowNodeTypeException(this.getClass(), this.kind, nodeType); }
/** * Returns the category for this constraint violation. By default, the category returned * is the full path for property. You can override this method if you prefer another strategy. */ protected String extractCategory(ValuedParameter[] params, ConstraintViolation<Object> violation) { Iterator<Node> path = violation.getPropertyPath().iterator(); Node method = path.next(); logger.debug("Constraint violation on method {}: {}", method, violation); StringBuilder cat = new StringBuilder(); cat.append(params[path.next().as(ParameterNode.class).getParameterIndex()].getName());// parameter name while (path.hasNext()) { cat.append(".").append(path.next()); } return cat.toString(); }
private int getFirstParameterIndex( Iterator<Node> node ){ ignoreMethodName( node ); ParameterNode parameterNode = node.next().as(ParameterNode.class); return parameterNode.getParameterIndex(); }