![JAR search and dependency download from the Maven repository](/logo.png)
com.google.gwt.validation.client.impl.GwtBeanDescriptorImpl Maven / Gradle / Ivy
/*
* Copyright 2010 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.gwt.validation.client.impl;
import java.lang.annotation.Annotation;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.validation.metadata.ConstraintDescriptor;
import javax.validation.metadata.PropertyDescriptor;
/**
* EXPERIMENTAL and subject to change. Do not use this in
* production code.
*
* Abstract BeanDescriptor for use by generated {@link GwtBeanDescriptor}.
*
* Subclasses are expected to call setDescriptorMap from the constructor.
*
* @param the bean Type
*/
public final class GwtBeanDescriptorImpl implements GwtBeanDescriptor {
/**
* Builder for {@link GwtBeanDescriptors}.
*
* @param the bean Type
*/
public static final class Builder {
private final Class clazz;
private final Map descriptorMap =
new HashMap();
private final Set> constraints =
new HashSet>();
private boolean isConstrained;
private Builder(Class clazz) {
this.clazz = clazz;
}
public Builder add(
ConstraintDescriptor extends Annotation> constraintDescriptor) {
constraints.add(constraintDescriptor);
return this;
}
public GwtBeanDescriptorImpl build() {
return new GwtBeanDescriptorImpl(clazz, isConstrained, descriptorMap,
constraints);
}
public Builder put(String key, PropertyDescriptor value) {
descriptorMap.put(key, value);
return this;
}
public Builder setConstrained(boolean isConstrained) {
this.isConstrained = isConstrained;
return this;
}
}
public static Builder builder(Class clazz) {
return new Builder(clazz);
}
private final Class clazz;
private final Set> constraints = new HashSet>();
private final Map descriptorMap = new HashMap();
private final boolean isBeanConstrained;
private GwtBeanDescriptorImpl(Class clazz, boolean isConstrained,
Map descriptorMap,
Set> constraints) {
super();
this.clazz = clazz;
this.isBeanConstrained = isConstrained;
this.descriptorMap.putAll(descriptorMap);
this.constraints.addAll(constraints);
}
public ConstraintFinder findConstraints() {
// TODO(nchalko) implement
return null;
}
public Set getConstrainedProperties() {
return new HashSet(descriptorMap.values());
}
public Set> getConstraintDescriptors() {
// Copy for safety
return new HashSet>(constraints);
}
public PropertyDescriptor getConstraintsForProperty(String propertyName) {
return descriptorMap.get(propertyName);
}
public Class> getElementClass() {
return clazz;
}
public boolean hasConstraints() {
return !constraints.isEmpty();
}
public boolean isBeanConstrained() {
return isBeanConstrained;
}
}