View Javadoc

1   /*
2    * $Id: MuleResourceLoader.java 7976 2007-08-21 14:26:13Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.extras.spring.config;
12  
13  import org.apache.commons.logging.Log;
14  import org.apache.commons.logging.LogFactory;
15  import org.springframework.core.io.ClassPathResource;
16  import org.springframework.core.io.DefaultResourceLoader;
17  import org.springframework.core.io.FileSystemResource;
18  import org.springframework.core.io.Resource;
19  
20  /**
21   * By default, a resource is loaded directly from the classpath.  Override this method to try loading it
22   * from the file system first.
23   */
24  public class MuleResourceLoader extends DefaultResourceLoader 
25  {
26      protected transient Log logger = LogFactory.getLog(MuleResourceLoader.class);
27      
28      /**
29       * By default, a resource is loaded directly from the classpath.  Override this method to try loading it
30       * from the file system first.
31       */
32      //@Override
33      protected Resource getResourceByPath(String path)
34      {
35          Resource r = new FileSystemResource(path);
36          if (logger.isDebugEnabled())
37          {
38              logger.debug("Attempting to load resource from file system: " + ((FileSystemResource) r).getFile().getAbsolutePath());
39          }
40          if (r.exists())
41          {
42              return r;
43          }
44          else
45          {
46              logger.debug("Resource does not exist on file system, loading from classpath.");
47              r = new ClassPathResource(path, getClassLoader());
48              return r;
49          }
50      }
51  }