站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > Spring Framework 1.2.9 API 文档英文版

AbstractResource (Spring Framework) - Spring Framework 1.2.9 API 文档英文版


org.springframework.core.io
Class AbstractResource

java.lang.Object
  extended by org.springframework.core.io.AbstractResource
All Implemented Interfaces:
InputStreamSource, Resource
Direct Known Subclasses:
ByteArrayResource, ClassPathResource, DescriptiveResource, FileSystemResource, InputStreamResource, ServletContextResource, UrlResource

public abstract class AbstractResource
extends Object
implements Resource

Convenience base class for Resource implementations, pre-implementing typical behavior.

The "exists" method will check whether a File or InputStream can be opened; "isOpen" will always return false; "getURL" and "getFile" throw an exception; and "toString" will return the description.

Since:
28.12.2003
Author:
Juergen Hoeller

Constructor Summary
AbstractResource()
           
 
Method Summary
 Resource createRelative(String relativePath)
          This implementation throws a FileNotFoundException, assuming that relative resources cannot be created for this resource.
 boolean equals(Object obj)
          This implementation compares description strings.
 boolean exists()
          This implementation checks whether a File can be opened, falling back to whether an InputStream can be opened.
abstract  String getDescription()
          This abstract method declaration shadows the method in the Resource interface.
 File getFile()
          This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to an absolute file path.
 String getFilename()
          This implementation always throws IllegalStateException, assuming that the resource does not carry a filename.
 URL getURL()
          This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to a URL.
 int hashCode()
          This implementation returns the description's hash code.
 boolean isOpen()
          This implementation always returns false.
 String toString()
          This implementation returns the description of this resource.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.springframework.core.io.InputStreamSource
getInputStream
 

Constructor Detail

AbstractResource

public AbstractResource()
Method Detail

exists

public boolean exists()
This implementation checks whether a File can be opened, falling back to whether an InputStream can be opened. This will cover both directories and content resources.

Specified by:
exists in interface Resource

isOpen

public boolean isOpen()
This implementation always returns false.

Specified by:
isOpen in interface Resource

getURL

public URL getURL()
           throws IOException
This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to a URL.

Specified by:
getURL in interface Resource
Throws:
IOException - if the resource cannot be resolved as URL, i.e. if the resource is not available as descriptor

getFile

public File getFile()
             throws IOException
This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to an absolute file path.

Specified by:
getFile in interface Resource
Throws:
IOException - if the resource cannot be resolved as absolute file path, i.e. if the resource is not available in a file system

createRelative

public Resource createRelative(String relativePath)
                        throws IOException
This implementation throws a FileNotFoundException, assuming that relative resources cannot be created for this resource.

Specified by:
createRelative in interface Resource
Parameters:
relativePath - the relative path (relative to this resource)
Returns:
the resource handle for the relative resource
Throws:
IOException - if the relative resource cannot be determined

getFilename

public String getFilename()
                   throws IllegalStateException
This implementation always throws IllegalStateException, assuming that the resource does not carry a filename.

Specified by:
getFilename in interface Resource
Throws:
IllegalStateException

getDescription

public abstract String getDescription()
This abstract method declaration shadows the method in the Resource interface. This is necessary to make the toString implementation in this class work on Sun's JDK 1.3 classic VM, which can't find the method when executing toString else. Furthermore, getDescription is also called from equals and hashCode

Specified by:
getDescription in interface Resource
See Also:
Resource.getDescription(), toString(), equals(Object), hashCode()

toString

public String toString()
This implementation returns the description of this resource.

Overrides:
toString in class Object
See Also:
getDescription()

equals

public boolean equals(Object obj)
This implementation compares description strings.

Overrides:
equals in class Object
See Also:
getDescription()

hashCode

public int hashCode()
This implementation returns the description's hash code.

Overrides:
hashCode in class Object
See Also:
getDescription()


Copyright (c) 2002-2007 The Spring Framework Project.