Example usage for org.springframework.util Assert isAssignable

List of usage examples for org.springframework.util Assert isAssignable

Introduction

In this page you can find the example usage for org.springframework.util Assert isAssignable.

Prototype

public static void isAssignable(Class<?> superType, Class<?> subType) 

Source Link

Document

Assert that superType.isAssignableFrom(subType) is true .

Usage

From source file:org.jnap.core.bean.model.PersistentEnumFactory.java

/**
 * //  w ww.j  av a 2  s  .  c  om
 * @param value
 * @param enumType
 * @return
 */
public static <E extends Enum, V extends Serializable> E get(V value, Class<E> enumType) {
    Assert.isAssignable(PersistentEnum.class, enumType);
    E enumMatch = null;
    for (E enumValue : enumType.getEnumConstants()) {
        if (((PersistentEnum) enumValue).getValue().equals(value)) {
            enumMatch = enumValue;
            break;
        }
    }
    return enumMatch;
}

From source file:ws.antonov.config.api.consumer.ConfigClientInvocationHandler.java

public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
    ConfigParamsBuilder.ConfigParamsMap configParams = generateConfigParams(method, objects);
    Assert.isAssignable(Message.class, method.getReturnType());
    return configClient.getConfig((Class<Message>) method.getReturnType(), configParams);
}

From source file:ua.com.manometer.jasperreports.ConfigurableJasperReportsView.java

/**
 * Set the {@link JRExporter} implementation <code>Class</code> to use. Throws
 * {@link IllegalArgumentException} if the <code>Class</code> doesn't implement
 * {@link JRExporter}. Required setting, as it does not have a default.
 *///  www  .  j av a 2 s  . c o  m
public void setExporterClass(Class<? extends JRExporter> exporterClass) {
    Assert.isAssignable(JRExporter.class, exporterClass);
    this.exporterClass = exporterClass;
}

From source file:ee.kovmen.xtee.consumer.CustomTransformerObjectSupport.java

/**
 * Specify the {@code TransformerFactory} class to use.
 *//*from  www .  ja va 2  s. com*/
public void setTransformerFactoryClass(Class transformerFactoryClass) {
    Assert.isAssignable(TransformerFactory.class, transformerFactoryClass);
    this.transformerFactoryClass = transformerFactoryClass;
}

From source file:io.gravitee.management.idp.core.plugin.IdentityProviderPluginHandler.java

@Override
public void handle(Plugin plugin) {
    try {/*from  www .j a v a 2s . com*/
        ClassLoader classloader = pluginClassLoaderFactory.getOrCreateClassLoader(plugin,
                this.getClass().getClassLoader());

        final Class<?> identityProviderClass = classloader.loadClass(plugin.clazz());
        LOGGER.info("Register a new identity provider plugin: {} [{}]", plugin.id(), plugin.clazz());

        Assert.isAssignable(IdentityProvider.class, identityProviderClass);

        IdentityProvider identityIdentityProvider = createInstance(
                (Class<IdentityProvider>) identityProviderClass);
        identityProviderManager.register(new IdentityProviderDefinition(identityIdentityProvider, plugin));
    } catch (Exception iae) {
        LOGGER.error("Unexpected error while create identity provider instance", iae);
    }
}

From source file:org.codehaus.grepo.procedure.repository.GenericProcedureRepositoryFactoryBean.java

/**
 * {@inheritDoc}//  w w w. ja  v a  2s .  c  o  m
 */
@Override
protected void validateTargetClass() {
    super.validateTargetClass();
    Assert.isAssignable(GenericProcedureRepositorySupport.class, getTargetClass());
}

From source file:org.codehaus.grepo.query.commons.repository.GenericQueryRepositoryFactoryBean.java

/**
 * {@inheritDoc}//from ww w  .j  a v a 2  s  .co  m
 */
@Override
protected void validateTargetClass() {
    super.validateTargetClass();
    Assert.isAssignable(GenericQueryRepositorySupport.class, getTargetClass());
}

From source file:org.motechproject.server.event.annotations.MotechListenerNamedParametersProxy.java

