List of usage examples for org.springframework.context ConfigurableApplicationContext CONFIG_LOCATION_DELIMITERS
String CONFIG_LOCATION_DELIMITERS
To view the source code for org.springframework.context ConfigurableApplicationContext CONFIG_LOCATION_DELIMITERS.
Click Source Link
From source file:org.mybatis.spring.extend.SqlSessionFactoryBean.java
private void parseExtTypeAliases(Configuration configuration) { if (!hasLength(extTypeAliasesPackage)) { return;/* w w w . j a v a 2s. c o m*/ } String prefix = "classpath:"; String suffix = "/*.class"; String[] extArr = tokenizeToStringArray(extTypeAliasesPackage, ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS); ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); ClassLoader classLoader = getClass().getClassLoader(); try { for (String ext : extArr) { Resource[] resources = resolver.getResources(prefix + ext + suffix); if (resources != null) { for (Resource resource : resources) { String classFilePath = resource.getURI().getPath(); int index = classFilePath.indexOf("classes"); String className = classFilePath.substring(index + 8, classFilePath.length() - 6) .replaceAll("/", "."); Class<?> clz = classLoader.loadClass(className); configuration.getTypeAliasRegistry().registerAlias(clz); } } } } catch (Exception e) { throw new RuntimeException("parse extTypeAliasesPackage failed", e); } }
From source file:org.mybatis.spring.extend.SqlSessionFactoryBean.java
private void parseMapperPackage(Configuration configuration) throws IOException { if (!hasLength(mapperPackage)) { return;//from w w w . jav a2s .com } String prefix = "classpath:"; String suffix = "/*.xml"; String[] extArr = tokenizeToStringArray(mapperPackage, ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS); ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); for (String ext : extArr) { Resource[] mapperResources = resolver.getResources(prefix + ext + suffix); for (Resource resource : mapperResources) { if (resource == null) { continue; } try { XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(resource.getInputStream(), configuration, resource.toString(), configuration.getSqlFragments()); xmlMapperBuilder.parse(); } catch (Exception e) { throw new NestedIOException("Failed to parse mapping resource: '" + resource + "'", e); } finally { ErrorContext.instance().reset(); } } } }
From source file:org.broadleafcommerce.common.extensibility.jpa.convert.inheritance.SingleTableInheritanceClassTransformer.java
@Override public void compileJPAProperties(Properties props, Object key) throws Exception { if (((String) key).equals(SINGLE_TABLE_ENTITIES)) { String[] classes = StringUtils.tokenizeToStringArray(props.getProperty((String) key), ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS); for (String clazz : classes) { String keyName;// www. j a v a2 s . c o m int pos = clazz.lastIndexOf("."); if (pos >= 0) { keyName = clazz.substring(pos + 1, clazz.length()); } else { keyName = clazz; } SingleTableInheritanceInfo info = new SingleTableInheritanceInfo(); info.setClassName(clazz); String discriminatorName = props.getProperty("broadleaf.ejb." + keyName + ".discriminator.name"); if (discriminatorName != null) { info.setDiscriminatorName(discriminatorName); String type = props.getProperty("broadleaf.ejb." + keyName + ".discriminator.type"); if (type != null) { info.setDiscriminatorType(DiscriminatorType.valueOf(type)); } String length = props.getProperty("broadleaf.ejb." + keyName + ".discriminator.length"); if (length != null) { info.setDiscriminatorLength(Integer.parseInt(length)); } } infos.remove(info); infos.add(info); } } }
From source file:org.broadleafcommerce.common.web.extensibility.MergeXmlWebApplicationContext.java
/** * Load the bean definitions with the given XmlBeanDefinitionReader. * <p>The lifecycle of the bean factory is handled by the refreshBeanFactory method; * therefore this method is just supposed to load and/or register bean definitions. * <p>Delegates to a ResourcePatternResolver for resolving location patterns * into Resource instances.//from w ww . j av a 2s . c om * @throws org.springframework.beans.BeansException in case of bean registration errors * @throws java.io.IOException if the required XML document isn't found * @see #refreshBeanFactory * @see #getConfigLocations * @see #getResources * @see #getResourcePatternResolver */ protected void loadBeanDefinitions(XmlBeanDefinitionReader reader) throws BeansException, IOException { String[] broadleafConfigLocations = StandardConfigLocations.retrieveAll(standardLocationTypes); ArrayList<ResourceInputStream> sources = new ArrayList<ResourceInputStream>(20); for (String location : broadleafConfigLocations) { InputStream source = MergeXmlWebApplicationContext.class.getClassLoader().getResourceAsStream(location); if (source != null) { sources.add(new ResourceInputStream(source, location)); } } ResourceInputStream[] filteredSources = new ResourceInputStream[] {}; filteredSources = sources.toArray(filteredSources); String patchLocation = getPatchLocation(); String[] patchLocations = StringUtils.tokenizeToStringArray(patchLocation, ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS); List<ResourceInputStream> patchList = new ArrayList<ResourceInputStream>(); for (int i = 0; i < patchLocations.length; i++) { ResourceInputStream patch; if (patchLocations[i].startsWith("classpath")) { InputStream is = MergeXmlWebApplicationContext.class.getClassLoader().getResourceAsStream( patchLocations[i].substring("classpath*:".length(), patchLocations[i].length())); patch = new ResourceInputStream(is, patchLocations[i]); } else { Resource resource = getResourceByPath(patchLocations[i]); patch = new ResourceInputStream(resource.getInputStream(), patchLocations[i]); } if (patch == null || patch.available() <= 0) { patchList.addAll(getResourcesFromPatternResolver(patchLocations[i])); } else { patchList.add(patch); } } ImportProcessor importProcessor = new ImportProcessor(this); ResourceInputStream[] patchArray; try { filteredSources = importProcessor.extract(filteredSources); patchArray = importProcessor.extract(patchList.toArray(new ResourceInputStream[patchList.size()])); } catch (MergeException e) { throw new FatalBeanException("Unable to merge source and patch locations", e); } Resource[] resources = new MergeApplicationContextXmlConfigResource().getConfigResources(filteredSources, patchArray); reader.loadBeanDefinitions(resources); }
From source file:org.jahia.services.SpringContextSingleton.java
/** * Searches for Spring resource locations given the specified (pattern-based) location. Multiple locations can be provided separated by * comma (or any delimiter, defined in {@link org.springframework.context.ConfigurableApplicationContext#CONFIG_LOCATION_DELIMITERS} ). * * @param locationPatterns/*from ww w . ja v a 2 s . c om*/ * (pattern-based) location to search for resources. Multiple locations can be provided separated by comma (or any delimiter, * defined in {@link org.springframework.context.ConfigurableApplicationContext#CONFIG_LOCATION_DELIMITERS} ) * @param useCache can we use lookup caches? * @return an array of {@link Resource} objects found * @throws IOException * in case of a lookup error */ public Resource[] getResources(String locationPatterns, boolean useCache) throws IOException { Resource[] allResources = useCache ? resourcesCache.get(locationPatterns) : null; if (allResources == null) { allResources = new Resource[0]; for (String location : org.springframework.util.StringUtils.tokenizeToStringArray(locationPatterns, ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS)) { try { allResources = (Resource[]) ArrayUtils.addAll(allResources, context.getResources(location.trim())); } catch (FileNotFoundException e) { // Ignore logger.debug("Cannot find resources", e); } } if (useCache) { resourcesCache.put(locationPatterns, allResources); } } return allResources; }