pl.edu.agh.cast.resource
Class ResourceRegistry

java.lang.Object
  extended by pl.edu.agh.cast.resource.ResourceRegistry
All Implemented Interfaces:
IResourceRegistry

public class ResourceRegistry
extends Object
implements IResourceRegistry

Default implementation of IResourceRegistry.

Author:
AGH CAST Team

Constructor Summary
ResourceRegistry()
          Constructor.
 
Method Summary
 void dispose()
          Disposes all hold resources including loaded images.
 IVisualResource getResource(String id)
          Looks up and returns a resource with the given id.
 IVisualResource getResource(String id, String defaultId)
          Looks up and returns a resource with the given id.
 List<IVisualResource> getResources(String tag)
          Returns list of all resources marked with given tag.
 void initalize()
          Initialize the resource registry.
 void register(IVisualResource resource)
          Creates a new resource on base of the given entry and register it by given id and tags (all included in entry object).
protected  void setResourcesProvidersReader(pl.edu.agh.cast.resource.ResourceRegistry.IVisualResourcesProvidersReader reader)
           
 boolean unregister(String id)
           Unregisters a resource with the given id.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceRegistry

public ResourceRegistry()
Constructor.

Method Detail

getResource

public IVisualResource getResource(String id)
Looks up and returns a resource with the given id. If resource is not found null is returned.

Specified by:
getResource in interface IResourceRegistry
Parameters:
id - resource id
Returns:
resource object or null if no resource with given id is registered.
See Also:
IResourceRegistry.getResource(java.lang.String)

getResource

public IVisualResource getResource(String id,
                                   String defaultId)
Looks up and returns a resource with the given id. If resource is not then the resource with default id is returned. If none can be found null is returned.

Specified by:
getResource in interface IResourceRegistry
Parameters:
id - resource id
defaultId - default resource id
Returns:
resource object or default resource object or null if no resource with given id and default id is registered.
See Also:
IResourceRegistry.getResource(java.lang.String, java.lang.String)

getResources

public List<IVisualResource> getResources(String tag)
Returns list of all resources marked with given tag. For more details see class java doc.

Specified by:
getResources in interface IResourceRegistry
Parameters:
tag - tag which identifies resource family.
Returns:
list of resource associated with given tag; if no resources found an empty list is returned;
See Also:
IResourceRegistry.getResources(java.lang.String)

initalize

public void initalize()
               throws ResourceException
Initialize the resource registry. Reads available extensions from the extension point, creates and registers defined resources. Throws checked exception when any error in reading resources occur.

Specified by:
initalize in interface IResourceRegistry
Throws:
ResourceException
See Also:
IResourceRegistry.initalize()

dispose

public void dispose()
Disposes all hold resources including loaded images.

Specified by:
dispose in interface IResourceRegistry
See Also:
IResourceRegistry.dispose()

register

public void register(IVisualResource resource)
              throws ResourceException
Creates a new resource on base of the given entry and register it by given id and tags (all included in entry object).

Specified by:
register in interface IResourceRegistry
Parameters:
resource - resource to register
Throws:
ResourceException - when any error occur during creating resource or a resource with the same id already exists in the registry
See Also:
pl.edu.agh.cast.resource.IResourceRegistry#register(pl.edu.agh.cast.resource.VisualResourceEntry)

unregister

public boolean unregister(String id)
                   throws ResourceException

Unregisters a resource with the given id.

Note: the method disposes all images associated with resource making it unavailable in the application. It should be used carefully, only from performance reasons.

Specified by:
unregister in interface IResourceRegistry
Parameters:
id - resource id to unregister
Returns:
true if resource was successfully unregistered; false if resource didn't exist.
Throws:
ResourceException - when any error occurs during unregistering resource.
See Also:
IResourceRegistry.unregister(java.lang.String)

setResourcesProvidersReader

protected void setResourcesProvidersReader(pl.edu.agh.cast.resource.ResourceRegistry.IVisualResourcesProvidersReader reader)


Copyright © 2007-2009 IISG AGH-UST Krakow, Poland. All Rights Reserved.