Java Code Examples for javax.validation.Path.Node#getName()

The following examples show how to use javax.validation.Path.Node#getName() . 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: ConstraintViolationImpl.java    From crnk-framework with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
	Iterator<Node> iterator = iterator();
	StringBuilder builder = new StringBuilder();
	while (iterator.hasNext()) {
		Node node = iterator.next();
		String name = node.getName();
		if (name != null && builder.length() > 0) {
			builder.append(".");
		}
		builder.append(node);
	}
	return builder.toString();
}
 
Example 2
Source File: ConstraintViolationExceptionMapper.java    From crnk-framework with Apache License 2.0 4 votes vote down vote up
public Object visitProperty(Object nodeObject, Node node) {
	ResourceRegistry resourceRegistry = context.getResourceRegistry();
	Class nodeClass = nodeObject.getClass();
	ResourceInformation resourceInformation = null;
	if (resourceRegistry.hasEntry(nodeClass)) {
		RegistryEntry entry = resourceRegistry.getEntry(nodeClass);
		resourceInformation = entry.getResourceInformation();
	}

	String name = node.getName();

	Object next;
	if (node.getKind() == ElementKind.PROPERTY) {
		if (resourceRegistry.hasEntry(nodeClass)) {
			ResourceFieldAccessor accessor = resourceInformation.getAccessor(name);
			if (accessor != null) {
				next = accessor.getValue(nodeObject);
			} else {
				next = PropertyUtils.getProperty(nodeObject, name);
			}
		} else {
			next = PropertyUtils.getProperty(nodeObject, name);
		}
	} else if (node.getKind() == ElementKind.BEAN) {
		next = nodeObject;
	} else {
		throw new UnsupportedOperationException("unknown node: " + node);
	}

	if (name != null) {
		ResourceField resourceField =
				resourceInformation != null ? resourceInformation.findFieldByUnderlyingName(name) : null;

		String mappedName = name;
		if (resourceField != null) {
			// in case of @JsonApiRelationId it will be mapped to original name
			resourceField = resourceInformation.findFieldByUnderlyingName(resourceField.getUnderlyingName());
			mappedName = resourceField.getJsonName();
		}

		appendSeparator();
		if (resourceField == null || resourceField.getResourceFieldType() == ResourceFieldType.ID) {
			// continue along attributes path or primary key on root
			appendSourcePointer(mappedName);
		} else if (resourceField != null && resourceField.getResourceFieldType() == ResourceFieldType.RELATIONSHIP) {
			appendSourcePointer("/data/relationships/");
			appendSourcePointer(mappedName);
		} else {

			appendSourcePointer("/data/attributes/");
			appendSourcePointer(mappedName);
		}
	}
	return next;
}