You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bval.apache.org by mb...@apache.org on 2018/02/25 19:38:22 UTC
[2/6] bval git commit: clean up no-longer-used code from JSR module
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/JsrFeatures.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/JsrFeatures.java b/bval-jsr/src/main/java/org/apache/bval/jsr/JsrFeatures.java
deleted file mode 100644
index 91687f9..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/JsrFeatures.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.bval.jsr;
-
-import org.apache.bval.model.Features;
-
-/**
- * Description: Contains MetaBean feature keys of additional features used in the implementation
- * of JSR303<br/>
- *
- * @see org.apache.bval.model.FeaturesCapable
- * @see org.apache.bval.model.Features
- */
-public interface JsrFeatures {
- interface Method extends Features.Property {
- String MethodDescriptor = "MethodDescriptor";
- }
-
- interface Constructor extends Features.Property {
- String ConstructorDescriptor = "ConstructorDescriptor";
- }
-
- /**
- * JSR303 Property features
- */
- interface Property extends Features.Property {
- /** INFO: cached PropertyDescriptorImpl of the property */
- String PropertyDescriptor = "PropertyDescriptor";
- /**
- * INFO: Class[] with the groups to validate a REF_CASCADE
- */
- String REF_GROUPS = "refGroups";
-
- // Collection<Annotation>
- String ANNOTATIONS_TO_PROCESS = "annotationToProcess";
- }
-
- /**
- * JSR303 bean features
- */
- interface Bean extends Features.Bean {
- /**
- * INFO: List of Group(Class) for {@link javax.validation.GroupSequence#value()}
- * (redefined default group)
- **/
- String GROUP_SEQUENCE = "GroupSequence";
-
- /**
- * INFO: cached BeanDescriptorImpl of the bean
- */
- String BEAN_DESCRIPTOR = "BeanDescriptor";
- }
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/JsrMetaBeanFactory.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/JsrMetaBeanFactory.java b/bval-jsr/src/main/java/org/apache/bval/jsr/JsrMetaBeanFactory.java
deleted file mode 100644
index 97eece1..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/JsrMetaBeanFactory.java
+++ /dev/null
@@ -1,339 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.bval.jsr;
-
-import org.apache.bval.MetaBeanFactory;
-import org.apache.bval.jsr.groups.Group;
-import org.apache.bval.jsr.util.ClassHelper;
-import org.apache.bval.jsr.xml.MetaConstraint;
-import org.apache.bval.model.Features.Property;
-import org.apache.bval.model.Meta;
-import org.apache.bval.model.MetaBean;
-import org.apache.bval.model.MetaConstructor;
-import org.apache.bval.model.MetaMethod;
-import org.apache.bval.model.MetaParameter;
-import org.apache.bval.model.MetaProperty;
-import org.apache.bval.util.AccessStrategy;
-import org.apache.bval.util.FieldAccess;
-import org.apache.bval.util.MethodAccess;
-import org.apache.bval.util.reflection.Reflection;
-import org.apache.commons.weaver.privilizer.Privilizing;
-import org.apache.commons.weaver.privilizer.Privilizing.CallTo;
-
-import javax.validation.ConstraintDeclarationException;
-import javax.validation.GroupDefinitionException;
-import javax.validation.GroupSequence;
-import javax.validation.groups.ConvertGroup;
-import javax.validation.groups.Default;
-
-import java.lang.annotation.Annotation;
-import java.lang.annotation.ElementType;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Description: process the class annotations for JSR303 constraint validations to build the MetaBean with information
- * from annotations and JSR303 constraint mappings (defined in xml)<br/>
- */
-@Privilizing(@CallTo(Reflection.class))
-public class JsrMetaBeanFactory implements MetaBeanFactory {
- /** Shared log instance */
- // of dubious utility as it's static :/
- protected static final Logger log = Logger.getLogger(JsrMetaBeanFactory.class.getName());
-
- /** {@link javax.validation.ValidatorFactory} used */
- protected final ApacheValidatorFactory factory;
-
- /**
- * {@link AnnotationProcessor} used.
- */
- protected AnnotationProcessor annotationProcessor;
-
- /**
- * Create a new Jsr303MetaBeanFactory instance.
- *
- * @param factory the validator factory.
- */
- public JsrMetaBeanFactory(ApacheValidatorFactory factory) {
- this.factory = factory;
- this.annotationProcessor = new AnnotationProcessor(factory);
- }
-
- /**
- * {@inheritDoc} Add the validation features to the metabean that come from JSR303 annotations in the beanClass.
- */
- @Override
- public void buildMetaBean(MetaBean metabean) {
- try {
- final Class<?> beanClass = metabean.getBeanClass();
- processGroupSequence(beanClass, metabean);
-
- // process class, superclasses and interfaces
- final List<Class<?>> classSequence =
- ClassHelper.fillFullClassHierarchyAsList(new ArrayList<Class<?>>(), beanClass);
-
- // start with superclasses and go down the hierarchy so that
- // the child classes are processed last to have the chance to
- // overwrite some declarations
- // of their superclasses and that they see what they inherit at the
- // time of processing
- for (int i = classSequence.size() - 1; i >= 0; i--) {
- Class<?> eachClass = classSequence.get(i);
- processClass(eachClass, metabean);
- processGroupSequence(eachClass, metabean, "{GroupSequence:" + eachClass.getCanonicalName() + "}");
- }
-
- } catch (IllegalAccessException e) {
- throw new IllegalArgumentException(e);
- } catch (InvocationTargetException e) {
- throw new IllegalArgumentException(e.getTargetException());
- }
- }
-
- /**
- * Process class annotations, field and method annotations.
- *
- * @param beanClass
- * @param metabean
- * @throws IllegalAccessException
- * @throws InvocationTargetException
- */
- private void processClass(Class<?> beanClass, MetaBean metabean)
- throws IllegalAccessException, InvocationTargetException {
-
- // if NOT ignore class level annotations
- if (!factory.getAnnotationIgnores().isIgnoreAnnotations(beanClass)) {
- annotationProcessor.processAnnotations(null, beanClass, beanClass, null,
- new AppendValidationToMeta(metabean));
- }
-
- final Collection<String> missingValid = new ArrayList<String>();
-
- final Field[] fields = Reflection.getDeclaredFields(beanClass);
- for (final Field field : fields) {
- MetaProperty metaProperty = metabean.getProperty(field.getName());
- // create a property for those fields for which there is not yet a
- // MetaProperty
- if (!factory.getAnnotationIgnores().isIgnoreAnnotations(field)) {
- AccessStrategy access = new FieldAccess(field);
- boolean create = metaProperty == null;
- if (create) {
- metaProperty = addMetaProperty(metabean, access);
- }
- if (!annotationProcessor.processAnnotations(metaProperty, beanClass, field, access,
- new AppendValidationToMeta(metaProperty)) && create) {
- metabean.putProperty(metaProperty.getName(), null);
- }
-
- if (field.getAnnotation(ConvertGroup.class) != null) {
- missingValid.add(field.getName());
- }
- }
- }
- final Method[] methods = Reflection.getDeclaredMethods(beanClass);
- for (final Method method : methods) {
- if (method.isSynthetic() || method.isBridge()) {
- continue;
- }
- String propName = null;
- if (method.getParameterTypes().length == 0) {
- propName = MethodAccess.getPropertyName(method);
- }
- if (propName != null) {
- if (!factory.getAnnotationIgnores().isIgnoreAnnotations(method)) {
- AccessStrategy access = new MethodAccess(propName, method);
- MetaProperty metaProperty = metabean.getProperty(propName);
- boolean create = metaProperty == null;
- // create a property for those methods for which there is
- // not yet a MetaProperty
- if (create) {
- metaProperty = addMetaProperty(metabean, access);
- }
- if (!annotationProcessor.processAnnotations(metaProperty, beanClass, method, access,
- new AppendValidationToMeta(metaProperty)) && create) {
- metabean.putProperty(propName, null);
- }
- }
- }
- }
-
- addXmlConstraints(beanClass, metabean);
-
- for (final String name : missingValid) {
- final MetaProperty metaProperty = metabean.getProperty(name);
- if (metaProperty != null && metaProperty.getFeature(Property.REF_CASCADE) == null) {
- throw new ConstraintDeclarationException("@ConvertGroup needs @Valid");
- }
- }
- missingValid.clear();
- }
-
- /**
- * Add cascade validation and constraints from xml mappings
- *
- * @param beanClass
- * @param metabean
- * @throws IllegalAccessException
- * @throws InvocationTargetException
- */
- private void addXmlConstraints(Class<?> beanClass, MetaBean metabean)
- throws IllegalAccessException, InvocationTargetException {
- for (final MetaConstraint<?, ? extends Annotation> metaConstraint : factory.getMetaConstraints(beanClass)) {
- Meta meta;
- AccessStrategy access = metaConstraint.getAccessStrategy();
- boolean create = false;
- if (access == null) { // class level
- meta = null;
- } else if (access.getElementType() == ElementType.METHOD
- && !metaConstraint.getMember().getName().startsWith("get")) { // TODO: better getter test
- final Method method = Method.class.cast(metaConstraint.getMember());
- meta = metabean.getMethod(method);
- final MetaMethod metaMethod;
- if (meta == null) {
- meta = new MetaMethod(metabean, method);
- metaMethod = MetaMethod.class.cast(meta);
- metabean.addMethod(method, metaMethod);
- } else {
- metaMethod = MetaMethod.class.cast(meta);
- }
- final Integer index = metaConstraint.getIndex();
- if (index != null && index >= 0) {
- MetaParameter param = metaMethod.getParameter(index);
- if (param == null) {
- param = new MetaParameter(metaMethod, index);
- metaMethod.addParameter(index, param);
- }
- param.addAnnotation(metaConstraint.getAnnotation());
- } else {
- metaMethod.addAnnotation(metaConstraint.getAnnotation());
- }
- continue;
- } else if (access.getElementType() == ElementType.CONSTRUCTOR) {
- final Constructor<?> constructor = Constructor.class.cast(metaConstraint.getMember());
- meta = metabean.getConstructor(constructor);
- final MetaConstructor metaConstructor;
- if (meta == null) {
- meta = new MetaConstructor(metabean, constructor);
- metaConstructor = MetaConstructor.class.cast(meta);
- metabean.addConstructor(constructor, metaConstructor);
- } else {
- metaConstructor = MetaConstructor.class.cast(meta);
- }
- final Integer index = metaConstraint.getIndex();
- if (index != null && index >= 0) {
- MetaParameter param = metaConstructor.getParameter(index);
- if (param == null) {
- param = new MetaParameter(metaConstructor, index);
- metaConstructor.addParameter(index, param);
- }
- param.addAnnotation(metaConstraint.getAnnotation());
- } else {
- metaConstructor.addAnnotation(metaConstraint.getAnnotation());
- }
- continue;
- } else { // property level
- meta = metabean.getProperty(access.getPropertyName());
- create = meta == null;
- if (create) {
- meta = addMetaProperty(metabean, access);
- }
- }
- if (!annotationProcessor.processAnnotation(metaConstraint.getAnnotation(), meta, beanClass,
- metaConstraint.getAccessStrategy(), new AppendValidationToMeta(meta == null ? metabean : meta), false)
- && create) {
- metabean.putProperty(access.getPropertyName(), null);
- }
- }
- for (final AccessStrategy access : factory.getValidAccesses(beanClass)) {
- if (access.getElementType() == ElementType.PARAMETER) {
- continue;
- }
-
- MetaProperty metaProperty = metabean.getProperty(access.getPropertyName());
- boolean create = metaProperty == null;
- if (create) {
- metaProperty = addMetaProperty(metabean, access);
- }
- if (!annotationProcessor.addAccessStrategy(metaProperty, access) && create) {
- metabean.putProperty(access.getPropertyName(), null);
- }
- }
- }
-
- private void processGroupSequence(Class<?> beanClass, MetaBean metabean) {
- processGroupSequence(beanClass, metabean, JsrFeatures.Bean.GROUP_SEQUENCE);
- }
-
- private void processGroupSequence(Class<?> beanClass, MetaBean metabean, String key) {
- GroupSequence annotation = beanClass.getAnnotation(GroupSequence.class);
- List<Group> groupSeq = metabean.getFeature(key);
- if (groupSeq == null) {
- groupSeq =
- metabean.initFeature(key, new ArrayList<Group>(annotation == null ? 1 : annotation.value().length));
- }
- Class<?>[] groupClasses = factory.getDefaultSequence(beanClass);
- if (groupClasses == null || groupClasses.length == 0) {
- if (annotation == null) {
- groupSeq.add(Group.DEFAULT);
- return;
- } else {
- groupClasses = annotation.value();
- }
- }
- boolean containsDefault = false;
- for (final Class<?> groupClass : groupClasses) {
- if (groupClass.getName().equals(beanClass.getName())) {
- groupSeq.add(Group.DEFAULT);
- containsDefault = true;
- } else if (groupClass.getName().equals(Default.class.getName())) {
- throw new GroupDefinitionException("'Default.class' must not appear in @GroupSequence! Use '"
- + beanClass.getSimpleName() + ".class' instead.");
- } else {
- groupSeq.add(new Group(groupClass));
- }
- }
- if (!containsDefault) {
- throw new GroupDefinitionException("Redefined default group sequence must contain " + beanClass.getName());
- }
- log.log(Level.FINEST,
- String.format("Default group sequence for bean %s is: %s", beanClass.getName(), groupSeq));
- }
-
- /**
- * Add a {@link MetaProperty} to a {@link MetaBean}.
- * @param parentMetaBean
- * @param access
- * @return the created {@link MetaProperty}
- */
- public static MetaProperty addMetaProperty(MetaBean parentMetaBean, AccessStrategy access) {
- final MetaProperty result = new MetaProperty();
- final String name = access.getPropertyName();
- result.setName(name);
- result.setType(access.getJavaType());
- parentMetaBean.putProperty(name, result);
- return result;
- }
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/MethodDescriptor.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/MethodDescriptor.java b/bval-jsr/src/main/java/org/apache/bval/jsr/MethodDescriptor.java
deleted file mode 100644
index 99bc31d..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/MethodDescriptor.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 org.apache.bval.jsr;
-
-import javax.validation.metadata.ElementDescriptor;
-import javax.validation.metadata.ParameterDescriptor;
-import java.util.List;
-
-/**
- * Description: This class will disappear when such
- * functionality is part of the JSR303 specification.<br/>
- */
-public interface MethodDescriptor extends ElementDescriptor {
- /**
- * Get the {@link javax.validation.metadata.ParameterDescriptor}s for this {@link org.apache.bval.jsr.MethodDescriptor}.
- * @return {@link java.util.List} of {@link javax.validation.metadata.ParameterDescriptor}
- */
- List<ParameterDescriptor> getParameterDescriptors(); //index aligned
-
- /**
- * Learn whether the referenced method should be validated.
- * @return boolean
- */
- boolean isCascaded();
-
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/MethodDescriptorImpl.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/MethodDescriptorImpl.java b/bval-jsr/src/main/java/org/apache/bval/jsr/MethodDescriptorImpl.java
deleted file mode 100644
index f9b0247..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/MethodDescriptorImpl.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 org.apache.bval.jsr;
-
-import org.apache.bval.model.MetaBean;
-import org.apache.bval.model.MetaMethod;
-import org.apache.bval.model.Validation;
-
-import java.lang.reflect.Method;
-
-/**
- * Description: {@link MethodDescriptor} implementation.<br/>
- */
-public class MethodDescriptorImpl extends InvocableElementDescriptor
- implements javax.validation.metadata.MethodDescriptor, ProcedureDescriptor {
- private static final Validation[] EMPTY_VALIDATION = new Validation[0];
-
- private final String name;
-
- protected MethodDescriptorImpl(final MetaBean metaBean, final Validation[] validations, final Method method) {
- super(metaBean, method.getReturnType(), validations);
- name = method.getName();
- }
-
- public MethodDescriptorImpl(final MetaBean bean, final MetaMethod metaMethod) {
- super(bean, metaMethod.getMethod().getReturnType(), EMPTY_VALIDATION);
- setCascaded(false);
- this.name = metaMethod.getMethod().getName();
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public boolean hasConstrainedParameters() {
- return super.hasConstrainedParameters();
- }
-
- @Override
- public boolean hasConstrainedReturnValue() {
- return super.hasConstrainedReturnValue();
- }
-
- @Override
- public boolean hasConstraints() {
- return false;
- }
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/ParameterAccess.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/ParameterAccess.java b/bval-jsr/src/main/java/org/apache/bval/jsr/ParameterAccess.java
deleted file mode 100644
index a9c16bb..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/ParameterAccess.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.bval.jsr;
-
-import org.apache.bval.util.AccessStrategy;
-
-import java.lang.annotation.ElementType;
-import java.lang.reflect.Type;
-
-/**
- * Implementation of {@link org.apache.bval.util.AccessStrategy} for method parameters.
- *
- * @author Carlos Vara
- */
-public class ParameterAccess extends AccessStrategy {
-
- private Type paramType;
- private int paramIdx;
-
- /**
- * Create a new ParameterAccess instance.
- * @param paramType
- * @param paramIdx
- */
- public ParameterAccess(Type paramType, int paramIdx) {
- this.paramType = paramType;
- this.paramIdx = paramIdx;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Object get(Object instance) {
- throw new UnsupportedOperationException("Obtaining a parameter value not yet implemented");
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public ElementType getElementType() {
- return ElementType.PARAMETER;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Type getJavaType() {
- return this.paramType;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String getPropertyName() {
- return "" + paramIdx;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o)
- return true;
- if (o == null || getClass() != o.getClass())
- return false;
-
- final ParameterAccess that = (ParameterAccess) o;
- return paramIdx == that.paramIdx && paramType.equals(that.paramType);
- }
-
- @Override
- public int hashCode() {
- int result = paramType.hashCode();
- result = 31 * result + paramIdx;
- return result;
- }
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/ParameterDescriptorImpl.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/ParameterDescriptorImpl.java b/bval-jsr/src/main/java/org/apache/bval/jsr/ParameterDescriptorImpl.java
deleted file mode 100644
index 65f3ecc..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/ParameterDescriptorImpl.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 org.apache.bval.jsr;
-
-import org.apache.bval.jsr.groups.Group;
-import org.apache.bval.jsr.groups.GroupConversionDescriptorImpl;
-import org.apache.bval.model.MetaBean;
-import org.apache.bval.model.Validation;
-
-import javax.validation.metadata.ContainerElementTypeDescriptor;
-import javax.validation.metadata.GroupConversionDescriptor;
-import javax.validation.metadata.ParameterDescriptor;
-import java.util.Set;
-import java.util.concurrent.CopyOnWriteArraySet;
-
-/**
- * Description: {@link javax.validation.metadata.ParameterDescriptor} implementation.<br/>
- */
-public class ParameterDescriptorImpl extends ElementDescriptorImpl implements ParameterDescriptor {
- private final Set<GroupConversionDescriptor> groupConversions =
- new CopyOnWriteArraySet<GroupConversionDescriptor>();
- private final String name;
- private int index;
-
- /**
- * Create a new ParameterDescriptorImpl instance.
- * @param metaBean
- * @param validations
- */
- public ParameterDescriptorImpl(MetaBean metaBean, Validation[] validations, String name) {
- super(metaBean, metaBean.getBeanClass(), validations);
- this.name = name;
- }
-
- /**
- * Create a new ParameterDescriptorImpl instance.
- * @param elementClass
- * @param validations
- */
- public ParameterDescriptorImpl(Class<?> elementClass, Validation[] validations, String name) {
- super(elementClass, validations);
- this.name = name;
- }
-
- @Override
- public Set<GroupConversionDescriptor> getGroupConversions() {
- return groupConversions;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int getIndex() {
- return index;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- /**
- * Set the index of the referenced parameter.
- * @param index
- */
- public void setIndex(int index) {
- this.index = index;
- }
-
- @Override
- public void addGroupMapping(final Group from, final Group to) {
- groupConversions.add(new GroupConversionDescriptorImpl(from, to));
- super.addGroupMapping(from, to);
- }
-
- @Override
- public Set<ContainerElementTypeDescriptor> getConstrainedContainerElementTypes() {
- // TODO Auto-generated method stub
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/ParametersAccess.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/ParametersAccess.java b/bval-jsr/src/main/java/org/apache/bval/jsr/ParametersAccess.java
deleted file mode 100644
index 2490dbc..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/ParametersAccess.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.bval.jsr;
-
-import org.apache.bval.util.AccessStrategy;
-
-import java.lang.annotation.ElementType;
-import java.lang.reflect.Type;
-
-public class ParametersAccess extends AccessStrategy {
- @Override
- public Object get(final Object instance) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public ElementType getElementType() {
- return ElementType.PARAMETER;
- }
-
- @Override
- public Type getJavaType() {
- return Object[].class;
- }
-
- @Override
- public String getPropertyName() {
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/ProcedureDescriptor.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/ProcedureDescriptor.java b/bval-jsr/src/main/java/org/apache/bval/jsr/ProcedureDescriptor.java
deleted file mode 100644
index d85c703..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/ProcedureDescriptor.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 org.apache.bval.jsr;
-
-import org.apache.bval.jsr.groups.Group;
-import org.apache.bval.model.MetaBean;
-
-import javax.validation.metadata.ParameterDescriptor;
-import java.util.List;
-
-/**
- * Description: superinterface of {@link javax.validation.metadata.ConstructorDescriptor} and {@link org.apache.bval.jsr.MethodDescriptor}.<br/>
- */
-public interface ProcedureDescriptor {
- /**
- * Get the owning metabean.
- * @return MetaBean
- */
- MetaBean getMetaBean();
-
- /**
- * Set whether this procedure should be validated.
- * @param b
- */
- void setCascaded(boolean b);
-
- /**
- * Get the parameter descriptors of this procedure.
- * @return {@link java.util.List} of {@link javax.validation.metadata.ParameterDescriptor}
- */
- List<ParameterDescriptor> getParameterDescriptors();
-
- void addGroupMapping(Group from, Group to);
-
- Group mapGroup(Group current);
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/PropertyDescriptorImpl.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/PropertyDescriptorImpl.java b/bval-jsr/src/main/java/org/apache/bval/jsr/PropertyDescriptorImpl.java
deleted file mode 100644
index 03cf5de..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/PropertyDescriptorImpl.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.bval.jsr;
-
-import org.apache.bval.model.Features;
-import org.apache.bval.model.MetaProperty;
-
-import java.util.Set;
-
-import javax.validation.metadata.ContainerElementTypeDescriptor;
-import javax.validation.metadata.PropertyDescriptor;
-
-/**
- * Description: {@link PropertyDescriptor} implementation.<br/>
- *
- * TODO: use it instead of MetaProperty!
- */
-class PropertyDescriptorImpl extends ElementDescriptorImpl implements PropertyDescriptor {
- private String propertyPath;
-
- /**
- * Create a new PropertyDescriptorImpl instance.
- *
- * @param property
- */
- PropertyDescriptorImpl(MetaProperty property) {
- super(property.getParentMetaBean(), property.getTypeClass(), property.getValidations());
- setCascaded(property.getMetaBean() != null || property.getFeature(Features.Property.REF_CASCADE) != null);
- setPropertyPath(property.getName());
- }
-
- /**
- * Set the referenced property path.
- *
- * @param propertyPath
- */
- public void setPropertyPath(String propertyPath) {
- this.propertyPath = propertyPath;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String getPropertyName() {
- return propertyPath;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return "PropertyDescriptorImpl{" + "returnType=" + elementClass + ", propertyPath='" + propertyPath + '\''
- + '}';
- }
-
- @Override
- public Set<ContainerElementTypeDescriptor> getConstrainedContainerElementTypes() {
- // TODO Auto-generated method stub
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/ReturnAccess.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/ReturnAccess.java b/bval-jsr/src/main/java/org/apache/bval/jsr/ReturnAccess.java
deleted file mode 100644
index b973b3f..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/ReturnAccess.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.bval.jsr;
-
-import org.apache.bval.util.AccessStrategy;
-
-import java.lang.annotation.ElementType;
-import java.lang.reflect.Type;
-
-/**
- * Implementation of {@link org.apache.bval.util.AccessStrategy} for method return values.
- *
- * @author Carlos Vara
- */
-public class ReturnAccess extends AccessStrategy {
-
- private Type returnType;
-
- /**
- * Create a new ReturnAccess instance.
- * @param returnType
- */
- public ReturnAccess(Type returnType) {
- this.returnType = returnType;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Object get(Object instance) {
- throw new UnsupportedOperationException("Obtaining a method return value not yet implemented");
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public ElementType getElementType() {
- return ElementType.METHOD;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Type getJavaType() {
- return this.returnType;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String getPropertyName() {
- return "Return value";
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/ReturnValueDescriptorImpl.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/ReturnValueDescriptorImpl.java b/bval-jsr/src/main/java/org/apache/bval/jsr/ReturnValueDescriptorImpl.java
deleted file mode 100644
index a6faa9b..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/ReturnValueDescriptorImpl.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 org.apache.bval.jsr;
-
-import org.apache.bval.model.MetaBean;
-
-import javax.validation.metadata.ContainerElementTypeDescriptor;
-import javax.validation.metadata.ReturnValueDescriptor;
-import java.util.Collection;
-import java.util.Set;
-
-public class ReturnValueDescriptorImpl extends ElementDescriptorImpl implements ReturnValueDescriptor {
- public ReturnValueDescriptorImpl(final MetaBean metaBean, Class<?> returnType,
- final Collection<ConstraintValidation<?>> list, boolean cascaded) {
- super(metaBean, returnType, list.toArray(new ConstraintValidation<?>[list.size()]));
- setCascaded(cascaded);
- }
-
- @Override
- public boolean hasConstraints() {
- return false;
- }
-
- @Override
- public Set<ContainerElementTypeDescriptor> getConstrainedContainerElementTypes() {
- // TODO Auto-generated method stub
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/UnknownPropertyException.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/UnknownPropertyException.java b/bval-jsr/src/main/java/org/apache/bval/jsr/UnknownPropertyException.java
deleted file mode 100644
index c771050..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/UnknownPropertyException.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.bval.jsr;
-
-import javax.validation.ValidationException;
-
-/**
- * Internal exception thrown when trying to access a property that doesn't exist
- * in a bean.
- *
- * @version $Rev: 1166451 $ $Date: 2011-09-08 00:32:26 +0200 (jeu., 08 sept. 2011) $
- *
- * @author Carlos Vara
- */
-public class UnknownPropertyException extends ValidationException {
-
- private static final long serialVersionUID = 1L;
-
- /**
- * Create a new UnknownPropertyException instance.
- * @param message
- */
- public UnknownPropertyException(String message) {
- super(message);
- }
-
- /**
- * Create a new UnknownPropertyException instance.
- */
- public UnknownPropertyException() {
- super();
- }
-
- /**
- * Create a new UnknownPropertyException instance.
- * @param message
- * @param cause
- */
- public UnknownPropertyException(String message, Throwable cause) {
- super(message, cause);
- }
-
- /**
- * Create a new UnknownPropertyException instance.
- * @param cause
- */
- public UnknownPropertyException(Throwable cause) {
- super(cause);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/CascadableContainerD.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/CascadableContainerD.java b/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/CascadableContainerD.java
index 8e6410a..7404278 100644
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/CascadableContainerD.java
+++ b/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/CascadableContainerD.java
@@ -29,6 +29,7 @@ import javax.validation.metadata.ContainerElementTypeDescriptor;
import javax.validation.metadata.GroupConversionDescriptor;
import org.apache.bval.jsr.GraphContext;
+import org.apache.bval.jsr.groups.GroupConversion;
import org.apache.bval.jsr.util.ToUnmodifiable;
import org.apache.bval.util.Validate;
import org.apache.bval.util.reflection.TypeUtils;
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/DescriptorManager.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/DescriptorManager.java b/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/DescriptorManager.java
index e90527e..01a1b5c 100644
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/DescriptorManager.java
+++ b/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/DescriptorManager.java
@@ -62,6 +62,10 @@ public class DescriptorManager {
return Optional.ofNullable(beanDescriptors.putIfAbsent(beanClass, beanD)).orElse(beanD);
}
+ public void clear() {
+ beanDescriptors.clear();
+ }
+
private MetadataBuilder.ForBean builder(Class<?> beanClass) {
final MetadataBuilder.ForBean primaryBuilder =
new HierarchyBuilder(reflectionBuilder::forBean).forBean(beanClass);
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/GroupConversion.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/GroupConversion.java b/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/GroupConversion.java
deleted file mode 100644
index 9ef724e..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/GroupConversion.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to you 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 org.apache.bval.jsr.descriptor;
-
-import java.util.Objects;
-import java.util.Optional;
-
-import javax.validation.metadata.GroupConversionDescriptor;
-
-import org.apache.bval.util.Lazy;
-import org.apache.bval.util.LazyInt;
-import org.apache.bval.util.Validate;
-
-public class GroupConversion implements GroupConversionDescriptor {
- public static class Builder {
- private final Class<?> from;
-
- private Builder(Class<?> from) {
- this.from = from;
- }
-
- public GroupConversion to(Class<?> to) {
- return new GroupConversion(from, to);
- }
- }
-
- public static Builder from(Class<?> from) {
- return new Builder(from);
- }
-
- private final Class<?> from;
- private final Class<?> to;
- private final LazyInt hashCode;
- private final Lazy<String> toString;
-
- private GroupConversion(Class<?> from, Class<?> to) {
- super();
- this.from = Validate.notNull(from, "from");
- this.to = Validate.notNull(to, "to");
- this.hashCode = new LazyInt(() -> Objects.hash(this.from, this.to));
- this.toString = new Lazy<>(
- () -> String.format("%s from %s to %s", GroupConversion.class.getSimpleName(), this.from, this.to));
- }
-
- @Override
- public Class<?> getFrom() {
- return from;
- }
-
- @Override
- public Class<?> getTo() {
- return to;
- }
-
- @Override
- public boolean equals(Object obj) {
- return obj == this
- || Optional.ofNullable(obj).filter(GroupConversion.class::isInstance).map(GroupConversion.class::cast)
- .filter(gc -> Objects.equals(from, gc.from) && Objects.equals(to, gc.to)).isPresent();
- }
-
- @Override
- public int hashCode() {
- return hashCode.getAsInt();
- }
-
- @Override
- public String toString() {
- return toString.get();
- }
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/MetadataReader.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/MetadataReader.java b/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/MetadataReader.java
index ba49ed4..6f00495 100644
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/MetadataReader.java
+++ b/bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/MetadataReader.java
@@ -47,6 +47,7 @@ import javax.validation.metadata.PropertyDescriptor;
import javax.validation.metadata.Scope;
import org.apache.bval.jsr.ApacheValidatorFactory;
+import org.apache.bval.jsr.groups.GroupConversion;
import org.apache.bval.jsr.metadata.ContainerElementKey;
import org.apache.bval.jsr.metadata.EmptyBuilder;
import org.apache.bval.jsr.metadata.MetadataBuilder;
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/groups/GroupConversion.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/groups/GroupConversion.java b/bval-jsr/src/main/java/org/apache/bval/jsr/groups/GroupConversion.java
new file mode 100644
index 0000000..68babdf
--- /dev/null
+++ b/bval-jsr/src/main/java/org/apache/bval/jsr/groups/GroupConversion.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you 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 org.apache.bval.jsr.groups;
+
+import java.util.Objects;
+import java.util.Optional;
+
+import javax.validation.metadata.GroupConversionDescriptor;
+
+import org.apache.bval.util.Lazy;
+import org.apache.bval.util.LazyInt;
+import org.apache.bval.util.Validate;
+
+public class GroupConversion implements GroupConversionDescriptor {
+ public static class Builder {
+ private final Class<?> from;
+
+ private Builder(Class<?> from) {
+ this.from = from;
+ }
+
+ public GroupConversion to(Class<?> to) {
+ return new GroupConversion(from, to);
+ }
+ }
+
+ public static Builder from(Class<?> from) {
+ return new Builder(from);
+ }
+
+ private final Class<?> from;
+ private final Class<?> to;
+ private final LazyInt hashCode;
+ private final Lazy<String> toString;
+
+ private GroupConversion(Class<?> from, Class<?> to) {
+ super();
+ this.from = Validate.notNull(from, "from");
+ this.to = Validate.notNull(to, "to");
+ this.hashCode = new LazyInt(() -> Objects.hash(this.from, this.to));
+ this.toString = new Lazy<>(
+ () -> String.format("%s from %s to %s", GroupConversion.class.getSimpleName(), this.from, this.to));
+ }
+
+ @Override
+ public Class<?> getFrom() {
+ return from;
+ }
+
+ @Override
+ public Class<?> getTo() {
+ return to;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return obj == this
+ || Optional.ofNullable(obj).filter(GroupConversion.class::isInstance).map(GroupConversion.class::cast)
+ .filter(gc -> Objects.equals(from, gc.from) && Objects.equals(to, gc.to)).isPresent();
+ }
+
+ @Override
+ public int hashCode() {
+ return hashCode.getAsInt();
+ }
+
+ @Override
+ public String toString() {
+ return toString.get();
+ }
+}
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/groups/GroupConversionDescriptorImpl.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/groups/GroupConversionDescriptorImpl.java b/bval-jsr/src/main/java/org/apache/bval/jsr/groups/GroupConversionDescriptorImpl.java
deleted file mode 100644
index 6d45ced..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/groups/GroupConversionDescriptorImpl.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 org.apache.bval.jsr.groups;
-
-import javax.validation.ConstraintDeclarationException;
-import javax.validation.GroupSequence;
-import javax.validation.metadata.GroupConversionDescriptor;
-
-public class GroupConversionDescriptorImpl implements GroupConversionDescriptor {
- private final Class<?> to;
- private final Class<?> from;
-
- public GroupConversionDescriptorImpl(final Group from, final Group to) {
- this.from = from.getGroup();
- if (this.from.isAnnotationPresent(GroupSequence.class)) {
- throw new ConstraintDeclarationException("from() can't get a group sequence");
- }
- this.to = to.getGroup();
- }
-
- @Override
- public Class<?> getFrom() {
- return from;
- }
-
- @Override
- public Class<?> getTo() {
- return to;
- }
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/CompositeBuilder.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/CompositeBuilder.java b/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/CompositeBuilder.java
index 54ff0f8..0090790 100644
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/CompositeBuilder.java
+++ b/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/CompositeBuilder.java
@@ -38,7 +38,7 @@ import java.util.stream.Stream;
import javax.validation.metadata.Scope;
-import org.apache.bval.jsr.descriptor.GroupConversion;
+import org.apache.bval.jsr.groups.GroupConversion;
import org.apache.bval.jsr.util.ToUnmodifiable;
import org.apache.bval.util.Validate;
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/DualBuilder.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/DualBuilder.java b/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/DualBuilder.java
index 269d953..9524889 100644
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/DualBuilder.java
+++ b/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/DualBuilder.java
@@ -36,7 +36,7 @@ import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
-import org.apache.bval.jsr.descriptor.GroupConversion;
+import org.apache.bval.jsr.groups.GroupConversion;
import org.apache.bval.jsr.util.ToUnmodifiable;
import org.apache.bval.util.Validate;
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/EmptyBuilder.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/EmptyBuilder.java b/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/EmptyBuilder.java
index c95f6d7..7321784 100644
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/EmptyBuilder.java
+++ b/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/EmptyBuilder.java
@@ -30,7 +30,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
-import org.apache.bval.jsr.descriptor.GroupConversion;
+import org.apache.bval.jsr.groups.GroupConversion;
import org.apache.bval.util.Lazy;
import org.apache.bval.util.ObjectUtils;
import org.apache.bval.util.Validate;
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/MetadataBuilder.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/MetadataBuilder.java b/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/MetadataBuilder.java
index 7dbdcbc..ac6cc1a 100644
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/MetadataBuilder.java
+++ b/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/MetadataBuilder.java
@@ -31,7 +31,7 @@ import java.util.Set;
import javax.validation.metadata.Scope;
-import org.apache.bval.jsr.descriptor.GroupConversion;
+import org.apache.bval.jsr.groups.GroupConversion;
/**
* Common interface for populating the Bean Validation descriptors from various sources. Most implementations should
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/ReflectionBuilder.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/ReflectionBuilder.java b/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/ReflectionBuilder.java
index 12f62da..ea1a9bf 100644
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/ReflectionBuilder.java
+++ b/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/ReflectionBuilder.java
@@ -48,7 +48,7 @@ import javax.validation.groups.ConvertGroup;
import org.apache.bval.jsr.ApacheValidatorFactory;
import org.apache.bval.jsr.ConstraintAnnotationAttributes;
-import org.apache.bval.jsr.descriptor.GroupConversion;
+import org.apache.bval.jsr.groups.GroupConversion;
import org.apache.bval.jsr.util.AnnotationsManager;
import org.apache.bval.jsr.util.Methods;
import org.apache.bval.jsr.util.ToUnmodifiable;
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/XmlBuilder.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/XmlBuilder.java b/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/XmlBuilder.java
index bd71ccc..aef162d 100644
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/XmlBuilder.java
+++ b/bval-jsr/src/main/java/org/apache/bval/jsr/metadata/XmlBuilder.java
@@ -48,7 +48,7 @@ import javax.validation.ValidationException;
import javax.xml.bind.JAXBElement;
import org.apache.bval.jsr.ConstraintAnnotationAttributes;
-import org.apache.bval.jsr.descriptor.GroupConversion;
+import org.apache.bval.jsr.groups.GroupConversion;
import org.apache.bval.jsr.util.AnnotationsManager;
import org.apache.bval.jsr.util.ToUnmodifiable;
import org.apache.bval.jsr.xml.AnnotationProxyBuilder;
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/util/ClassHelper.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/util/ClassHelper.java b/bval-jsr/src/main/java/org/apache/bval/jsr/util/ClassHelper.java
deleted file mode 100644
index 73c82a6..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/util/ClassHelper.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.bval.jsr.util;
-
-import java.io.Serializable;
-import java.security.AccessController;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-/**
- * Common operations on classes that do not require an {@link AccessController}.
- *
- * @author Carlos Vara
- */
-public class ClassHelper {
- private static final Set<Class<?>> IGNORED_TYPES = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(null,Object.class,Serializable.class,Cloneable.class)));
-
- private ClassHelper() {
- // No instances please
- }
-
- /**
- * Fill the list with the full class/interface hierarchy of the given class.
- * List is ordered from the most to less specific.
- *
- * @param allClasses
- * The current list of classes in the hierarchy.
- * @param clazz
- */
- public static List<Class<?>> fillFullClassHierarchyAsList(List<Class<?>> allClasses, Class<?> clazz) {
- if (IGNORED_TYPES.contains(clazz) || allClasses.contains(clazz)) {
- return allClasses;
- }
- allClasses.add(clazz);
- fillFullClassHierarchyAsList(allClasses, clazz.getSuperclass());
- for (Class<?> subClass : clazz.getInterfaces()) {
- fillFullClassHierarchyAsList(allClasses, subClass);
- }
- return allClasses;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/util/ContainerElementNodeBuilderCustomizableContextImpl.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/util/ContainerElementNodeBuilderCustomizableContextImpl.java b/bval-jsr/src/main/java/org/apache/bval/jsr/util/ContainerElementNodeBuilderCustomizableContextImpl.java
index 13c3365..7459fdc 100644
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/util/ContainerElementNodeBuilderCustomizableContextImpl.java
+++ b/bval-jsr/src/main/java/org/apache/bval/jsr/util/ContainerElementNodeBuilderCustomizableContextImpl.java
@@ -74,5 +74,4 @@ public class ContainerElementNodeBuilderCustomizableContextImpl
context.addError(template, path);
return context;
}
-
}
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/util/EnumerationConverter.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/util/EnumerationConverter.java b/bval-jsr/src/main/java/org/apache/bval/jsr/util/EnumerationConverter.java
deleted file mode 100644
index 159fc43..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/util/EnumerationConverter.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.bval.jsr.util;
-
-import org.apache.commons.beanutils.Converter;
-
-/**
- * A {@code org.apache.commons.beanutils.Converter} implementation to handle
- * Enumeration type.
- */
-@Deprecated
-public final class EnumerationConverter implements Converter {
-
- /**
- * The static converter instance.
- */
- private static final EnumerationConverter INSTANCE = new EnumerationConverter();
-
- /**
- * Returns this converter instance.
- *
- * @return this converter instance.
- */
- public static EnumerationConverter getInstance() {
- return INSTANCE;
- }
-
- /**
- * This class can't be instantiated.
- */
- private EnumerationConverter() {
- // do nothing
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- @SuppressWarnings({ "unchecked", "rawtypes" })
- public Object convert(Class type, Object value) {
- if (!type.isEnum()) {
- throw new RuntimeException("Only enum types supported in this version!");
- }
-
- if (value == null) {
- throw new RuntimeException("Null values not supported in this version!");
- }
-
- if (String.class != value.getClass()) {
- throw new RuntimeException("Only java.lang.String values supported in this version!");
- }
-
- String stringValue = (String) value;
-
- final Class<Enum> enumClass = type;
- return Enum.valueOf(enumClass, stringValue);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/util/NodeBuilderDefinedContextImpl.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/util/NodeBuilderDefinedContextImpl.java b/bval-jsr/src/main/java/org/apache/bval/jsr/util/NodeBuilderDefinedContextImpl.java
index f695e84..5a20e08 100644
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/util/NodeBuilderDefinedContextImpl.java
+++ b/bval-jsr/src/main/java/org/apache/bval/jsr/util/NodeBuilderDefinedContextImpl.java
@@ -28,7 +28,7 @@ import org.apache.bval.jsr.job.ConstraintValidatorContextImpl;
*/
public final class NodeBuilderDefinedContextImpl
implements ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderDefinedContext {
- private final ConstraintValidatorContextImpl context;
+ private final ConstraintValidatorContextImpl<?> context;
private final String template;
private final PathImpl path;
@@ -38,7 +38,7 @@ public final class NodeBuilderDefinedContextImpl
* @param template
* @param path
*/
- public NodeBuilderDefinedContextImpl(ConstraintValidatorContextImpl contextImpl, String template, PathImpl path) {
+ public NodeBuilderDefinedContextImpl(ConstraintValidatorContextImpl<?> contextImpl, String template, PathImpl path) {
this.context = contextImpl;
this.template = template;
this.path = path;
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/util/ValidationContextTraversal.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/util/ValidationContextTraversal.java b/bval-jsr/src/main/java/org/apache/bval/jsr/util/ValidationContextTraversal.java
deleted file mode 100644
index f6e19c0..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/util/ValidationContextTraversal.java
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to you 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 org.apache.bval.jsr.util;
-
-import org.apache.bval.DynamicMetaBean;
-import org.apache.bval.jsr.JsrMetaBeanFactory;
-import org.apache.bval.jsr.UnknownPropertyException;
-import org.apache.bval.jsr.util.PathNavigation.CallbackProcedure;
-import org.apache.bval.model.MetaBean;
-import org.apache.bval.model.MetaProperty;
-import org.apache.bval.model.ValidationContext;
-import org.apache.bval.util.AccessStrategy;
-import org.apache.bval.util.IndexedAccess;
-import org.apache.bval.util.KeyedAccess;
-import org.apache.bval.util.PropertyAccess;
-import org.apache.bval.util.ObjectUtils;
-import org.apache.bval.util.reflection.TypeUtils;
-
-import java.lang.annotation.ElementType;
-import java.lang.reflect.Type;
-
-/**
- * {@link ValidationContext} traversal {@link CallbackProcedure}.
- *
- * @version $Rev: 1137074 $ $Date: 2011-06-17 18:20:30 -0500 (Fri, 17 Jun 2011) $
- */
-public class ValidationContextTraversal extends CallbackProcedure {
- private static class NullSafePropertyAccess extends AccessStrategy {
- private final PropertyAccess wrapped;
-
- /**
- * Create a new NullSafePropertyAccess instance.
- *
- * @param clazz
- * @param propertyName
- */
- public NullSafePropertyAccess(Class<?> clazz, String propertyName) {
- wrapped = PropertyAccess.getInstance(clazz, propertyName);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Object get(Object bean) {
- return bean == null ? null : wrapped.get(bean);
- }
-
- @Override
- public ElementType getElementType() {
- return wrapped.getElementType();
- }
-
- @Override
- public Type getJavaType() {
- return wrapped.getJavaType();
- }
-
- @Override
- public String getPropertyName() {
- return wrapped.getPropertyName();
- }
- }
-
- private final ValidationContext<?> validationContext;
- private Type type;
- private Class<?> rawType;
-
- /**
- * Create a new {@link ValidationContextTraversal} instance.
- *
- * @param validationContext
- */
- public ValidationContextTraversal(ValidationContext<?> validationContext) {
- this.validationContext = validationContext;
- init();
- }
-
- /**
- * Initialize from {@link ValidationContext}.
- */
- public void init() {
- this.rawType = validationContext.getMetaBean().getBeanClass();
- this.type = this.rawType;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void handleIndexOrKey(String token) {
- moveDownIfNecessary();
-
- AccessStrategy access;
- if (IndexedAccess.getJavaElementType(type) != null) {
- try {
- Integer index = token == null ? null : Integer.valueOf(token);
- access = new IndexedAccess(type, index);
- validationContext.setCurrentIndex(index);
- } catch (NumberFormatException e) {
- throw new UnknownPropertyException(String.format("Cannot parse %s as an array/iterable index", token),
- e);
- }
- } else if (KeyedAccess.getJavaElementType(type) != null) {
- access = new KeyedAccess(type, token);
- validationContext.setCurrentKey(token);
- } else {
- throw new UnknownPropertyException(String.format("Cannot determine index/key type for %s", type));
- }
- Object value = validationContext.getBean();
- Object child = value == null ? null : access.get(value);
- setType(child == null ? access.getJavaType() : child.getClass());
- validationContext.setBean(child,
- validationContext.getMetaBean().resolveMetaBean(child == null ? rawType : child));
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void handleProperty(String token) {
- moveDownIfNecessary();
-
- MetaBean metaBean = validationContext.getMetaBean();
-
- if (metaBean instanceof DynamicMetaBean) {
- metaBean = metaBean.resolveMetaBean(ObjectUtils.defaultIfNull(validationContext.getBean(), rawType));
- validationContext.setMetaBean(metaBean);
- }
- MetaProperty mp = metaBean.getProperty(token);
- if (mp == null) {
- // TODO this could indicate a property hosted on a superclass; should we shunt the context traversal down a path based on that type?
-
- PropertyAccess access = PropertyAccess.getInstance(rawType, token);
- if (access.isKnown()) {
- // add heretofore unknown, but valid, property on the fly:
- mp = JsrMetaBeanFactory.addMetaProperty(metaBean, access);
- } else {
- throw new UnknownPropertyException("unknown property '" + token + "' in " + metaBean.getId());
- }
- }
- validationContext.setMetaProperty(mp);
- setType(mp.getType());
- }
-
- /**
- * If we currently have a property, navigate the context such that the property becomes the bean, in preparation for
- * another property.
- */
- public void moveDownIfNecessary() {
- MetaProperty mp = validationContext.getMetaProperty();
- if (mp != null) {
- if (mp.getMetaBean() == null) {
- throw new UnknownPropertyException(
- String.format("Property %s.%s is not cascaded", mp.getParentMetaBean().getId(), mp.getName()));
- }
- validationContext.moveDown(mp,
- new NullSafePropertyAccess(validationContext.getMetaBean().getBeanClass(), mp.getName()));
- }
- }
-
- /**
- * Set the type of the expression processed thus far.
- *
- * @param type
- */
- protected void setType(Type type) {
- this.rawType = TypeUtils.getRawType(type, this.type);
- this.type = type;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void handleGenericInIterable() {
- throw new UnsupportedOperationException("Cannot navigate a ValidationContext to []");
- }
-
- /**
- * @return the type
- */
- public Type getType() {
- return type;
- }
-
- /**
- * @return the rawType
- */
- public Class<?> getRawType() {
- return rawType;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void complete() {
- super.complete();
- if (validationContext.getMetaProperty() != null) {
- return;
- }
- if (validationContext.getMetaBean() instanceof DynamicMetaBean) {
- validationContext.setMetaBean(validationContext.getMetaBean()
- .resolveMetaBean(ObjectUtils.defaultIfNull(validationContext.getBean(), rawType)));
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/xml/AnnotationIgnores.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/xml/AnnotationIgnores.java b/bval-jsr/src/main/java/org/apache/bval/jsr/xml/AnnotationIgnores.java
deleted file mode 100644
index 3ac39c4..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/xml/AnnotationIgnores.java
+++ /dev/null
@@ -1,202 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.bval.jsr.xml;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Member;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Description: This class instantiated during the parsing of the XML configuration
- * data and keeps track of the annotations which should be ignored.<br/>
- */
-public final class AnnotationIgnores {
-
- private static final Logger log = Logger.getLogger(AnnotationIgnores.class.getName());
-
- /**
- * Keeps track whether the 'ignore-annotations' flag is set on bean level in the
- * xml configuration.
- * If 'ignore-annotations' is not specified: default = true
- */
- private final Map<Class<?>, Boolean> ignoreAnnotationDefaults = new HashMap<Class<?>, Boolean>();
-
- /**
- * Keeps track of explicitly excluded members (fields and properties) for a given class.
- * If a member appears in
- * the list mapped to a given class 'ignore-annotations' was explicitly set to
- * <code>true</code> in the configuration
- * for this class.
- */
- private final Map<Class<?>, Map<Member, Boolean>> ignoreAnnotationOnMember =
- new HashMap<Class<?>, Map<Member, Boolean>>();
-
- private final Map<Class<?>, Boolean> ignoreAnnotationOnClass = new HashMap<Class<?>, Boolean>();
-
- private final Map<Class<?>, Map<Member, Map<Integer, Boolean>>> ignoreAnnotationOnParameter =
- new HashMap<Class<?>, Map<Member, Map<Integer, Boolean>>>();
- private final Map<Member, Boolean> ignoreAnnotationOnReturn = new HashMap<Member, Boolean>();
- private final Map<Member, Boolean> ignoreAnnotationOnCrossParameter = new HashMap<Member, Boolean>();
-
- /**
- * Record the ignore state for a particular annotation type.
- * @param clazz
- * @param b, default true if null
- */
- public void setDefaultIgnoreAnnotation(Class<?> clazz, Boolean b) {
- ignoreAnnotationDefaults.put(clazz, b == null || b.booleanValue());
- }
-
- /**
- * Learn whether the specified annotation type should be ignored.
- * @param clazz
- * @return boolean
- */
- public boolean getDefaultIgnoreAnnotation(Class<?> clazz) {
- return ignoreAnnotationDefaults.containsKey(clazz) && ignoreAnnotationDefaults.get(clazz);
- }
-
- /**
- * Ignore annotations on a particular {@link Member} of a class.
- * @param member
- */
- public void setIgnoreAnnotationsOnMember(Member member, boolean value) {
- Class<?> beanClass = member.getDeclaringClass();
- Map<Member, Boolean> memberList = ignoreAnnotationOnMember.get(beanClass);
- if (memberList == null) {
- memberList = new HashMap<Member, Boolean>();
- ignoreAnnotationOnMember.put(beanClass, memberList);
- }
- memberList.put(member, value);
- }
-
- /**
- * Learn whether annotations should be ignored on a particular {@link Member} of a class.
- * @param member
- * @return boolean
- */
- public boolean isIgnoreAnnotations(final Member member) {
- final Class<?> clazz = member.getDeclaringClass();
- final Map<Member, Boolean> ignoreAnnotationForMembers = ignoreAnnotationOnMember.get(clazz);
- if (ignoreAnnotationForMembers != null && ignoreAnnotationForMembers.containsKey(member)) {
- final boolean value = ignoreAnnotationForMembers.get(member);
- if (value) {
- logMessage(member, clazz);
- }
- return value;
- }
-
- final boolean ignoreAnnotation = getDefaultIgnoreAnnotation(clazz);
- if (ignoreAnnotation) {
- logMessage(member, clazz);
- }
- return ignoreAnnotation;
- }
-
- public void setIgnoreAnnotationsOnParameter(final Member method, final int i, final boolean value) {
- final Class<?> beanClass = method.getDeclaringClass();
- Map<Member, Map<Integer, Boolean>> memberList = ignoreAnnotationOnParameter.get(beanClass);
- if (memberList == null) {
- memberList = new HashMap<Member, Map<Integer, Boolean>>();
- ignoreAnnotationOnParameter.put(beanClass, memberList);
- }
- Map<Integer, Boolean> indexes = memberList.get(method);
- if (indexes == null) {
- indexes = new HashMap<Integer, Boolean>();
- memberList.put(method, indexes);
- }
- indexes.put(i, value);
- }
-
- public boolean isIgnoreAnnotationOnParameter(final Member m, final int i) {
- final Map<Member, Map<Integer, Boolean>> members = ignoreAnnotationOnParameter.get(m.getDeclaringClass());
- if (members != null) {
- final Map<Integer, Boolean> indexes = members.get(m);
- if (indexes != null && indexes.containsKey(i)) {
- return indexes.get(i);
- }
- }
- return false;
- }
-
- private void logMessage(Member member, Class<?> clazz) {
- String type;
- if (member instanceof Field) {
- type = "Field";
- } else {
- type = "Property";
- }
- log.log(Level.FINEST, String.format("%s level annotations are getting ignored for %s.%s", type, clazz.getName(),
- member.getName()));
- }
-
- /**
- * Record the ignore state of a particular class.
- * @param clazz
- * @param b
- */
- public void setIgnoreAnnotationsOnClass(Class<?> clazz, boolean b) {
- ignoreAnnotationOnClass.put(clazz, b);
- }
-
- /**
- * Learn whether annotations should be ignored for a given class.
- * @param clazz to check
- * @return boolean
- */
- public boolean isIgnoreAnnotations(Class<?> clazz) {
- boolean ignoreAnnotation;
- if (ignoreAnnotationOnClass.containsKey(clazz)) {
- ignoreAnnotation = ignoreAnnotationOnClass.get(clazz);
- } else {
- ignoreAnnotation = getDefaultIgnoreAnnotation(clazz);
- }
- if (ignoreAnnotation) {
- log.log(Level.FINEST, String.format("Class level annotation are getting ignored for %s", clazz.getName()));
- }
- return ignoreAnnotation;
- }
-
- public void setIgnoreAnnotationOnReturn(final Member method, final boolean value) {
- ignoreAnnotationOnReturn.put(method, value);
- }
-
- public boolean isIgnoreAnnotationOnReturn(final Member m) {
- final Boolean value = ignoreAnnotationOnReturn.get(m);
- if (value != null) {
- return value;
- }
- return false;
- }
-
- public void setIgnoreAnnotationOnCrossParameter(final Member method, final boolean value) {
- ignoreAnnotationOnCrossParameter.put(method, value);
- }
-
- public boolean isIgnoreAnnotationOnCrossParameter(final Member m) {
- final Boolean value = ignoreAnnotationOnCrossParameter.get(m);
- if (value != null) {
- return value;
- }
- return false;
- }
-}