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

org.jvault.beanreader.ClassReader Maven / Gradle / Ivy

package org.jvault.beanreader;

import org.jvault.annotation.InternalBean;
import org.jvault.exceptions.NoDefinedInternalBeanException;
import org.jvault.metadata.InternalAPI;

import java.lang.reflect.Modifier;

@InternalAPI
final class ClassReader {

    private static final ClassReader INSTANCE = new ClassReader();

    private ClassReader(){}

    static ClassReader getInstance(){
        return ClassReader.INSTANCE;
    }

    Class readClass(String classSrc){
        Class cls = getClassForSrc(classSrc);
        throwIfModifierInterface(cls);
        throwIfIsNotAnnotatedInternalBean(cls);
        return cls;
    }

    private Class getClassForSrc(String src){
        try{
            return Class.forName(src);
        } catch (ClassNotFoundException CNFE){
            throw new IllegalStateException("Can not find Class \"" + src + "\"");
        }
    }

    private void throwIfModifierInterface(Class cls){
        if(Modifier.isAbstract(cls.getModifiers()) || Modifier.isInterface(cls.getModifiers()))
            throw new IllegalStateException("\"@InternalBean\" annotation Could not marked \"jnterface\" or \"abstract\"");
    }

    private void throwIfIsNotAnnotatedInternalBean(Class cls) {
        if (cls.getDeclaredAnnotation(InternalBean.class) == null)
            throw new NoDefinedInternalBeanException(cls.getSimpleName());
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy