net.shibboleth.utilities.java.support.resource
Class AbstractResource

java.lang.Object
  extended by net.shibboleth.utilities.java.support.component.AbstractDestructableInitializableComponent
      extended by net.shibboleth.utilities.java.support.resource.AbstractResource
All Implemented Interfaces:
Component, DestructableComponent, InitializableComponent, ValidatableComponent, Resource
Direct Known Subclasses:
ClasspathResource, FilesystemResource, HttpResource

public abstract class AbstractResource
extends AbstractDestructableInitializableComponent
implements Resource

Base class for resources.


Field Summary
private  String location
          Location of the resource.
 
Constructor Summary
AbstractResource()
           
 
Method Summary
protected abstract  boolean doExists()
          Checks whether the resource exists.
protected abstract  InputStream doGetInputStream()
          Gets the input stream to the resource's data.
protected abstract  long doGetLastModifiedTime()
          Gets the time, in milliseconds since the epoch, when the resource was last modified.
protected  void doValidate()
          Performs the logic to validate this component.
 boolean equals(Object obj)
          Two resources are considered equal if they are of the same type and and have the same location.
 boolean exists()
          Checks whether the resource exists.
 InputStream getInputStream()
          Gets the input stream to the resource's data.
 long getLastModifiedTime()
          Gets the time, in milliseconds since the epoch, when the resource was last modified.
 String getLocation()
          Gets resource location information.
 int hashCode()
          
protected  void setLocation(String resourceLocation)
          Sets the resource location.
 String toString()
          
 void validate()
          Checks whether this component is valid and ready to be used.
 
Methods inherited from class net.shibboleth.utilities.java.support.component.AbstractDestructableInitializableComponent
destroy, doDestroy, doInitialize, initialize, isDestroyed, isInitialized
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.shibboleth.utilities.java.support.component.DestructableComponent
destroy, isDestroyed
 
Methods inherited from interface net.shibboleth.utilities.java.support.component.InitializableComponent
initialize, isInitialized
 

Field Detail

location

private String location
Location of the resource.

Constructor Detail

AbstractResource

public AbstractResource()
Method Detail

validate

public final void validate()
                    throws ComponentValidationException
Checks whether this component is valid and ready to be used.

This method delegates to doValidate() if the component is not destroyed and is initialized.

Specified by:
validate in interface ValidatableComponent
Throws:
ComponentValidationException - thrown if the component is not currently in a valid and usable state

exists

@Nonnull
public final boolean exists()
                     throws ResourceException
Checks whether the resource exists.

This method delegates to doExists() if this component is not destroyed and is initialized.

Specified by:
exists in interface Resource
Returns:
true if the resource exists, false if not
Throws:
ResourceException - thrown if there is a problem determining if the resource exists

getInputStream

@Nonnull
public final InputStream getInputStream()
                                 throws ResourceException
Gets the input stream to the resource's data.

This method delegates to doGetInputStream() if this component is not destroyed and is initialized.

Specified by:
getInputStream in interface Resource
Returns:
input stream to the resource's data
Throws:
ResourceException - thrown if an input stream can not be created for the resource

getLastModifiedTime

@Nonnull
public final long getLastModifiedTime()
                               throws ResourceException
Gets the time, in milliseconds since the epoch, when the resource was last modified.

This method delegates to doGetLastModifiedTime() if this component is not destroyed and is initialized.

Specified by:
getLastModifiedTime in interface Resource
Returns:
time, in milliseconds since the epoch, when the resource was last modified
Throws:
ResourceException - thrown if the last modified time can not be determined

getLocation

@Nonnull
public final String getLocation()
Gets resource location information. Examples might be filesystem path, URL, etc.

Specified by:
getLocation in interface Resource
Returns:
resource location information

equals

public boolean equals(@Nullable
                      Object obj)
Two resources are considered equal if they are of the same type and and have the same location.

Overrides:
equals in class Object

hashCode

public int hashCode()

Overrides:
hashCode in class Object

toString

public String toString()

Overrides:
toString in class Object

setLocation

protected void setLocation(@Nullable
                           String resourceLocation)
Sets the resource location.

Parameters:
resourceLocation - the resource location

doValidate

protected void doValidate()
                   throws ComponentValidationException
Performs the logic to validate this component.

This implementation checks that the resource exists via exists().

Throws:
ComponentValidationException - thrown if the component is not valid

doExists

@Nonnull
protected abstract boolean doExists()
                             throws ResourceException
Checks whether the resource exists.

Returns:
true if the resource exists, false if not
Throws:
ResourceException - thrown if there is a problem determining if the resource exists

doGetInputStream

@Nonnull
protected abstract InputStream doGetInputStream()
                                         throws ResourceException
Gets the input stream to the resource's data.

Returns:
input stream to the resource's data
Throws:
ResourceException - thrown if an input stream can not be created for the resource

doGetLastModifiedTime

@Nonnull
protected abstract long doGetLastModifiedTime()
                                       throws ResourceException
Gets the time, in milliseconds since the epoch, when the resource was last modified.

Returns:
time, in milliseconds since the epoch, when the resource was last modified
Throws:
ResourceException - thrown if the last modified time can not be determined


Copyright © 1999-2012. All Rights Reserved.