|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.commons.resources.impl.ResourcesBase
public abstract class ResourcesBase
Convenience base class for
Resources
implementations.
Default implementations of the content retrieval methods are provided
for all methods except getObject()
. The default methods for
the other content retrieval methods are coded in terms of
getString()
, on the assumption that most uses of
Resources
are of this type.
However, they can be easily overridden as needed.
CollectionResourcesBase
,
JDBCResources
,
PropertyResources
,
ResourceBundleResources
,
WebappPropertyResources
,
WebappXMLResources
,
XMLResources
,
Serialized FormConstructor Summary | |
---|---|
ResourcesBase()
Create a new Resources instance
with no name. |
|
ResourcesBase(String name)
Create a new Resources instance
with the specified logical name. |
Method Summary | |
---|---|
void |
destroy()
This method must be called when the manager of this resource decides that it's no longer needed. |
int |
getBufferSize()
Return the size of the buffer to use when converting InputStream or Reader objects. |
byte[] |
getBytes(String key,
Locale locale)
Return the content for the specified key as a
byte array, localized based on the specified locale . |
InputStream |
getInputStream(String key,
Locale locale)
Return the content for the specified key as an
InputStream, localized based on the specified locale . |
abstract Iterator |
getKeys()
Return an Iterator over the defined keys in this
Resources instance. |
String |
getName()
Return the logical name of this Resources
instance. |
abstract Object |
getObject(String key,
Locale locale)
Return the content for the specified key as an
Object, localized based on the specified locale . |
Reader |
getReader(String key,
Locale locale)
Return the content for the specified key as a
Reader, localized based on the specified locale . |
String |
getString(String key,
Locale locale)
Return the content for the specified key as a
String, localized based on the specified locale . |
void |
init()
This must be called to initialize the data content of this Resources instance, before
any of the getXxx() methods are called. |
boolean |
isReturnNull()
Return true if resource getter methods will return
null instead of throwing an exception on invalid
key values. |
void |
setBufferSize(int bufferSize)
Set the size of the buffer to use when converting InputStream or Reader objects. |
void |
setReturnNull(boolean returnNull)
Set a flag determining whether resource getter methods should return null instead of throwing an exception on
invalid key values. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ResourcesBase()
Create a new Resources
instance
with no name.
public ResourcesBase(String name)
Create a new Resources
instance
with the specified logical name.
name
- Logical name of the new instanceMethod Detail |
---|
public void init()
This must be called to initialize the data content of this
Resources
instance, before
any of the getXxx()
methods are called.
The default implementation does nothing.
init
in interface Resources
ResourcesException
- if an error occurs during initializationpublic void destroy()
This method must be called when the manager of this resource
decides that it's no longer needed. After this method is called,
no further calls to any of the getXxx()
methods are
allowed.
The default implementation does nothing.
destroy
in interface Resources
ResourcesException
- if an error occurs during finalizationpublic abstract Iterator getKeys()
Return an Iterator
over the defined keys in this
Resources
instance.
getKeys
in interface Resources
public String getName()
Return the logical name of this Resources
instance.
getName
in interface Resources
public boolean isReturnNull()
Return true
if resource getter methods will return
null
instead of throwing an exception on invalid
key values.
isReturnNull
in interface Resources
public void setReturnNull(boolean returnNull)
Set a flag determining whether resource getter methods should
return null
instead of throwing an exception on
invalid key values.
setReturnNull
in interface Resources
returnNull
- The new flag valuepublic int getBufferSize()
Return the size of the buffer to use when converting InputStream or Reader objects.
public void setBufferSize(int bufferSize)
Set the size of the buffer to use when converting InputStream or Reader objects.
bufferSize
- The buffer size.public byte[] getBytes(String key, Locale locale)
Return the content for the specified key
as a
byte array, localized based on the specified locale
.
The default implementation calls getString()
and
converts the value to a byte array.
getBytes
in interface Resources
key
- Identifier for the requested contentlocale
- Locale with which to localize retrieval,
or null
for the default Locale
ResourcesException
- if an error occurs retrieving or
returning the requested content
ResourcesKeyException
- if the no value for the specified
key was found, and isReturnNull()
returns
false
public InputStream getInputStream(String key, Locale locale)
Return the content for the specified key
as an
InputStream, localized based on the specified locale
.
The default implementation calls getsBytes()
and returns an input stream over the resulting byte array.
getInputStream
in interface Resources
key
- Identifier for the requested contentlocale
- Locale with which to localize retrieval,
or null
for the default Locale
ResourcesException
- if an error occurs retrieving or
returning the requested content
ResourcesKeyException
- if the no value for the specified
key was found, and isReturnNull()
returns
false
public abstract Object getObject(String key, Locale locale)
Return the content for the specified key
as an
Object, localized based on the specified locale
.
There is no default implementation of this method. Concrete subclasses must provide such an implementation.
getObject
in interface Resources
key
- Identifier for the requested contentlocale
- Locale with which to localize retrieval,
or null
for the default Locale
ResourcesException
- if an error occurs retrieving or
returning the requested content
ResourcesKeyException
- if the no value for the specified
key was found, and isReturnNull()
returns
false
public Reader getReader(String key, Locale locale)
Return the content for the specified key
as a
Reader, localized based on the specified locale
.
The default implementation calls getString()
and returns a reader over the resulting characters.
getReader
in interface Resources
key
- Identifier for the requested contentlocale
- Locale with which to localize retrieval,
or null
for the default Locale
ResourcesException
- if an error occurs retrieving or
returning the requested content
ResourcesKeyException
- if the no value for the specified
key was found, and isReturnNull()
returns
false
public String getString(String key, Locale locale)
Return the content for the specified key
as a
String, localized based on the specified locale
.
The default implementation calls getObject()
and converts the result to a String if necessary.
getString
in interface Resources
key
- Identifier for the requested contentlocale
- Locale with which to localize retrieval,
or null
for the default Locale
ResourcesException
- if an error occurs retrieving or
returning the requested content
ResourcesKeyException
- if the no value for the specified
key was found, and isReturnNull()
returns
false
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |