com.webmethods.caf.faces.data.object
Class ResourceBundleContentProvider

java.lang.Object
  extended by com.webmethods.caf.faces.data.object.ResourceBundleContentProvider
All Implemented Interfaces:
IContentProvider

public class ResourceBundleContentProvider
extends Object
implements IContentProvider

Adapts a ResourceBundle to an IContentProvider.

Emulates behaviour of f:loadBundle tag, generating "???key???" for the value of a missing resources.

Used internally by BaseFacesPreferencesBean.getPortletResources() and BaseApplicationBean.getApplicationResources().

 ResourceBundle rb = new ListResourceBundle {
   protected Object[][] getContents() {
       return new Object[][]{
           {"company.name", "webMethods"},
       } 
   };
 
 IContentProvider provider = new ResourceBundleContentProvider(rb);
 String contactName = provider.getValue("company.name"); // returns "webMethods"
 


Field Summary
protected  ResourceBundle m_bundle
           
 
Constructor Summary
ResourceBundleContentProvider()
          Default constructor.
ResourceBundleContentProvider(ResourceBundle bundle)
          Initializes provider with the given resource bundle.
 
Method Summary
 Object[] getPropertyKeys()
          Returns keys in the resource bundle
 ResourceBundle getResourceBundle()
          Returns wrapped resource bundle
 Class getType(Object propertyKey)
          Returns java type of the given property
 Object getValue(Object propertyKey)
          Returns the value from the resource bundle for the given key
 Object getValue(Object propertyKey, Object[] args)
          Returns the value from the resource bundle for the given key
 boolean hasProperty(Object propertyKey)
          Always return true.
 void setResourceBundle(ResourceBundle bundle)
          Sets resource bundle to wrap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.webmethods.caf.faces.data.IContentProvider
toString
 

Field Detail

m_bundle

protected ResourceBundle m_bundle
Constructor Detail

ResourceBundleContentProvider

public ResourceBundleContentProvider()
Default constructor. ResourceBundleContentProvider.setResourceBundle(ResourceBundle) must be called before use.


ResourceBundleContentProvider

public ResourceBundleContentProvider(ResourceBundle bundle)
Initializes provider with the given resource bundle.

Parameters:
bundle - resource bundle
Method Detail

getValue

public Object getValue(Object propertyKey)
                throws EvaluationException,
                       PropertyNotFoundException
Returns the value from the resource bundle for the given key

Specified by:
getValue in interface IContentProvider
Parameters:
propertyKey - the key to lookup the value in the resource bundle
Returns:
the value from the resource bundle
Throws:
EvaluationException - if error during property evaluation
PropertyNotFoundException - if property is not supported

getValue

public Object getValue(Object propertyKey,
                       Object[] args)
                throws EvaluationException,
                       PropertyNotFoundException
Returns the value from the resource bundle for the given key

Parameters:
propertyKey - the key to lookup the value in the resource bundle
args - the object array contains string substitution values
Returns:
the formatted string from the resource bundle
Throws:
EvaluationException
PropertyNotFoundException

getType

public Class getType(Object propertyKey)
              throws PropertyNotFoundException
Description copied from interface: IContentProvider
Returns java type of the given property

Specified by:
getType in interface IContentProvider
Parameters:
propertyKey - the property key of type String or Integer
Returns:
property java Class
Throws:
PropertyNotFoundException - if property is not supported

getPropertyKeys

public Object[] getPropertyKeys()
Returns keys in the resource bundle

Specified by:
getPropertyKeys in interface IContentProvider
Returns:
array of keys in the resource bundle

hasProperty

public boolean hasProperty(Object propertyKey)
Always return true.

Specified by:
hasProperty in interface IContentProvider
Parameters:
propertyKey - property key of type String or Integer
Returns:
true if property is supported

getResourceBundle

public ResourceBundle getResourceBundle()
Returns wrapped resource bundle

Returns:
null if not set

setResourceBundle

public void setResourceBundle(ResourceBundle bundle)
Sets resource bundle to wrap

Parameters:
bundle - resource bundle, must not be null