@Override
public void callHandler(MotechEvent event) {
    List<Object> args = new ArrayList<Object>();
    Class<?>[] paramTypes = method.getParameterTypes();
    Annotation[][] paramAnnotations = method.getParameterAnnotations();
    Assert.isTrue(paramTypes.length == paramAnnotations.length);
    for (int i = 0; i < paramTypes.length; i++) {
        Class<?> t = paramTypes[i];
        Assert.notEmpty(paramAnnotations[i], "MotechParam(name) annotation is required for each parameter.");
        //TODO now assuming only MotechParam annotation is present...
        Assert.isAssignable(MotechParam.class, paramAnnotations[i][0].getClass());
        MotechParam annotation = (MotechParam) paramAnnotations[i][0];
        Object arg = event.getParameters().get(annotation.value());
        Assert.notNull(arg, String.format("parameter #%d with name:\"%s\" not found or null prameter passed.",
                i, annotation.value()));
        Assert.isAssignable(t, arg.getClass(), String.format("Parameter #%d expected subtypes of %s passed %s.",
                i, t.getName(), arg.getClass().getName()));
        args.add(arg);/* ww  w.  ja v a 2  s.co m*/
    }
    ReflectionUtils.invokeMethod(method, bean, args.toArray());

}

From source file:io.gravitee.gateway.repository.plugins.RepositoryPluginHandler.java

@Override
public void handle(Plugin plugin) {
    try {//from  ww w  .  j a  v  a  2s  .  co  m
        ClassLoader classloader = pluginClassLoaderFactory.getOrCreateClassLoader(plugin,
                this.getClass().getClassLoader());

        final Class<?> repositoryClass = classloader.loadClass(plugin.clazz());
        LOGGER.info("Register a new repository plugin: {} [{}]", plugin.id(), plugin.clazz());

        Assert.isAssignable(Repository.class, repositoryClass);

        Repository repository = createInstance((Class<Repository>) repositoryClass);
        for (Scope scope : repository.scopes()) {
            if (!repositories.containsKey(scope)) {
                String requiredRepositoryType = repositoryTypeByScope.get(scope);

                // Load only repository plugin for a given scope (provided in the configuration)
                if (repository.type().equalsIgnoreCase(requiredRepositoryType)) {
                    LOGGER.info("Repository [{}] loaded by {}", scope, repository.type());

                    // Not yet loaded, let's mount the repository in application context
                    try {
                        ApplicationContext repoApplicationContext = pluginContextFactory
                                .create(new AnnotationBasedPluginContextConfigurer(plugin) {
                                    @Override
                                    public Set<Class<?>> configurations() {
                                        return Collections.singleton(repository.configuration(scope));
                                    }
                                });

                        registerRepositoryDefinitions(repository, repoApplicationContext);
                        repositories.put(scope, repository);
                    } catch (Exception iae) {
                        LOGGER.error("Unexpected error while creating context for repository instance", iae);
                        pluginContextFactory.remove(plugin);
                    }
                } else {
                    LOGGER.debug("Scoped repository [{}] must be loaded by {}. Skipping registration", scope,
                            requiredRepositoryType);
                }
            } else {
                LOGGER.warn("Repository scope {} already loaded by {}", scope, repositories.get(scope));
            }
        }
    } catch (Exception iae) {
        LOGGER.error("Unexpected error while create repository instance", iae);
    }
}

From source file:io.gravitee.management.repository.plugins.RepositoryPluginHandler.java

@Override
public void handle(Plugin plugin) {
    try {/*from  w ww.  ja v a 2  s. c  o  m*/
        ClassLoader classloader = pluginClassLoaderFactory.getOrCreateClassLoader(plugin,
                this.getClass().getClassLoader());

        final Class<?> repositoryClass = classloader.loadClass(plugin.clazz());
        LOGGER.info("Register a new repository: {} [{}]", plugin.id(), plugin.clazz());

        Assert.isAssignable(Repository.class, repositoryClass);

        Repository repository = createInstance((Class<Repository>) repositoryClass);
        Collection<Scope> scopes = scopeByRepositoryType.getOrDefault(repository.type(),
                Collections.EMPTY_LIST);

        for (Scope scope : scopes) {
            if (!repositories.containsKey(scope)) {
                // Not yet loaded, let's mount the repository in application context
                try {
                    ApplicationContext applicationContext = pluginContextFactory
                            .create(new AnnotationBasedPluginContextConfigurer(plugin) {
                                @Override
                                public Set<Class<?>> configurations() {
                                    return Collections.singleton(repository.configuration(scope));
                                }
                            });

                    registerRepositoryDefinitions(repository, applicationContext);
                    repositories.put(scope, repository);
                } catch (Exception iae) {
                    LOGGER.error("Unexpected error while creating context for repository instance", iae);
                    pluginContextFactory.remove(plugin);
                }

            } else {
                LOGGER.warn("Repository scope {} already loaded by {}", scope, repositories.get(scope));
            }
        }
    } catch (Exception iae) {
        LOGGER.error("Unexpected error while create repository instance", iae);
    }
}