pl.edu.agh.cast.resource
Interface IResourceRegistry

All Known Implementing Classes:
ResourceRegistry

public interface IResourceRegistry

The registry which holds all visual resources in the application.

A single resource is identified by its unique id in String format. For resources associated with data types such as icon for visualizing entity, the id is equal to Type#toString(). For other resources such as actions icons, the id is java package style unique identifier.

Resources can also have tags (string identifiers) which allows for creating families of similar resources. For example all data sets could have DATA_SET_RESOURCE tag, creating data set resource family. Each resource can have zero or more associated tags.

A single resource is represented by IVisualResource interface - see java doc for more details.

The registry is initialized during the application start and reads & verifies all defined resources at this time so all errors or warnings are shown to user already at startup. Resources are read from pl.edu.agh.cast.resource.provider extension point which returns providers ( IVisualResourcesProvider) containing definition of resources.

Author:
AGH CAST Team

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).
 boolean unregister(String id)
           Unregisters a resource with the given id.
 

Method Detail

initalize

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.

Throws:
ResourceException

dispose

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


register

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).

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

unregister

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.

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.

getResource

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

Parameters:
id - resource id
Returns:
resource object or null if no resource with given id is registered.

getResource

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.

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.

getResources

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

Parameters:
tag - tag which identifies resource family.
Returns:
list of resource associated with given tag; if no resources found an empty list is returned;


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