Example usage for org.springframework.cglib.core ReflectUtils findConstructor

List of usage examples for org.springframework.cglib.core ReflectUtils findConstructor

Introduction

In this page you can find the example usage for org.springframework.cglib.core ReflectUtils findConstructor.

Prototype

public static Constructor findConstructor(String desc, ClassLoader loader) 

Source Link

Usage

From source file:com.kugou.limos.config.AbstractInterfaceConfig.java

protected void checkStubAndMock(Class<?> interfaceClass) {
    if (ConfigUtils.isNotEmpty(local)) {
        Class<?> localClass = ConfigUtils.isDefault(local)
                ? ReflectUtils.forName(interfaceClass.getName() + "Local")
                : ReflectUtils.forName(local);
        if (!interfaceClass.isAssignableFrom(localClass)) {
            throw new IllegalStateException("The local implemention class " + localClass.getName()
                    + " not implement interface " + interfaceClass.getName());
        }//ww w .  jav a 2s .c  om
        try {
            ReflectUtils.findConstructor(localClass, interfaceClass);
        } catch (NoSuchMethodException e) {
            throw new IllegalStateException("No such constructor \"public " + localClass.getSimpleName() + "("
                    + interfaceClass.getName() + ")\" in local implemention class " + localClass.getName());
        }
    }
    if (ConfigUtils.isNotEmpty(stub)) {
        Class<?> localClass = ConfigUtils.isDefault(stub)
                ? ReflectUtils.forName(interfaceClass.getName() + "Stub")
                : ReflectUtils.forName(stub);
        if (!interfaceClass.isAssignableFrom(localClass)) {
            throw new IllegalStateException("The local implemention class " + localClass.getName()
                    + " not implement interface " + interfaceClass.getName());
        }
        try {
            ReflectUtils.findConstructor(localClass, interfaceClass);
        } catch (NoSuchMethodException e) {
            throw new IllegalStateException("No such constructor \"public " + localClass.getSimpleName() + "("
                    + interfaceClass.getName() + ")\" in local implemention class " + localClass.getName());
        }
    }
    if (ConfigUtils.isNotEmpty(mock)) {
        if (mock.startsWith(Constants.RETURN_PREFIX)) {
            String value = mock.substring(Constants.RETURN_PREFIX.length());
            try {
                MockInvoker.parseMockValue(value);
            } catch (Exception e) {
                throw new IllegalStateException(
                        "Illegal mock json value in <dubbo:service ... mock=\"" + mock + "\" />");
            }
        } else {
            Class<?> mockClass = ConfigUtils.isDefault(mock)
                    ? ReflectUtils.forName(interfaceClass.getName() + "Mock")
                    : ReflectUtils.forName(mock);
            if (!interfaceClass.isAssignableFrom(mockClass)) {
                throw new IllegalStateException("The mock implemention class " + mockClass.getName()
                        + " not implement interface " + interfaceClass.getName());
            }
            try {
                mockClass.getConstructor(new Class<?>[0]);
            } catch (NoSuchMethodException e) {
                throw new IllegalStateException("No such empty constructor \"public "
                        + mockClass.getSimpleName() + "()\" in mock implemention class " + mockClass.getName());
            }
        }
    }
}