public class OsgiBundleResourcePatternResolver
extends org.springframework.core.io.support.PathMatchingResourcePatternResolver
ResourcePatternResolver.
Can find resources in the bundle jar and bundle space. See OsgiBundleResource for more
information.
ClassPath support
As mentioned by PathMatchingResourcePatternResolver, class-path pattern matching needs to resolve the
class-path structure to a file-system location (be it an actual folder or a jar). Inside the OSGi environment this is
problematic as the bundles can be loaded in memory directly from input streams. To avoid relying on each platform
bundle storage structure, this implementation tries to determine the bundles that assemble the given bundle
class-path and analyze each of them individually. This involves the bundle archive (including special handling of the
Bundle-Classpath as it is computed at runtime), the bundle required packages and its attached fragments.
Depending on the configuration of running environment, this might cause significant IO activity which can affect
performance.
Note: Currently, static imports as well as Bundle-Classpath and
Required-Bundle entries are supported. Support for DynamicPackage-Import depends on
how/when the underlying platform does the wiring between the dynamically imported bundle and the given bundle.
Portability Note: Since it relies only on the OSGi API, this implementation depends heavily on how
closely the platform implements the OSGi spec. While significant tests have been made to ensure compatibility, one
might experience different behaviour especially when dealing with jars with missing folder entries or
boot-path delegation. It is strongly recommended that wildcard resolution be thoroughly tested before switching to a
different platform before you rely on it.Bundle,
OsgiBundleResource,
PathMatchingResourcePatternResolver| Modifier and Type | Field and Description |
|---|---|
private org.osgi.framework.Bundle |
bundle
The bundle on which this resolver works on.
|
private static java.lang.String |
BUNDLE_DEFAULT_CP |
private org.osgi.framework.BundleContext |
bundleContext
The bundle context associated with this bundle.
|
private static char |
DOT |
private static java.lang.String |
FOLDER_SEPARATOR |
private static java.lang.String |
FOLDER_WILDCARD |
private static java.lang.String |
JAR_EXTENSION |
private static org.apache.commons.logging.Log |
logger
Our own logger to protect against incompatible class changes.
|
private DependencyResolver |
resolver |
private static char |
SLASH |
| Constructor and Description |
|---|
OsgiBundleResourcePatternResolver(org.osgi.framework.Bundle bundle) |
OsgiBundleResourcePatternResolver(org.springframework.core.io.ResourceLoader resourceLoader) |
| Modifier and Type | Method and Description |
|---|---|
private org.springframework.core.io.ContextResource[] |
convertURLEnumerationToResourceArray(java.util.Enumeration<java.net.URL> enm,
java.lang.String path) |
private java.lang.String |
determineFolderPattern(java.lang.String path) |
private java.util.Set<org.springframework.core.io.Resource> |
doFindPathMatchingFileResources(org.springframework.core.io.Resource rootDirResource,
java.lang.String subPattern,
int searchType)
Based on the search type, uses the appropriate searching method.
|
private void |
doRetrieveMatchingBundleEntries(org.osgi.framework.Bundle bundle,
java.lang.String fullPattern,
java.lang.String dir,
java.util.Set<org.springframework.core.io.Resource> result,
int searchType)
Searches each level inside the bundle for entries based on the search strategy chosen.
|
private void |
findBundleClassPathMatchingFolders(java.util.List<java.lang.String> list,
org.osgi.framework.Bundle bundle,
java.lang.String cpEntryPath,
java.lang.String pattern)
Checks the folder entries from the Bundle-Classpath for the given pattern.
|
private void |
findBundleClassPathMatchingJarEntries(java.util.List<java.lang.String> list,
java.net.URL url,
java.lang.String pattern)
Checks the jar entries from the Bundle-Classpath for the given pattern.
|
private java.util.Collection<java.lang.String> |
findBundleClassPathMatchingPaths(org.osgi.framework.Bundle bundle,
java.lang.String pattern)
Searches the bundle classpath (Bundle-Classpath) entries for the given pattern.
|
private org.springframework.core.io.Resource[] |
findClassPathMatchingResources(java.lang.String locationPattern,
int type)
Special classpath method.
|
private void |
findImportedBundleMatchingResource(ImportedBundle importedBundle,
java.lang.String rootPath,
java.lang.String path,
java.util.Collection<java.lang.String> foundPaths)
Searches for the given pattern inside the imported bundle.
|
private org.springframework.core.io.Resource[] |
findPathMatchingResources(java.lang.String locationPattern,
int searchType)
Replace the super class implementation to pass in the searchType parameter.
|
protected org.springframework.core.io.Resource[] |
findResources(java.lang.String locationPattern)
Finds existing resources.
|
private void |
findSyntheticClassPathMatchingResource(org.osgi.framework.Bundle bundle,
java.lang.String path,
java.util.Collection<java.lang.String> foundPaths)
Applies synthetic class-path analysis.
|
org.springframework.core.io.Resource[] |
getResources(java.lang.String locationPattern) |
private java.lang.String |
handleString(java.lang.String path)
Handles candidates returned as Strings.
|
private java.lang.String |
handleURL(java.net.URL path)
Handles candidates returned as URLs.
|
protected boolean |
isJarResource(org.springframework.core.io.Resource resource)
Overrides the default check up since computing the URL can be fairly expensive operation as there is no caching
(due to the framework dynamic nature).
|
convertClassLoaderURL, determineRootDir, doFindMatchingFileSystemResources, doFindPathMatchingFileResources, doFindPathMatchingJarResources, doRetrieveMatchingFiles, findAllClassPathResources, findPathMatchingResources, getClassLoader, getJarFile, getPathMatcher, getResource, getResourceLoader, resolveRootDirResource, retrieveMatchingFiles, setPathMatcherprivate static final org.apache.commons.logging.Log logger
private final org.osgi.framework.Bundle bundle
private final org.osgi.framework.BundleContext bundleContext
private static final java.lang.String FOLDER_SEPARATOR
private static final java.lang.String FOLDER_WILDCARD
private static final java.lang.String JAR_EXTENSION
private static final java.lang.String BUNDLE_DEFAULT_CP
private static final char SLASH
private static final char DOT
private final DependencyResolver resolver
public OsgiBundleResourcePatternResolver(org.osgi.framework.Bundle bundle)
public OsgiBundleResourcePatternResolver(org.springframework.core.io.ResourceLoader resourceLoader)
protected org.springframework.core.io.Resource[] findResources(java.lang.String locationPattern)
throws java.io.IOException
locationPattern - location patternjava.io.IOException - in case of I/O errorspublic org.springframework.core.io.Resource[] getResources(java.lang.String locationPattern)
throws java.io.IOException
getResources in interface org.springframework.core.io.support.ResourcePatternResolvergetResources in class org.springframework.core.io.support.PathMatchingResourcePatternResolverjava.io.IOExceptionprivate org.springframework.core.io.Resource[] findClassPathMatchingResources(java.lang.String locationPattern,
int type)
throws java.io.IOException
locationPattern - type - java.io.IOExceptionprivate java.lang.String determineFolderPattern(java.lang.String path)
private org.springframework.core.io.ContextResource[] convertURLEnumerationToResourceArray(java.util.Enumeration<java.net.URL> enm,
java.lang.String path)
private void findImportedBundleMatchingResource(ImportedBundle importedBundle, java.lang.String rootPath, java.lang.String path, java.util.Collection<java.lang.String> foundPaths) throws java.io.IOException
importedBundle - imported bundlepath - path used for pattern matchingfoundPaths - collection of found resultsjava.io.IOExceptionprivate void findSyntheticClassPathMatchingResource(org.osgi.framework.Bundle bundle,
java.lang.String path,
java.util.Collection<java.lang.String> foundPaths)
throws java.io.IOException
bundle - path - foundPaths - java.io.IOExceptionprivate java.util.Collection<java.lang.String> findBundleClassPathMatchingPaths(org.osgi.framework.Bundle bundle,
java.lang.String pattern)
throws java.io.IOException
bundle - pattern - java.io.IOExceptionprivate void findBundleClassPathMatchingJarEntries(java.util.List<java.lang.String> list,
java.net.URL url,
java.lang.String pattern)
throws java.io.IOException
list - ur - java.io.IOExceptionprivate void findBundleClassPathMatchingFolders(java.util.List<java.lang.String> list,
org.osgi.framework.Bundle bundle,
java.lang.String cpEntryPath,
java.lang.String pattern)
throws java.io.IOException
list - bundle - cpEntryPath - pattern - java.io.IOExceptionprivate org.springframework.core.io.Resource[] findPathMatchingResources(java.lang.String locationPattern,
int searchType)
throws java.io.IOException
java.io.IOExceptionPathMatchingResourcePatternResolver.findPathMatchingResources(String)protected boolean isJarResource(org.springframework.core.io.Resource resource)
throws java.io.IOException
isJarResource in class org.springframework.core.io.support.PathMatchingResourcePatternResolverjava.io.IOExceptionprivate java.util.Set<org.springframework.core.io.Resource> doFindPathMatchingFileResources(org.springframework.core.io.Resource rootDirResource,
java.lang.String subPattern,
int searchType)
throws java.io.IOException
java.io.IOExceptionOsgiBundleResource.BUNDLE_URL_PREFIX,
PathMatchingResourcePatternResolver.getResources(java.lang.String)private void doRetrieveMatchingBundleEntries(org.osgi.framework.Bundle bundle,
java.lang.String fullPattern,
java.lang.String dir,
java.util.Set<org.springframework.core.io.Resource> result,
int searchType)
throws java.io.IOException
bundle - the bundle to do the lookupfullPattern - matching patterndir - directory inside the bundleresult - set of results (used to concatenate matching sub dirs)searchType - the search strategy to usejava.io.IOExceptionprivate java.lang.String handleURL(java.net.URL path)
path - private java.lang.String handleString(java.lang.String path)
path -