本文整理汇总了Java中javax.validation.ElementKind.PROPERTY属性的典型用法代码示例。如果您正苦于以下问题:Java ElementKind.PROPERTY属性的具体用法?Java ElementKind.PROPERTY怎么用?Java ElementKind.PROPERTY使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.validation.ElementKind
的用法示例。
在下文中一共展示了ElementKind.PROPERTY属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createPropertyNode
/**
* create property node.
*
* @param name name of the node
* @param parent parent node
* @return new node implementation
*/
// TODO It would be nicer if we could return PropertyNode
public static NodeImpl createPropertyNode(final String name, final NodeImpl parent) {
return new NodeImpl( //
name, //
parent, //
false, //
null, //
null, //
ElementKind.PROPERTY, //
EMPTY_CLASS_ARRAY, //
null, //
null, //
null, //
null //
);
}
示例2: as
@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);
}
示例3: createBody
@Override
public ValidationErrorMessage createBody(ConstraintViolationException ex, HttpServletRequest req) {
ErrorMessage tmpl = super.createBody(ex, req);
ValidationErrorMessage msg = new ValidationErrorMessage(tmpl);
for (ConstraintViolation<?> violation : ex.getConstraintViolations()) {
Node pathNode = findLastNonEmptyPathNode(violation.getPropertyPath());
// path is probably useful only for properties (fields)
if (pathNode != null && pathNode.getKind() == ElementKind.PROPERTY) {
msg.addError(pathNode.getName(), convertToString(violation.getInvalidValue()), violation.getMessage());
// type level constraints etc.
} else {
msg.addError(violation.getMessage());
}
}
return msg;
}
开发者ID:jirutka,项目名称:spring-rest-exception-handler,代码行数:20,代码来源:ConstraintViolationExceptionHandler.java
示例4: callReferenceConstraints
private void callReferenceConstraints(Object obj, DescriptorPath path) {
DescriptorNode node = path.getHeadNode();
for (ReferenceConstraint<T> constraint : constraints) {
if (node.getClass().isAssignableFrom(constraint.getNodeType())) {
continue;
}
Annotation annotation;
Class<? extends Annotation> annClass = constraint.getAnnotationType();
if (node.getKind() == ElementKind.BEAN) {
annotation = ReflectionHelper.findAnnotation(obj.getClass(), annClass);
} else if (node.getKind() == ElementKind.PROPERTY) {
Method method = node.as(PropertyNode.class).getMethod();
annotation = ReflectionHelper.findAnnotation(method, annClass);
} else {
throw new IllegalStateException(node.getKind() + " is an unsupported type.");
}
if (annotation == null) {
continue;
}
this.violations.addAll(constraint.checkConstraint(annotation, obj, path, allowedRefs));
}
}
示例5: printPropertyPath
private String printPropertyPath(Path path) {
if (path == null) return "UNKNOWN";
String propertyPath = "";
Path.Node parameterNode = null;
// Construct string representation of property path.
// This will strip away any other nodes added by RESTEasy (method, parameter, ...).
for (Path.Node node : path) {
if (node.getKind() == ElementKind.PARAMETER) {
parameterNode = node;
}
if (node.getKind() == ElementKind.PROPERTY) {
if (!propertyPath.isEmpty()) {
propertyPath += ".";
}
propertyPath += node;
}
}
if (propertyPath.isEmpty() && parameterNode != null) {
// No property path constructed, assume this is a validation failure on a request parameter.
propertyPath = parameterNode.toString();
}
return propertyPath;
}
示例6: visitProperty
public Object visitProperty(Object nodeObject, Node node) {
Object next;
if (node.getKind() == ElementKind.PROPERTY) {
next = PropertyUtils.getProperty(nodeObject, node.getName());
}
else if (node.getKind() == ElementKind.BEAN) {
next = nodeObject;
}
else {
throw new UnsupportedOperationException("unknown node: " + node);
}
if (node.getName() != null) {
appendSeparator();
if (!isResource(nodeObject.getClass()) || isPrimaryKey(nodeObject.getClass(), node.getName())) {
// continue along attributes path or primary key on root
appendSourcePointer(node.getName());
}
else if (isAssociation(nodeObject.getClass(), node.getName())) {
appendSourcePointer("/data/relationships/");
appendSourcePointer(node.getName());
}
else {
appendSourcePointer("/data/attributes/");
appendSourcePointer(node.getName());
}
}
return next;
}
示例7: getKind
@Override
public ElementKind getKind() {
if (path == null) {
return ElementKind.BEAN;
} else {
return ElementKind.PROPERTY;
}
}
示例8: printPropertyPath
private String printPropertyPath(Path path) {
if (path == null) {
return "UNKNOWN";
}
String propertyPath = "";
Path.Node parameterNode = null;
// Construct string representation of property path.
// This will strip away any other nodes added by RESTEasy (method, parameter, ...).
for (Path.Node node : path) {
if (node.getKind() == ElementKind.PARAMETER) {
parameterNode = node;
}
if (node.getKind() == ElementKind.PROPERTY) {
if (!propertyPath.isEmpty()) {
propertyPath += ".";
}
propertyPath += node;
}
}
if (propertyPath.isEmpty() && parameterNode != null) {
// No property path constructed, assume this is a validation failure on a request parameter.
propertyPath = parameterNode.toString();
}
return propertyPath;
}
示例9: toString
@Override
public String toString() {
final StringBuilder b = new StringBuilder();
for (final Node node : nodes) {
if (b.length() > 0 && node.getKind() == ElementKind.PROPERTY) {
b.append('.');
}
b.append(node.toString());
}
return b.toString();
}
示例10: ValidationResponse
public ValidationResponse(final ConstraintViolationException cause) {
super(false, new ArrayList<>());
//noinspection ThrowableResultOfMethodCallIgnored
checkNotNull(cause);
Set<ConstraintViolation<?>> violations = cause.getConstraintViolations();
if (violations != null && !violations.isEmpty()) {
for (ConstraintViolation<?> violation : violations) {
List<String> entries = new ArrayList<>();
// iterate path to get the full path
Iterator<Node> it = violation.getPropertyPath().iterator();
while (it.hasNext()) {
Node node = it.next();
if (ElementKind.PROPERTY == node.getKind() || (ElementKind.PARAMETER == node.getKind() && !it.hasNext())) {
if (node.getKey() != null) {
entries.add(node.getKey().toString());
}
entries.add(node.getName());
}
}
if (entries.isEmpty()) {
if (messages == null) {
messages = new ArrayList<>();
}
messages.add(violation.getMessage());
}
else {
if (errors == null) {
errors = new HashMap<>();
}
errors.put(Joiner.on('.').join(entries), violation.getMessage());
}
}
}
else if (cause.getMessage() != null) {
messages = new ArrayList<>();
messages.add(cause.getMessage());
}
}
示例11: derivePropertyPathByNode
protected String derivePropertyPathByNode(ConstraintViolation<Object> vio) {
final StringBuilder sb = new StringBuilder();
final Path path = vio.getPropertyPath();
int elementCount = 0;
for (Path.Node node : path) {
if (node.isInIterable()) { // building e.g. "[0]" of seaList[0]
Object nodeIndex = node.getIndex();
if (nodeIndex == null) {
nodeIndex = node.getKey(); // null if e.g. iterable
}
sb.append("[").append(nodeIndex != null ? nodeIndex : "").append("]"); // e.g. [0] or []
}
final String nodeName = node.getName();
if (nodeName != null && node.getKind() == ElementKind.PROPERTY) {
// _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
// if e.g.
// private List<@Required String> seaList;
// then path is "seaList[0].<list element>" since Hibernate Validator-6.x
// <list element> part is unneeded for property path of message so skip here
// _/_/_/_/_/_/_/_/_/_/
if (!nodeName.startsWith("<")) { // except e.g. <list element>
if (elementCount > 0) {
sb.append(".");
}
sb.append(nodeName);
++elementCount;
}
}
}
return sb.toString(); // e.g. sea, sea.hangar, seaList[0], seaList[0].hangar
}
示例12: setLeafNodeValueIfRequired
public NodeImpl setLeafNodeValueIfRequired(final Object value) {
// The value is only exposed for property and container element nodes
if (this.currentLeafNode.getKind() == ElementKind.PROPERTY
|| this.currentLeafNode.getKind() == ElementKind.CONTAINER_ELEMENT) {
this.requiresWriteableNodeList();
this.currentLeafNode = NodeImpl.setPropertyValue(this.currentLeafNode, value);
this.nodeList.set(this.nodeList.size() - 1, this.currentLeafNode);
// the property value is not part of the NodeImpl hashCode so we don't need to reset the
// PathImpl hashCode
}
return this.currentLeafNode;
}
示例13: PropertyNode
public PropertyNode(String name,
boolean iterable,
Integer index,
Method method) {
super(name, iterable, index, null, ElementKind.PROPERTY);
this.method = method;
}
示例14: getKind
@Override
public ElementKind getKind() {
return ElementKind.PROPERTY;
}
示例15: BeanMetaDataImpl513
/**
* Creates a new {@link BeanMetaDataImpl}
*
* @param beanClass
* The Java type represented by this meta data object.
* @param defaultGroupSequence
* The default group sequence.
* @param defaultGroupSequenceProvider
* The default group sequence provider if set.
* @param constraintMetaDataSet
* All constraint meta data relating to the represented type.
*/
public BeanMetaDataImpl513(Class<T> beanClass, List<Class<?>> defaultGroupSequence,
DefaultGroupSequenceProvider<? super T> defaultGroupSequenceProvider,
Set<ConstraintMetaData> constraintMetaDataSet) {
this.beanClass = beanClass;
this.propertyMetaDataMap = newHashMap();
Set<PropertyMetaData> propertyMetaDataSet = newHashSet();
Set<ExecutableMetaData> executableMetaDataSet = newHashSet();
for (ConstraintMetaData constraintMetaData : constraintMetaDataSet) {
if (constraintMetaData.getKind() == ElementKind.PROPERTY) {
propertyMetaDataSet.add((PropertyMetaData) constraintMetaData);
} else {
executableMetaDataSet.add((ExecutableMetaData) constraintMetaData);
}
}
Set<Cascadable> cascadedProperties = newHashSet();
Set<MetaConstraint<?>> allMetaConstraints = newHashSet();
for (PropertyMetaData propertyMetaData : propertyMetaDataSet) {
propertyMetaDataMap.put(propertyMetaData.getName(), propertyMetaData);
if (propertyMetaData.isCascading()) {
cascadedProperties.add(propertyMetaData);
}
allMetaConstraints.addAll(propertyMetaData.getConstraints());
}
this.cascadedProperties = Collections.unmodifiableSet(cascadedProperties);
this.allMetaConstraints = Collections.unmodifiableSet(allMetaConstraints);
// this.classHierarchyWithoutInterfaces =
// ClassHierarchyHelper.getHierarchy(
// beanClass,
// Filters.excludeInterfaces()
// );
this.classHierarchyWithoutInterfaces = new ArrayList<Class<? super T>>(1);
this.classHierarchyWithoutInterfaces.add(beanClass);
setDefaultGroupSequenceOrProvider(defaultGroupSequence, defaultGroupSequenceProvider);
this.directMetaConstraints = getDirectConstraints();
this.executableMetaDataMap = Collections.unmodifiableMap(byIdentifier(executableMetaDataSet));
this.beanDescriptor = new BeanDescriptorImpl(beanClass, getClassLevelConstraintsAsDescriptors(),
getConstrainedPropertiesAsDescriptors(), getConstrainedMethodsAsDescriptors(),
getConstrainedConstructorsAsDescriptors(), defaultGroupSequenceIsRedefined(),
getDefaultGroupSequence(null));
}