package fi.vincit.jmobster.processor;
/*
 * Copyright 2012 Juha Siponen
 *
 * 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.
*/

import java.lang.annotation.Annotation;
import fi.vincit.jmobster.exception.InvalidType;

public abstract class BaseValidationAnnotationProcessor implements ValidationAnnotationProcessor {
    private String requiredType;
    private Class[] supportedAnnotations = new Class[0];

    protected BaseValidationAnnotationProcessor() {
    }

    protected BaseValidationAnnotationProcessor( String requiredType ) {
        this.requiredType = requiredType;
    }

    protected BaseValidationAnnotationProcessor( String requiredType, Class... annotations ) {
        this(requiredType);
        setSupportedAnnotations(annotations);
    }

    protected BaseValidationAnnotationProcessor( Class... annotations ) {
        this();
        setSupportedAnnotations(annotations);
    }

    @Override
    public String requiredType() {
        return requiredType;
    }

    @Override
    public boolean requiresType() {
        return requiredType() != null;
    }

    @Override
    public void validateType( String type ) {
        if( requiresType() ) {
            if( !requiredType().equals(type) ) {
                throw new InvalidType("Required type <" + requiredType() + "> given type <" + type + ">");
            }
        }
    }

    @Override
    public Class[] getGroups(Annotation annotation) {
        Class[] groups = getGroupsInternal(annotation);
        return groups != null ? groups : new Class[0];
    }

    protected abstract Class[] getGroupsInternal(Annotation annotation);

    @Override
    public boolean hasGroups(Annotation annotation) {
        Class[] groups = getGroups(annotation);
        return groups != null && groups.length > 0;
    }

    protected void setSupportedAnnotations(Class... annotations) {
        supportedAnnotations = annotations;
    }
    @Override
    public Class[] getSupportedAnnotations() {
        return supportedAnnotations;
    }

}

@@ -911,189 +911,8 @@
 %5D;%0A%0A
-    protected BaseValidationAnnotationProcessor() %7B%0A    %7D%0A%0A    protected BaseValidationAnnotationProcessor( String requiredType ) %7B%0A        this.requiredType = requiredType;%0A    %7D%0A%0A
     
@@ -1014,17 +1014,17 @@
     this
-(
+.
 required
@@ -1027,17 +1027,31 @@
 iredType
-)
+ = requiredType
 ;%0A      
@@ -1175,24 +1175,8 @@
 ) %7B%0A
-        this();%0A
     

Remove dangerous constructors