com.calitha.resource
Class Resource

java.lang.Object
  extended by com.calitha.resource.Resource
All Implemented Interfaces:
IResource
Direct Known Subclasses:
BinaryResource, TextResource

public abstract class Resource
extends Object
implements IResource

A Resource object represents a resource such as text or a www resource that can be used in your application.

This class must be extended to create a concrete implementation.

Author:
Robert van Loenhout

Constructor Summary
Resource(Locale locale, String namespace, String id, String mimetype)
          Creates a new resource object.
 
Method Summary
static String createKey(String namespace, String id)
          Creates a key used to store a resource in a map.
 boolean equals(Object obj)
           
 String getId()
          Gets the id of the resource.
 String getKey()
          Gets the key of the resource.
 Locale getLocale()
          Gets the locale that this resource is associated with.
 String getMimetype()
          Gets the mimetype of the resource.
 String getNamespace()
          Gets the namespace that the resource is part of.
 int hashCode()
           
 String toString()
           
 void toString(StringBuffer buffer)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.calitha.resource.IResource
getBytes, getText, getText
 

Constructor Detail

Resource

public Resource(Locale locale,
                String namespace,
                String id,
                String mimetype)
Creates a new resource object.

Parameters:
locale - locale
namespace - namespace
id - id
mimetype - mimetype
Throws:
IllegalArgumentException - if an argument is null
Method Detail

getLocale

public Locale getLocale()
Description copied from interface: IResource
Gets the locale that this resource is associated with.

Each resource is associated with a particular locale. However both the language and country can be empty mean it can be used for all languages and countries.

Specified by:
getLocale in interface IResource
Returns:
locale

getNamespace

public String getNamespace()
Description copied from interface: IResource
Gets the namespace that the resource is part of. This is used to keep resources with the same id seperate like java packages do, or XML namespaces.

Specified by:
getNamespace in interface IResource
Returns:
namespace

getId

public String getId()
Description copied from interface: IResource
Gets the id of the resource.

Specified by:
getId in interface IResource
Returns:
resource name

getKey

public String getKey()
Description copied from interface: IResource
Gets the key of the resource.

This is a combination of namespace and id. For example: namespace=com.caltiha, id=msg, key=com.calitha.msg If the namespace is null, then the key is the same as the id.

Specified by:
getKey in interface IResource
Returns:
resource key

getMimetype

public String getMimetype()
Description copied from interface: IResource
Gets the mimetype of the resource.

Specified by:
getMimetype in interface IResource
Returns:
mimetype

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

toString

public void toString(StringBuffer buffer)

toString

public String toString()
Overrides:
toString in class Object

createKey

public static String createKey(String namespace,
                               String id)
Creates a key used to store a resource in a map.

Parameters:
namespace - namespace
id - id
Returns:
key string