1.resource的前生后世

  前生:public interface Resource extends InputStreamSource

public interface InputStreamSource {

    /**
     * Return an {@link InputStream}.
     * <p>It is expected that each call creates a <i>fresh</i> stream.
     * <p>This requirement is particularly important when you consider an API such
     * as JavaMail, which needs to be able to read the stream multiple times when
     * creating mail attachments. For such a use case, it is <i>required</i>
     * that each <code>getInputStream()</code> call returns a fresh stream.
     * @throws IOException if the stream could not be opened
     * @see org.springframework.mail.javamail.MimeMessageHelper#addAttachment(String, InputStreamSource)
     */
    InputStream getInputStream() throws IOException;

}

后世:

2.Resource辅助工具类ResourceUtils

 1     /** Pseudo URL prefix for loading from the class path: "classpath:" */
 2     public static final String CLASSPATH_URL_PREFIX = "classpath:";
 3 
 4     /** URL prefix for loading from the file system: "file:" */
 5     public static final String FILE_URL_PREFIX = "file:";
 6 
 7     /** URL protocol for a file in the file system: "file" */
 8     public static final String URL_PROTOCOL_FILE = "file";
 9 
10     /** URL protocol for an entry from a jar file: "jar" */
11     public static final String URL_PROTOCOL_JAR = "jar";
12 
13     /** URL protocol for an entry from a zip file: "zip" */
14     public static final String URL_PROTOCOL_ZIP = "zip";
15 
16     /** URL protocol for an entry from a JBoss jar file: "vfszip" */
17     public static final String URL_PROTOCOL_VFSZIP = "vfszip";
18 
19     /** URL protocol for an entry from a WebSphere jar file: "wsjar" */
20     public static final String URL_PROTOCOL_WSJAR = "wsjar";
21 
22     /** URL protocol for an entry from an OC4J jar file: "code-source" */
23     public static final String URL_PROTOCOL_CODE_SOURCE = "code-source";
24 
25     /** Separator between JAR URL and file path within the JAR */
26     public static final String JAR_URL_SEPARATOR = "!/";

3.resource的继承关系:(http://www.ibm.com/developerworks/cn/java/j-lo-spring-principle/index.html 图 8. Resource 相关的类结构图

图 9. Context 和 Resource 的类关系图
图 9. Context 和 Resource 的类关系图
从上图可以看出,Context 是把资源的加载、解析和描述工作委托给了 ResourcePatternResolver 类来完成,他相当于一个接头人,他把资源的加载、解析和资源的定义整合在一起便于其他组件使用。

posted on 2013-03-21 11:22  一天不进步,就是退步  阅读(662)  评论(0编辑  收藏  举报