Example usage for org.apache.commons.lang ClassUtils getShortCanonicalName

List of usage examples for org.apache.commons.lang ClassUtils getShortCanonicalName

Introduction

In this page you can find the example usage for org.apache.commons.lang ClassUtils getShortCanonicalName.

Prototype

public static String getShortCanonicalName(String canonicalName) 

Source Link

Document

Gets the canonical name minus the package name from a String.

The string passed in is assumed to be a canonical name - it is not checked.

Usage

From source file:com.dm.estore.config.WebAppInitializer.java

private void registerListener(ServletContext servletContext) {
    AnnotationConfigWebApplicationContext rootContext = createContext(ApplicationModule.class);

    // find all classes marked as @Configuration in classpath
    ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(
            false);//ww w  . java2  s  .  c om
    scanner.addIncludeFilter(new AnnotationTypeFilter(Configuration.class));
    //TypeFilter tf = new AssignableTypeFilter(CLASS_YOU_WANT.class);
    //s.addIncludeFilter(tf);
    //s.scan("package.you.want1", "package.you.want2");       
    //String[] beans = bdr.getBeanDefinitionNames();
    for (BeanDefinition bd : scanner.findCandidateComponents("com.dm.estore")) {
        final String beanClassName = bd.getBeanClassName();
        final String simpleName = ClassUtils.getShortCanonicalName(beanClassName);
        if (!excludeFromAutoSearch.contains(beanClassName)
                && !simpleName.toLowerCase().startsWith(TEST_RESOURCES_PREFIX)) {
            LOG.warn("Load configuration from: " + bd.getBeanClassName());
            try {
                Class<?> clazz = WebAppInitializer.class.getClassLoader().loadClass(bd.getBeanClassName());
                rootContext.register(clazz);
            } catch (ClassNotFoundException ex) {
                LOG.error("Unable to load class: " + bd.getBeanClassName(), ex);
            }
        }
    }
    rootContext.refresh();

    servletContext.addListener(new ContextLoaderListener(rootContext));
}

From source file:edu.cornell.med.icb.goby.modes.AbstractCommandLineMode.java

/**
 * Load JSAP XML configuration for the current class. With potential
 * modifications to help / defaults stored in the helpValues map.
 *
 * @param helpValues a map of values to replace in the jsap help with other values
 * @return the configured JSAP object/*from   www . ja  va 2 s . co m*/
 * @throws IOException   error reading or configuring
 * @throws JSAPException error reading or configuring
 */
@SuppressWarnings("unchecked")
public JSAP loadJsapFromResource(final Map<String, String> helpValues) throws IOException, JSAPException {
    final Class thisClass = this.getClass();
    final String className = ClassUtils.getShortCanonicalName(thisClass);
    JSAP jsap;
    try {
        jsap = new JSAP(thisClass.getResource(className + ".jsap"));
        reformatHelp(jsap);

    } catch (NullPointerException e) { // NOPMD
        // No JSAP for "this", no additional args for the specific driver
        jsap = new JSAP();
    }

    // add options from driver to mode specific JSAP:
    final JSAP jsapSource = new JSAP(GenericToolsDriver.class
            .getResource(ClassUtils.getShortCanonicalName(GenericToolsDriver.class) + ".jsap"));
    final Iterator<String> idsIt = jsapSource.getIDMap().idIterator();
    while (idsIt.hasNext()) {
        final String id = idsIt.next();
        // remove parameters if they already exist in the destination.
        // This makes sure we use the source parameters, such as mode, help,
        // which contain variables to be replaced.
        if (jsap.getByID(id) != null) {
            jsap.unregisterParameter(jsap.getByID(id));
        }
        jsap.registerParameter(jsapSource.getByID(id));

    }
    if (helpValues == null) {
        return jsap;
    }
    final IDMap idMap = jsap.getIDMap();
    final Iterator<String> idIterator = idMap.idIterator();

    while (idIterator.hasNext()) {
        final String id = idIterator.next();
        final Parameter param = jsap.getByID(id);
        final String help = param.getHelp();
        final String[] defaults = param.getDefault();
        for (final Map.Entry<String, String> entry : helpValues.entrySet()) {
            // replace values in help
            if (help.contains(entry.getKey())) {
                param.setHelp(StringUtils.replace(help, entry.getKey(), entry.getValue()));
            }
            // replace values in defaults
            if (defaults != null) {
                for (int i = 0; i < defaults.length; i++) {
                    if (defaults[i].contains(entry.getKey())) {
                        defaults[i] = StringUtils.replace(defaults[i], entry.getKey(), entry.getValue());
                    }
                }
            }

        }
    }

    return jsap;
}