Example usage for org.springframework.util ClassUtils forName

List of usage examples for org.springframework.util ClassUtils forName

Introduction

In this page you can find the example usage for org.springframework.util ClassUtils forName.

Prototype

public static Class<?> forName(String name, @Nullable ClassLoader classLoader)
        throws ClassNotFoundException, LinkageError 

Source Link

Document

Replacement for Class.forName() that also returns Class instances for primitives (e.g.

Usage

From source file:net.paslavsky.springrest.SpringRestClientFactoryBean.java

private static Class<?> getClientClass(String clientClassName) {
    Assert.hasText(clientClassName,//w w  w .ja  v a  2s  .  com
            "Argument 'clientClassName' must be a name of the class from default classpath");
    try {
        return ClassUtils.forName(clientClassName, ClassUtils.getDefaultClassLoader());
    } catch (ClassNotFoundException e) {
        throw new SpringRestClientConfigurationException("Wrong class name of the REST client", e);
    }
}

From source file:com.bstek.dorado.spring.ImportDoradoElementParser.java

public BeanDefinition parse(Element element, ParserContext parserContext) {
    try {//  w  w  w.  j  av a 2s . c o m
        @SuppressWarnings("unchecked")
        Class<DoradoAppContextImporter> cl = (Class<DoradoAppContextImporter>) ClassUtils
                .forName(DEFAULT_IMPORTER, getClass().getClassLoader());
        DoradoAppContextImporter importer = cl.newInstance();
        importer.importDoradoAppContext(element, parserContext);
    } catch (Exception e) {
        logger.error(e, e);
    }
    return null;
}

From source file:sf.wicklet.gwt.site.server.db.H2Configurator.java

@SuppressWarnings("unchecked")
public static synchronized H2Configurator getInstance(final String dbpath) throws ClassNotFoundException {
    final H2Configurator ret = new H2Configurator((Class<? extends Driver>) ClassUtils.forName("org.h2.Driver",
            H2Configurator.class.getClassLoader()), dbpath);
    return ret;/*w  w w . j a  va  2  s.  c o  m*/
}

From source file:com.oembedler.moon.graphql.engine.GraphQLSchemaDiscoverer.java

public static Set<Class<?>> findSchemaClasses(final String basePackage) throws ClassNotFoundException {

    Set<Class<?>> initialEntitySet = new HashSet<Class<?>>();

    if (StringUtils.hasText(basePackage)) {
        ClassPathScanningCandidateComponentProvider componentProvider = new ClassPathScanningCandidateComponentProvider(
                false);// w  w w  .  j  av a 2 s  .  co  m
        componentProvider.addIncludeFilter(new AnnotationTypeFilter(GRAPH_QL_SCHEMA_ANNOTATION));

        for (BeanDefinition candidate : componentProvider.findCandidateComponents(basePackage)) {
            initialEntitySet.add(ClassUtils.forName(candidate.getBeanClassName(),
                    GraphQLSchemaDiscoverer.class.getClassLoader()));
        }
    }
    return initialEntitySet;
}

From source file:fr.xebia.xke.test.jdbc.datasource.H2InitializingDriverManagerDataSource.java

/**
 * Implementation of <code>InitializingBean</code>
 *///w w  w  .ja  va  2 s .c o  m
@Override
@SuppressWarnings("unchecked")
public void afterPropertiesSet() throws Exception {
    if (getDriver() == null && !StringUtils.hasText(driverClassName)) {
        setDriverClass((Class<? extends Driver>) ClassUtils.forName(DRIVER_CLASS_NAME,
                ClassUtils.getDefaultClassLoader()));
    }

    if (!StringUtils.hasText(getUrl())) {
        setUrl(URL);
    }

    if (!StringUtils.hasText(getUsername())) {
        setUsername(USERNAME);
    }

    if (!StringUtils.hasText(getPassword())) {
        setPassword(PASSWORD);
    }

    super.afterPropertiesSet();
}

From source file:be.vlaanderen.sesam.proxy.internal.http.actors.WfsGetFeatureLoggingActorFactory.java

@SuppressWarnings("unchecked")
public void afterPropertiesSet() throws Exception {
    if (implementation == null || "".equals(implementation))
        implementation = "be.vlaanderen.sesam.proxy.internal.http.actors.WfsGetFeatureLoggingActor";

    Class<? extends HttpInboundActor> impl = (Class<? extends HttpInboundActor>) ClassUtils
            .forName(implementation, null);

    instance = (HttpInboundActor) TypedActor.newInstance(HttpInboundActor.class, impl, timeout);

    log.debug(" - Created WfsGetFeatureLoggingActor Actor instance.");
}

From source file:com.agileapes.motorex.cli.value.impl.SpringValueReaderContext.java

@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    final String[] names = beanFactory.getBeanDefinitionNames();
    for (String name : names) {
        final BeanDefinition definition = beanFactory.getBeanDefinition(name);
        if (definition.isSingleton()) {
            final String className = definition.getBeanClassName();
            try {
                final Class<?> beanType = ClassUtils.forName(className, beanFactory.getBeanClassLoader());
                if (ValueReader.class.isAssignableFrom(beanType)) {
                    register(beanFactory.getBean(name, ValueReader.class));
                }//ww  w  .j a  v  a2 s .c  o  m
            } catch (ClassNotFoundException e) {
                throw new BeanCreationNotAllowedException(name, "Failed to access bean");
            }
        }
    }
}

