@@ -0,0 +1,2996 @@
+/*%0A * Copyright 2017, TeamDev Ltd. All rights reserved.%0A *%0A * Redistribution and use in source and/or binary forms, with or without%0A * modification, must retain the above copyright notice and the following%0A * disclaimer.%0A *%0A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS%0A * %22AS IS%22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT%0A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR%0A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT%0A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,%0A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT%0A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,%0A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY%0A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT%0A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE%0A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.%0A */%0A%0Apackage org.spine3.server.validate;%0A%0Aimport com.google.common.base.Optional;%0Aimport com.google.protobuf.Descriptors.FieldDescriptor;%0Aimport com.google.protobuf.Message;%0Aimport org.spine3.base.FieldPath;%0Aimport org.spine3.base.Stringifier;%0Aimport org.spine3.base.StringifierRegistry;%0Aimport org.spine3.validate.ConstraintViolation;%0Aimport org.spine3.validate.ConstraintViolationThrowable;%0A%0Aimport java.util.List;%0A%0A/**%0A * @author Illia Shepilov%0A */%0Apublic abstract class CommonValidatingBuilder%3CT extends Message%3E implements ValidatingBuilder%3CT%3E %7B%0A%0A    private final StringifierRegistry registry = StringifierRegistry.getInstance();%0A%0A    public %3CV%3E V getConvertedValue(Class%3CV%3E valueClass, String value) %7B%0A        final Stringifier%3CV%3E stringifier = getStringifier(valueClass);%0A        final V convertedValue = stringifier.reverse()%0A                                            .convert(value);%0A        return convertedValue;%0A    %7D%0A%0A    private %3CV%3E Stringifier%3CV%3E getStringifier(Class%3CV%3E toValueClass) %7B%0A        final Optional%3CStringifier%3CV%3E%3E stringifierOptional = registry.get(toValueClass);%0A        if (stringifierOptional.isPresent()) %7B%0A            return stringifierOptional.get();%0A        %7D%0A        //TODO:2017-03-02:illiashepilov: Think about necessary exception body.%0A        throw new StringifierNotFoundException();%0A    %7D%0A%0A    public %3CV%3E void validate(FieldDescriptor descriptor, V fieldValue, String valueName)%0A            throws ConstraintViolationThrowable %7B%0A        final FieldPath fieldPath = FieldPath.newBuilder()%0A                                             .addFieldName(valueName)%0A                                             .build();%0A        final FieldValidator%3C?%3E validator =%0A                FieldValidatorFactory.createStrict(descriptor, fieldValue, fieldPath);%0A        final List%3CConstraintViolation%3E constraints = validator.validate();%0A        if (!constraints.isEmpty()) %7B%0A            throw new ConstraintViolationThrowable(constraints);%0A        %7D%0A    %7D%0A%7D%0A

Create `CommonValidatingBuilder`.