Search in sources :

Example 1 with ExtensionLoadingDelegate

use of org.mule.runtime.extension.api.loader.ExtensionLoadingDelegate in project mule by mulesoft.

the class CraftedExtensionModelLoader method declareExtension.

@Override
protected void declareExtension(ExtensionLoadingContext context) {
    Class<?> delegateType = getDelegateType(context, context.getExtensionClassLoader());
    if (!ExtensionLoadingDelegate.class.isAssignableFrom(delegateType)) {
        throw new IllegalArgumentException(format("Property '%s' was expected to point to an implementation of the '%s', but '%s' was found instead", TYPE_PROPERTY_NAME, ExtensionLoadingDelegate.class.getName(), delegateType.getClass().getName()));
    }
    if (!isInstantiable(delegateType, new ReflectionCache())) {
        throw new IllegalArgumentException(format("Type '%s' is not instantiable. A concrete class with a public default constructor was expected", delegateType.getName()));
    }
    ExtensionLoadingDelegate delegate;
    try {
        delegate = (ExtensionLoadingDelegate) ClassUtils.instantiateClass(delegateType);
    } catch (Throwable e) {
        throw new MuleRuntimeException(createStaticMessage(format("Could not instantiate type '%s'", delegateType.getName())), e);
    }
    delegate.accept(context.getExtensionDeclarer(), context);
}
Also used : ReflectionCache(org.mule.runtime.module.extension.internal.util.ReflectionCache) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ExtensionLoadingDelegate(org.mule.runtime.extension.api.loader.ExtensionLoadingDelegate)

Aggregations

MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)1 ExtensionLoadingDelegate (org.mule.runtime.extension.api.loader.ExtensionLoadingDelegate)1 ReflectionCache (org.mule.runtime.module.extension.internal.util.ReflectionCache)1