Package org.springframework.core.io.support

Examples of org.springframework.core.io.support.ResourcePatternResolver


        Collection< String > basePackages,
        List<Class< ? extends Annotation > > annotations,
        ClassLoader loader)
        throws IOException, ClassNotFoundException {
   
        ResourcePatternResolver resolver = getResolver(loader);
        MetadataReaderFactory factory = new CachingMetadataReaderFactory(resolver);
       
        final Map< Class< ? extends Annotation >, Collection< Class< ? > > > classes =
            new HashMap< Class< ? extends Annotation >, Collection< Class< ? > > >();
        final Map< Class< ? extends Annotation >, Collection< String > > matchingInterfaces =
            new HashMap< Class< ? extends Annotation >, Collection< String > >();
        final Map<String, String[]> nonMatchingClasses = new HashMap<String, String[]>();
       
        for (Class< ? extends Annotation > annotation: annotations) {
            classes.put(annotation, new HashSet< Class < ? > >());
            matchingInterfaces.put(annotation, new HashSet< String >());
        }
       
        if (basePackages == null || basePackages.isEmpty()) {
            return classes;
        }
       
        for (final String basePackage: basePackages) {
            final boolean scanAllPackages = basePackage.equals(ALL_PACKAGES);
           
            final String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
                + (scanAllPackages ? "" : ClassUtils.convertClassNameToResourcePath(basePackage))
                + ALL_CLASS_FILES;
           
            final Resource[] resources = resolver.getResources(packageSearchPath);   
           
           
            for (final Resource resource: resources) {
                final MetadataReader reader = factory.getMetadataReader(resource);
                final AnnotationMetadata metadata = reader.getAnnotationMetadata();
View Full Code Here


        throws IOException {
        final List<URL> resourceURLs = new ArrayList<URL>();
        if (basePackages == null || basePackages.isEmpty()) {
            return resourceURLs;
        }
        ResourcePatternResolver resolver = getResolver(loader);
       
        for (final String basePackage: basePackages) {
            final boolean scanAllPackages = basePackage.equals(ALL_PACKAGES);
           
            String theBasePackage = basePackage;
            if (theBasePackage.startsWith(CLASSPATH_URL_SCHEME)) {
                theBasePackage = theBasePackage.substring(CLASSPATH_URL_SCHEME.length());
            }
           
            final String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
                + (scanAllPackages ? "" : ClassUtils.convertClassNameToResourcePath(theBasePackage))
                + ALL_FILES + "." + extension;
           
            final Resource[] resources = resolver.getResources(packageSearchPath);                       
            for (final Resource resource: resources) {
                resourceURLs.add(resource.getURL());
            }                       
        }
       
View Full Code Here

   * @return the corresponding BeanFactory reference
   */
  protected BeanFactory createDefinition(String resourceLocation, String factoryKey) {
    DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
    ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();

    try {
      Resource[] configResources = resourcePatternResolver.getResources(resourceLocation);
      if (configResources.length == 0) {
        throw new FatalBeanException("Unable to find resource for specified definition. " +
            "Group resource name [" + this.resourceLocation + "], factory key [" + factoryKey + "]");
      }
      reader.loadBeanDefinitions(configResources);
View Full Code Here

   * @param attributes meta attributes to apply to each flow definition resource
   * @return the flow definition resources
   */
  public FlowDefinitionResource[] createResources(String pattern, AttributeMap<Object> attributes) throws IOException {
    if (resourceLoader instanceof ResourcePatternResolver) {
      ResourcePatternResolver resolver = (ResourcePatternResolver) resourceLoader;
      Resource[] resources;
      if (basePath == null) {
        resources = resolver.getResources(pattern);
      } else {
        if (basePath.endsWith(SLASH) || pattern.startsWith(SLASH)) {
          resources = resolver.getResources(basePath + pattern);
        } else {
          resources = resolver.getResources(basePath + SLASH + pattern);
        }
      }
      FlowDefinitionResource[] flowResources = new FlowDefinitionResource[resources.length];
      for (int i = 0; i < resources.length; i++) {
        Resource resource = resources[i];
View Full Code Here

                                      Log            logger) {
        if (logger != null && logger.isDebugEnabled()) {
            logger.debug("Reading properties from directory: " + propertiesPath);
        }

        ResourcePatternResolver resolver;
    if (resourceLoader instanceof ResourcePatternResolver) {
      resolver = (ResourcePatternResolver) resourceLoader;
        } else {
      resolver = new PathMatchingResourcePatternResolver(resourceLoader);
        }

        Resource[] resources = null;

        // check if directory exists
        boolean load = true;
        if (!ResourceUtils.isClasspathUri(propertiesPath)) {
            final Resource resource = resolver.getResource(propertiesPath);
            if (!resource.exists()) {
                load = false;
            }
        }
        if (load) {
            try {
                resources = resolver.getResources(propertiesPath + "/*.properties");
                if (logger != null && logger.isDebugEnabled())
                    logger.debug("Found " + resources.length + " matching resources in " +
                                 propertiesPath + "/*.properties");
            } catch (IOException ignore) {
                if (logger != null && logger.isDebugEnabled()) {
View Full Code Here

     */
    protected void handleBeanInclude(final ParserContext parserContext,
                                     final String        path,
                                     final boolean       optional)
    throws Exception {
        final ResourcePatternResolver resolver =
            (ResourcePatternResolver) parserContext.getReaderContext().getReader().getResourceLoader();

        // check if the directory to read from exists
        // we only check if optional is set to true
        boolean load = true;
        if ( optional
             && !ResourceUtils.isClasspathUri(path) ) {
            final Resource rsrc = resolver.getResource(path);
            if ( !rsrc.exists()) {
                load = false;
            }
        }
        if ( load ) {
            try {
                Resource[] resources = resolver.getResources(path + "/*.xml");
                Arrays.sort(resources, ResourceUtils.getResourceComparator());
                for (int i = 0; i < resources.length; i++) {
                    this.handleImport(parserContext, resources[i].getURL().toExternalForm());
                }
            } catch (IOException ioe) {
View Full Code Here

                resourceName = GrailsRuntimeConfigurator.SPRING_RESOURCES_XML;
                springResources = parent.getResource(resourceName);
            }
            else {
                resourceName = DEVELOPMENT_SPRING_RESOURCES_XML;
                ResourcePatternResolver patternResolver = new PathMatchingResourcePatternResolver();
                springResources = patternResolver.getResource(resourceName);
            }

            if (springResources != null && springResources.exists()) {
                if (LOG.isDebugEnabled()) LOG.debug("[RuntimeConfiguration] Configuring additional beans from " + springResources.getURL());
                DefaultListableBeanFactory xmlBf = new OptimizedAutowireCapableBeanFactory();
View Full Code Here

        return new PathMatchingResourcePatternResolver();
    }

    @Override
    public Collection<ModuleDefinition> locateModules(String context) throws IOException {
        ResourcePatternResolver resolver = getResolver();

        Map<String, ModuleDefinition> allModules = discoverModules(context, resolver);

        return allModules.values();
    }
View Full Code Here

        //use the logic of the DefaultPersistenceUnitManager without the exception in the case of
        //a duplicate name. This will require reflection in order to do what we need.
        try {
            Set<String> persistenceUnitInfoNames = null;
            Map<String, PersistenceUnitInfo> persistenceUnitInfos = null;
            ResourcePatternResolver resourcePatternResolver = null;
            Field[] fields = getClass().getSuperclass().getDeclaredFields();
            for (Field field : fields) {
                if ("persistenceUnitInfoNames".equals(field.getName())) {
                    field.setAccessible(true);
                    persistenceUnitInfoNames = (Set<String>) field.get(this);
                } else if ("persistenceUnitInfos".equals(field.getName())) {
                    field.setAccessible(true);
                    persistenceUnitInfos = (Map<String, PersistenceUnitInfo>) field.get(this);
                } else if ("resourcePatternResolver".equals(field.getName())) {
                    field.setAccessible(true);
                    resourcePatternResolver = (ResourcePatternResolver) field.get(this);
                }
            }

            persistenceUnitInfoNames.clear();
            persistenceUnitInfos.clear();

            Method readPersistenceUnitInfos =
                    getClass().
                            getSuperclass().
                            getDeclaredMethod("readPersistenceUnitInfos");
            readPersistenceUnitInfos.setAccessible(true);

            //In Spring 3.0 this returns an array
            //In Spring 3.1 this returns a List
            Object pInfosObject = readPersistenceUnitInfos.invoke(this);
            Object[] puis;
            if (pInfosObject.getClass().isArray()) {
                puis = (Object[]) pInfosObject;
            } else {
                puis = ((Collection) pInfosObject).toArray();
            }

            for (Object pui : puis) {
                MutablePersistenceUnitInfo mPui = (MutablePersistenceUnitInfo) pui;
                if (mPui.getPersistenceUnitRootUrl() == null) {
                    Method determineDefaultPersistenceUnitRootUrl =
                            getClass().
                                    getSuperclass().
                                    getDeclaredMethod("determineDefaultPersistenceUnitRootUrl");
                    determineDefaultPersistenceUnitRootUrl.setAccessible(true);
                    mPui.setPersistenceUnitRootUrl((URL) determineDefaultPersistenceUnitRootUrl.invoke(this));
                }
                ConfigurationOnlyState state = ConfigurationOnlyState.getState();
                if ((state == null || !state.isConfigurationOnly()) && mPui.getNonJtaDataSource() == null) {
                    mPui.setNonJtaDataSource(getDefaultDataSource());
                }
                if (super.getLoadTimeWeaver() != null) {
                    Method puiInitMethod = mPui.getClass().getDeclaredMethod("init", LoadTimeWeaver.class);
                    puiInitMethod.setAccessible(true);
                    puiInitMethod.invoke(pui, getLoadTimeWeaver());
                }
                else {
                    Method puiInitMethod = mPui.getClass().getDeclaredMethod("init", ClassLoader.class);
                    puiInitMethod.setAccessible(true);
                    puiInitMethod.invoke(pui, resourcePatternResolver.getClassLoader());
                }
                postProcessPersistenceUnitInfo((MutablePersistenceUnitInfo) pui);
                String name = mPui.getPersistenceUnitName();
                persistenceUnitInfoNames.add(name);
View Full Code Here

    protected Map< Class< ? extends Annotation >, Collection< Class< ? > > > findClassesInternal(
        Collection< String > basePackages, List<Class< ? extends Annotation > > annotations)
        throws IOException, ClassNotFoundException {
   
        ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        MetadataReaderFactory factory = new CachingMetadataReaderFactory(resolver);
       
        final Map< Class< ? extends Annotation >, Collection< Class< ? > > > classes =
            new HashMap< Class< ? extends Annotation >, Collection< Class< ? > > >();
       
        for (Class< ? extends Annotation > annotation: annotations) {
            classes.put(annotation, new ArrayList< Class < ? > >());
        }
       
        if (basePackages == null || basePackages.isEmpty()) {
            return classes;
        }
       
        for (final String basePackage: basePackages) {
            final boolean scanAllPackages = basePackage.equals(ALL_PACKAGES);
           
            final String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
                + (scanAllPackages ? "" : ClassUtils.convertClassNameToResourcePath(basePackage))
                + ALL_CLASS_FILES;
           
            final Resource[] resources = resolver.getResources(packageSearchPath);                       
            for (final Resource resource: resources) {
                final MetadataReader reader = factory.getMetadataReader(resource);
                final AnnotationMetadata metadata = reader.getAnnotationMetadata();
               
                if (scanAllPackages && shouldSkip(metadata.getClassName())) {
View Full Code Here

TOP

Related Classes of org.springframework.core.io.support.ResourcePatternResolver

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.