Package org.springframework.core.io.support

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


    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< ? > > >();
        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 = new PathMatchingResourcePatternResolver();
       
       
       
        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

   * @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

   * @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

   * @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 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

    public List<EventCategoryTO> listAuditEvents() {
        // use set to avoi duplications or null elements
        final Set<EventCategoryTO> events = new HashSet<EventCategoryTO>();

        try {
            final ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
            final MetadataReaderFactory metadataReaderFactory =
                    new CachingMetadataReaderFactory(resourcePatternResolver);

            final String packageSearchPath =
                    ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
                    + ClassUtils.convertClassNameToResourcePath(
                    SystemPropertyUtils.resolvePlaceholders(this.getClass().getPackage().getName()))
                    + "/" + "**/*.class";

            final Resource[] resources = resourcePatternResolver.getResources(packageSearchPath);
            for (Resource resource : resources) {
                if (resource.isReadable()) {
                    final MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource);
                    final Class<?> clazz = Class.forName(metadataReader.getClassMetadata().getClassName());

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");
                resources = filterResources(resources, resourceFilter);
                if (logger != null && logger.isDebugEnabled())
                    logger.debug("Found " + resources.length + " matching resources in " +
                                 propertiesPath + "/*.properties");
            } catch (IOException ignore) {
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");
                resources = ResourceUtils.filterResources(resources, getResourceFilter());
                Arrays.sort(resources, ResourceUtils.getResourceComparator());
                for (int i = 0; i < resources.length; i++) {
                    this.handleImport(parserContext, resources[i].getURL().toExternalForm());
                }
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.