net.sf.mmm.util.resource.base
Class AbstractDataResourceProxy

java.lang.Object
  extended by net.sf.mmm.util.resource.base.AbstractDataResourceProxy
All Implemented Interfaces:
DataResource
Direct Known Subclasses:
AbstractBrowsableResourceProxy, AbstractDataResourceFactory.DataResourceAdapter

public abstract class AbstractDataResourceProxy
extends Object
implements DataResource

This is an abstract implementation of the DataResource interface that delegates to another DataResource.

Since:
1.0.2
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)

Constructor Summary
AbstractDataResourceProxy()
          The constructor.
 
Method Summary
protected abstract  DataResource getDelegate()
          This method gets the DataResource this proxy delegates to.
 Date getLastModificationDate()
          This method gets the last modification date of the DataResource if available and supported.
 String getName()
          This method gets the name of the resource.
 String getPath()
          This method gets the path of this resource.
 long getSize()
          This method gets the size (content-length) of this resource.
 String getUri()
          This method gets a string identifying this DataResource.
 URL getUrl()
          This method gets this resource as URL.
 boolean isAvailable()
          This method determines if this resource is available.
 boolean isData()
          This method determines if this resource has potentially data available.
 Boolean isModifiedSince(Date date)
          This method determines if this resource has been been modified since the given data.
 DataResource navigate(String relativePath)
          This method creates a new DataResource pointing to the given resourcePath based on this resource.
 OutputStream openOutputStream()
          This method opens an output-stream in order to write data to the resource.
 InputStream openStream()
          This method opens this resource for reading.
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractDataResourceProxy

public AbstractDataResourceProxy()
The constructor.

Method Detail

getDelegate

protected abstract DataResource getDelegate()
This method gets the DataResource this proxy delegates to.

Returns:
the delegate.

getPath

public String getPath()
This method gets the path of this resource. Please note that the path is including the name of the resource.
ATTENTION:
The result of this method may differ to the path used in the URL when this resource has been created.

Specified by:
getPath in interface DataResource
Returns:
the path that was used to identify this resource when creating.

getName

public String getName()
This method gets the name of the resource. It is analog to a filename.

Specified by:
getName in interface DataResource
Returns:
the name of the resource.

getSize

public long getSize()
This method gets the size (content-length) of this resource.

Specified by:
getSize in interface DataResource
Returns:
the size of this resource.

getUrl

public URL getUrl()
This method gets this resource as URL.

Specified by:
getUrl in interface DataResource
Returns:
the URL that represents this resource.

getUri

public String getUri()
This method gets a string identifying this DataResource. In most cases this will be the same as string-representation of the URL. However this method will not throw an exception.

Specified by:
getUri in interface DataResource
Returns:
the URI as string.

isAvailable

public boolean isAvailable()
This method determines if this resource is available. Available simply means that it exists and data can be read.
ATTENTION:
Depending on the underlying implementation this can be a relatively expensive operation. E.g. if this resource points to a remote URL this method has to open a network connection in order to verify if the resource is available. Use DataResource.isData() to prevent such expensive operaitons.

Specified by:
isAvailable in interface DataResource
Returns:
true if this resource is available, false otherwise.

isData

public boolean isData()
This method determines if this resource has potentially data available. Unlike DataResource.isAvailable() this method will not invoke expensive operations like connecting to remote URLs. If this method will return false, then DataResource.isAvailable() would also have returned false. However in case of true only DataResource.isAvailable() can guarantee if a resource really exists and contains data. E.g. if the resource points to a File then this method can check if it is a data-file. So in case it points to a directory or does not exist at all in the filesystem, this method will return false. Please also note that this may invoke expensive operations if the according directory path points to something like a network share. You should also be aware that the state of DataResource.isData() and DataResource.isAvailable() can change at any time so you never have a full guarantee if some data exists or NOT. However in most cases it is very improbable that this status changes when you read the resource immediately after the check.

Specified by:
isData in interface DataResource
Returns:
true if this resource points to potential data, false otherwise.

navigate

public DataResource navigate(String relativePath)
This method creates a new DataResource pointing to the given resourcePath based on this resource.
E.g. if this resource points to the file "/etc/init.d/rc" and relativePath would be "../apt/sources.list" the resulting resource would point to "/etc/apt/sources.list".

Specified by:
navigate in interface DataResource
Parameters:
relativePath - is the absolute or relative path pointing to a new resource. If it is a relative path, it is interpreted relative to the parent URI (directory) of this resource.
Returns:
is the resource pointing to the given path (relative to this resource).

openStream

public InputStream openStream()
This method opens this resource for reading.

Specified by:
openStream in interface DataResource
Returns:
the input stream where to read from.
See Also:
URL.openStream()

openOutputStream

public OutputStream openOutputStream()
This method opens an output-stream in order to write data to the resource.

Specified by:
openOutputStream in interface DataResource
Returns:
the OutputStream to write to the resource.

isModifiedSince

public Boolean isModifiedSince(Date date)
This method determines if this resource has been been modified since the given data.

Specified by:
isModifiedSince in interface DataResource
Parameters:
date - is the Date to check for.
Returns:
true if the resource has been modified after the given date, false if it has NOT been modified after the given date and null if this can NOT be determined (resource not available or operation NOT supported by this resource).

getLastModificationDate

public Date getLastModificationDate()
This method gets the last modification date of the DataResource if available and supported.

Specified by:
getLastModificationDate in interface DataResource
Returns:
the last modification Date or null if not available or supported.

toString

public String toString()

Overrides:
toString in class Object


Copyright © 2001-2010 mmm-Team. All Rights Reserved.