From source file:com.agileapes.webexport.io.impl.DatabaseOutputManager.java

private Connection getConnection(DatabaseAddress address) throws IOException {
    ConnectionDescriptor descriptor = new ConnectionDescriptor(address.getConnectionString(),
            address.getUsername(), address.getPassword());
    if (address.isKeepAlive()) {
        for (ConnectionDescriptor connectionDescriptor : descriptors) {
            if (descriptor.equals(connectionDescriptor)) {
                descriptor = connectionDescriptor;
            }/*from   w  w  w. ja  va2  s  .  c o m*/
        }
    }
    if (descriptor.getConnection() != null) {
        return descriptor.getConnection();
    }
    //loading the driver
    try {
        ClassUtils.forName(address.getDriver(), getClass().getClassLoader());
    } catch (ClassNotFoundException e) {
        throw new IOException("Driver not found: " + address.getDriver());
    }
    final Connection connection;
    try {
        if ((address.getUsername() == null || address.getUsername().isEmpty())
                && (address.getPassword() == null || address.getPassword().isEmpty())) {
            connection = DriverManager.getConnection(address.getConnectionString());
        } else {
            connection = DriverManager.getConnection(address.getConnectionString(), address.getUsername(),
                    address.getPassword());
        }
    } catch (SQLException e) {
        throw new IOException("Failed to get a connection to the database", e);
    }
    if (address.isKeepAlive()) {
        descriptors.remove(descriptor);
        descriptors.add(descriptor);
    }
    return connection;
}

From source file:com.agileapes.motorex.cli.target.impl.SpringExecutionTargetContext.java

@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    final String[] names = beanFactory.getBeanDefinitionNames();
    for (String name : names) {
        final BeanDefinition definition = beanFactory.getBeanDefinition(name);
        if (definition.isSingleton()) {
            final String className = definition.getBeanClassName();
            try {
                final Class<?> beanClass = ClassUtils.forName(className, beanFactory.getBeanClassLoader());
                if (ExecutionTarget.class.isAssignableFrom(beanClass)) {
                    final ExecutionTarget target = beanFactory.getBean(name, ExecutionTarget.class);
                    if (target instanceof AbstractIdentifiedExecutionTarget) {
                        AbstractIdentifiedExecutionTarget executionTarget = (AbstractIdentifiedExecutionTarget) target;
                        executionTarget.setIdentifier(name);
                    }/*from  w  ww.j  av  a2s.  co m*/
                    register(target);
                }
            } catch (ClassNotFoundException e) {
                throw new BeanCreationException(name, "Could not access bean class");
            }
        }
    }
}

From source file:org.focusns.common.web.widget.mvc.method.WidgetModelAttributeMethodProcessor.java

@Override
protected void validateIfApplicable(WebDataBinder binder, MethodParameter parameter) {
    ////  ww  w .j a  v a2s . com
    WebRequest webRequest = webRequestLocal.get();
    String groupsStr = webRequest.getParameter("groups");
    if (StringUtils.hasText(groupsStr)) {
        List<Object> hintList = new ArrayList<Object>();
        String[] groups = StringUtils.commaDelimitedListToStringArray(groupsStr);
        for (String group : groups) {
            try {
                hintList.add(ClassUtils.forName(group, getClass().getClassLoader()));
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        }
        //
        hintList.add(Default.class);
        //
        Annotation[] annotations = parameter.getParameterAnnotations();
        for (Annotation annot : annotations) {
            if (annot.annotationType().getSimpleName().startsWith("Valid")) {
                Object hints = hintList.toArray(new Object[hintList.size()]);
                binder.validate(hints instanceof Object[] ? (Object[]) hints : new Object[] { hints });
            }
        }
    }
}