org.codehaus.dna.impl
Class DefaultResourceLocator

java.lang.Object
  extended byorg.codehaus.dna.impl.AbstractFreezable
      extended byorg.codehaus.dna.impl.DefaultResourceLocator
All Implemented Interfaces:
Freezable, ResourceLocator

public class DefaultResourceLocator
extends org.codehaus.dna.impl.AbstractFreezable
implements ResourceLocator

ResourceLocator implementation backed by a Map and optionally delegating to parent ResourceLocators. The developer should create the DefaultResourceLocator, associate resources with locator and then invoke AbstractFreezable.makeReadOnly() before passing the Locator to the client component.

The implementation will first check for resources associated with itself and if unable to locate resource locally it will delegate to parent ResourceLocator.

Version:
$Revision: 1.2 $ $Date: 2004/05/01 09:51:48 $

Constructor Summary
DefaultResourceLocator()
          Create a ResourceLocator with no parent.
DefaultResourceLocator(ResourceLocator parent)
          Create a ResourceLocator with specified parent.
 
Method Summary
protected  void checkWriteable()
          Check if the resource has been "frozen" and thus is read only.
 boolean contains(java.lang.String key)
          Return true if a resource exists with specified key.
protected  ResourceLocator getParent()
          Return the parent ResourceLocator if any.
protected  java.util.Map getResourceMap()
          Return the map used to store resources.
protected  boolean isReadOnly()
          Return true if resource has been made read-only or frozen.
 java.lang.Object lookup(java.lang.String key)
          Return resource registered with specified key.
 void makeReadOnly()
          Mark the resource as read only.
 void put(java.lang.String key, java.lang.Object resource)
          Add a resource to resource locator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultResourceLocator

public DefaultResourceLocator()
Create a ResourceLocator with no parent.


DefaultResourceLocator

public DefaultResourceLocator(ResourceLocator parent)
Create a ResourceLocator with specified parent.

Parameters:
parent - the parent ResourceLocator
Method Detail

lookup

public java.lang.Object lookup(java.lang.String key)
                        throws MissingResourceException
Return resource registered with specified key.

Specified by:
lookup in interface ResourceLocator
Parameters:
key - the key
Returns:
the resource
Throws:
MissingResourceException - if unable to locate resource with specified key

contains

public boolean contains(java.lang.String key)
Return true if a resource exists with specified key.

Specified by:
contains in interface ResourceLocator
Parameters:
key - the key
Returns:
true if a resource exists with specified key.

put

public void put(java.lang.String key,
                java.lang.Object resource)
Add a resource to resource locator.

Parameters:
key - the key used to store resource (Must not be null).
resource - the resource (Must not be null).

getParent

protected final ResourceLocator getParent()
Return the parent ResourceLocator if any.

Returns:
the parent ResourceLocator if any.

getResourceMap

protected final java.util.Map getResourceMap()
Return the map used to store resources.

Returns:
the map used to store resources.

makeReadOnly

public void makeReadOnly()
Mark the resource as read only.

Specified by:
makeReadOnly in interface Freezable

checkWriteable

protected final void checkWriteable()
Check if the resource has been "frozen" and thus is read only. If read-only then throw an IllegalStateException.

Throws:
java.lang.IllegalStateException - if resource is read-only

isReadOnly

protected final boolean isReadOnly()
Return true if resource has been made read-only or frozen.

Returns:
true if resource has been made read-only or frozen, false otherwise.


Copyright © 2003-2004 Codehaus. All Rights Reserved.