All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jn.sqlhelper.datasource.key.parser.AbstractDataSourceKeyAnnotationParser Maven / Gradle / Ivy

There is a newer version: 3.6.16
Show newest version
package com.jn.sqlhelper.datasource.key.parser;

import com.jn.langx.annotation.NonNull;
import com.jn.langx.util.Preconditions;
import com.jn.langx.util.reflect.Reflects;
import com.jn.sqlhelper.datasource.key.DataSourceKey;

import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;

public abstract class AbstractDataSourceKeyAnnotationParser implements DataSourceKeyAnnotationParser {
    @Override
    public DataSourceKey parse(AnnotatedElement annotatedElement) {
        Preconditions.checkNotNull(annotatedElement);

        if (!Reflects.hasAnnotation(annotatedElement, getAnnotation())) {
            if (annotatedElement instanceof Method) {
                Method method = (Method) annotatedElement;
                Class clazz = method.getDeclaringClass();
                return parse(clazz);
            }
            return null;
        }
        if (annotatedElement instanceof Method || annotatedElement instanceof Class) {
            A annotation = Reflects.getAnnotation(annotatedElement, getAnnotation());
            return internalParse(annotation);
        }
        return null;
    }

    protected abstract DataSourceKey internalParse(@NonNull A annotation);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy