class BaseLdapPathBeanPostProcessor implements BeanPostProcessor, ApplicationContextAware, Ordered {

	BaseLdapPathSource getBaseLdapPathSourceFromApplicationContext() {
		if (StringUtils.hasLength(baseLdapPathSourceName)) {
			return applicationContext.getBean(baseLdapPathSourceName, BaseLdapPathSource.class);
		}

        Collection<BaseLdapPathSource> beans = applicationContext.getBeansOfType(BaseLdapPathSource.class).values();
        if (beans.isEmpty()) {
            throw new NoSuchBeanDefinitionException("No BaseLdapPathSource implementation definition found");
        } else if (beans.size() == 1) {
            return beans.iterator().next();
        } else {
            BaseLdapPathSource found = null;

            // Try to find the correct one
            for (BaseLdapPathSource bean : beans) {
                if(bean instanceof AbstractContextSource) {
                    if(found != null) {
                        // More than one found - nothing much to do.
                        throw new NoSuchBeanDefinitionException(
                                "More than BaseLdapPathSource implementation definition found in current ApplicationContext; " +
                                        "unable to determine the one to use. Please specify 'baseLdapPathSourceName'");
                    }

                    found = bean;
                }
            }

            if(found == null) {
                throw new NoSuchBeanDefinitionException(
                        "More than BaseLdapPathSource implementation definition found in current ApplicationContext; " +
                                "unable to determine the one to use (one of them should be an AbstractContextSource instance). " +
                                "Please specify 'baseLdapPathSourceName'");
            }

            return found;
        }
	}

}