org.apache.tools.ant.types.resources

Class ResourceDecorator

public abstract class ResourceDecorator extends Resource

Abstract class that delegates all reading methods of Resource to its wrapped resource and deals with reference handling.

Overwrites all setters to throw exceptions.

Since: Ant 1.8.0

Constructor Summary
protected ResourceDecorator()
no arg constructor
protected ResourceDecorator(ResourceCollection other)
Constructor with another resource to wrap.
Method Summary
voidaddConfigured(ResourceCollection a)
Sets the resource to wrap using a single-element collection.
Objectas(Class clazz)
intcompareTo(Object other)
protected voiddieOnCircularReference(Stack stack, Project project)
InputStreamgetInputStream()
Get an InputStream for the Resource.
longgetLastModified()
Tells the modification time in milliseconds since 01.01.1970 .
StringgetName()
Get the name of the resource.
OutputStreamgetOutputStream()
Get an OutputStream for the Resource.
protected ResourcegetResource()
De-references refids if any, ensures a wrapped resource has been specified.
longgetSize()
Get the size of this Resource.
inthashCode()
Get the hash code for this Resource.
booleanisDirectory()
Tells if the resource is a directory.
booleanisExists()
The exists attribute tells whether a file exists.
booleanisFilesystemOnly()
Fulfill the ResourceCollection contract.
voidsetDirectory(boolean directory)
Override setDirectory.
voidsetExists(boolean exists)
Set the exists attribute.
voidsetLastModified(long lastmodified)
Override setLastModified.
voidsetName(String name)
Overridden, not allowed to set the name of the resource.
voidsetRefid(Reference r)
Overrides the base version.
voidsetSize(long size)
Override setSize.

Constructor Detail

ResourceDecorator

protected ResourceDecorator()
no arg constructor

ResourceDecorator

protected ResourceDecorator(ResourceCollection other)
Constructor with another resource to wrap.

Parameters: other the resource to wrap.

Method Detail

addConfigured

public final void addConfigured(ResourceCollection a)
Sets the resource to wrap using a single-element collection.

Parameters: a the resource to wrap as a single element Resource collection.

as

public Object as(Class clazz)
{@inheritDoc }

compareTo

public int compareTo(Object other)
{@inheritDoc }

dieOnCircularReference

protected void dieOnCircularReference(Stack stack, Project project)
{@inheritDoc }

getInputStream

public InputStream getInputStream()
Get an InputStream for the Resource.

Returns: an InputStream containing this Resource's content.

Throws: IOException if unable to provide the content of this Resource as a stream. UnsupportedOperationException if InputStreams are not supported for this Resource type.

getLastModified

public long getLastModified()
Tells the modification time in milliseconds since 01.01.1970 .

Returns: 0 if the resource does not exist to mirror the behavior of java.io.File File.

getName

public String getName()
Get the name of the resource.

Returns: the name of the wrapped resource.

getOutputStream

public OutputStream getOutputStream()
Get an OutputStream for the Resource.

Returns: an OutputStream to which content can be written.

Throws: IOException if unable to provide the content of this Resource as a stream. UnsupportedOperationException if OutputStreams are not supported for this Resource type.

getResource

protected final Resource getResource()
De-references refids if any, ensures a wrapped resource has been specified.

getSize

public long getSize()
Get the size of this Resource.

Returns: the size, as a long, 0 if the Resource does not exist (for compatibility with java.io.File), or UNKNOWN_SIZE if not known.

hashCode

public int hashCode()
Get the hash code for this Resource.

Returns: hash code as int.

isDirectory

public boolean isDirectory()
Tells if the resource is a directory.

Returns: boolean flag indicating if the resource is a directory.

isExists

public boolean isExists()
The exists attribute tells whether a file exists.

Returns: true if this resource exists.

isFilesystemOnly

public boolean isFilesystemOnly()
Fulfill the ResourceCollection contract.

Returns: whether this Resource is a FileProvider.

setDirectory

public void setDirectory(boolean directory)
Override setDirectory.

Parameters: directory not used.

Throws: BuildException always.

setExists

public void setExists(boolean exists)
Set the exists attribute.

Parameters: exists if true, this resource exists.

setLastModified

public void setLastModified(long lastmodified)
Override setLastModified.

Parameters: lastmodified not used.

Throws: BuildException always.

setName

public void setName(String name)
Overridden, not allowed to set the name of the resource.

Parameters: name not used.

Throws: BuildException always.

setRefid

public void setRefid(Reference r)
Overrides the base version.

Parameters: r the Reference to set.

setSize

public void setSize(long size)
Override setSize.

Parameters: size not used.

Throws: BuildException always.