public class ObjectMethodContentProvider extends PageFlowScopeAdapter implements Serializable, IUpdateableContentProvider, IRefreshableContentProvider
Content provider that wraps a method call on an object instance. Calls the method
when refresh()
method is called.
Used as a base class for web service client provider implementations
class Item { public int getId(); public String getName(); }; class ItemLoader { public Item loadItem(String fileName}; } class MethodContentProvider extends ObjectMethodContentProvider { public MethodContentProvider() { parameters = new HashMap(); // need to create storage for parameters } public Map getParameters() { return parameters; } } ItemLoader itemLoader = new ItemLoader(); MethodContentProvider provider = new MethodContentProvider(itemLoader, "loadItem", new String[] {"fileName"}) { provider.getParameters().put("fileName", "item.xml"); Item item = (Item)provider.getValue("result"); item.getId(); item.getName();
Modifier and Type | Field and Description |
---|---|
protected boolean |
autoRefresh |
protected IErrorHandler |
errorHandler |
protected Method |
method |
protected Object[] |
methodArgs |
protected String |
methodName |
protected boolean |
needRefresh |
protected Object |
objectInstance |
protected Class<?> |
objectType |
protected Object |
output |
protected Object[] |
parameterNames |
protected Object |
parameters |
protected Class<?>[] |
parameterTypes |
protected static String[] |
PROPERTY_KEYS |
protected static String |
PROPERTYKEY_OUTPUT |
protected static String |
PROPERTYKEY_PARAMETERS |
protected static String |
PROPERTYKEY_RESULT |
protected Object |
result |
fExpireWithPageFlow
Constructor and Description |
---|
ObjectMethodContentProvider(Class<?> objectType,
String methodName,
String[] parameterNames)
Initializes provider with object class, method name to call and method parameter names.
|
ObjectMethodContentProvider(Object objectInstance,
String methodName,
String[] parameterNames)
Initializes provider with object instance, method name and parameters names
|
Modifier and Type | Method and Description |
---|---|
protected void |
clearCookie() |
IErrorHandler |
getErrorHandler() |
protected Method |
getMethod()
Finds the method specified by its name and parameters
|
protected Object[] |
getMethodArgs()
Creates array of method arguments from the method call.
|
protected String |
getMethodName()
Returns method name
|
boolean |
getNeedRefresh()
Returns
true if refresh() was never called or setNeedRefresh(boolean)
is set with true value by the client. |
protected Object |
getObjectInstance()
Returns object instance to call the method on
|
protected Class<?> |
getObjectType()
Returns object class
|
protected Object[] |
getParameterNames()
Introspects parameter names from the actual parameters object.
|
protected Class<?> |
getParameterType(Object parameterName)
Default implementation uses Application properyResolver to get type of
the parameterName property on the parameters bean
|
protected Class<?>[] |
getParameterTypes()
Gets method parameter types
|
protected Object |
getParameterValue(Object parameterName) |
Object[] |
getPropertyKeys()
Returns list of properties supported by this content provider.
|
Class<?> |
getType(Object propertyKey)
Returns java type of the given property
|
Object |
getValue(Object propertyKey)
Returns value of the given property
|
boolean |
hasProperty(Object propertyKey)
Checks if the given property is supported by this content provider
|
boolean |
isAutoRefresh()
Returns
true if the provider is currenlty in auto-refresh mode |
boolean |
isReadOnly(Object propertyKey)
Returns true if the given property is readonly.
|
protected boolean |
isSessionExpired() |
void |
refresh()
Invokes {link #getMethod()} method on
getObjectInstance() passing getMethodArgs()
and updates the result property. |
void |
setAutoRefresh(boolean autorefresh)
Sets auto refresh mode on.
|
protected void |
setCookie() |
void |
setErrorHandler(IErrorHandler errorHandler) |
void |
setNeedRefresh(boolean needRefresh)
Tells the provider that the input parameters have changed and the output results need to be refreshed the next time any
output property is requested via
IContentProvider.getValue(Object) . |
protected void |
setObjectInstance(Object objectInstance)
Sets new object intance to call the method on
|
protected void |
setObjectType(Class<?> objectType)
Return object class
|
void |
setValue(Object propertyKey,
Object value)
Sets new value of the given property
|
boolean |
supportsAutoRefresh()
Returns
true . |
getExpireWithPageFlow, setExpireWithPageFlow
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
toString
protected static final String PROPERTYKEY_PARAMETERS
protected static final String PROPERTYKEY_RESULT
protected static final String PROPERTYKEY_OUTPUT
protected static final String[] PROPERTY_KEYS
protected Class<?> objectType
protected Class<?>[] parameterTypes
protected Object[] parameterNames
protected String methodName
protected transient Method method
protected Object objectInstance
protected Object parameters
protected Object result
protected Object output
protected Object[] methodArgs
protected boolean autoRefresh
protected boolean needRefresh
protected IErrorHandler errorHandler
public ObjectMethodContentProvider(Class<?> objectType, String methodName, String[] parameterNames)
objectType
- object class of the instancemethodName
- method nameparameterNames
- parameters bean property names that that match the order of the method to invokepublic ObjectMethodContentProvider(Object objectInstance, String methodName, String[] parameterNames)
objectInstance
- the object instancemethodName
- method nameparameterNames
- method parameter namesprotected Method getMethod() throws ContentProviderException
ContentProviderException
- if method cannot be foundprotected String getMethodName()
protected Object getObjectInstance() throws ContentProviderException
ContentProviderException
protected void setObjectInstance(Object objectInstance)
objectInstance
- object instanceprotected Class<?> getObjectType() throws ContentProviderException
ContentProviderException
protected void setObjectType(Class<?> objectType)
objectType
- protected Object[] getParameterNames() throws ContentProviderException
ContentProviderException
protected Class<?>[] getParameterTypes() throws ContentProviderException
ContentProviderException
protected Class<?> getParameterType(Object parameterName)
parameterName
- method parameter nameprotected Object[] getMethodArgs() throws ContentProviderException
ContentProviderException
public Object[] getPropertyKeys()
IContentProvider
Object[0]
,
never null.getPropertyKeys
in interface IContentProvider
PROPERTYKEY_PARAMETERS
public Class<?> getType(Object propertyKey) throws PropertyNotFoundException
IContentProvider
getType
in interface IContentProvider
propertyKey
- the property key of type String
or Integer
Class
PropertyNotFoundException
- if property is not supportedpublic Object getValue(Object propertyKey) throws ELException, PropertyNotFoundException
IContentProvider
getValue
in interface IContentProvider
propertyKey
- the property key of type String
or Integer
null
PropertyNotFoundException
- if property is not supportedELException
public IErrorHandler getErrorHandler()
public void setErrorHandler(IErrorHandler errorHandler)
public boolean hasProperty(Object propertyKey)
IContentProvider
hasProperty
in interface IContentProvider
propertyKey
- property key of type String
or Integer
propertyKey
PROPERTYKEY_PARAMETERS
or PROPERTYKEY_RESULT
.public boolean isReadOnly(Object propertyKey) throws ELException, PropertyNotFoundException
IUpdateableContentProvider
Returns true if the given property is readonly. If it is readonly, IUpdateableContentProvider.setValue(Object, Object)
will
definitely fail.
isReadOnly
in interface IUpdateableContentProvider
propertyKey
- property key of type String
or Integer
PROPERTYKEY_PARAMETERS
and true for PROPERTYKEY_RESULT
.PropertyNotFoundException
ELException
public void setValue(Object propertyKey, Object value) throws ELException, PropertyNotFoundException
IUpdateableContentProvider
Sets new value of the given property
setValue
in interface IUpdateableContentProvider
propertyKey
- property key of type String
or Integer
value
- new property valuePropertyNotFoundException
- if property is not foundELException
public void refresh() throws ContentProviderException
getObjectInstance()
passing getMethodArgs()
and updates the result property.refresh
in interface IRefreshable
ContentProviderException
- if error loading data from the data sourcepublic boolean supportsAutoRefresh()
true
.supportsAutoRefresh
in interface IRefreshable
IRefreshable.setAutoRefresh(boolean)
public void setAutoRefresh(boolean autorefresh) throws ContentProviderException
IRefreshable
Sets auto refresh mode on. When auto refresh mode is on, the provider calls IRefreshable.getNeedRefresh()
to determine whether the refresh needs to be done before returning any result properties. If it returns
true
, the provider calls IRefreshable.refresh()
method to updated the result properties.
setAutoRefresh
in interface IRefreshable
autorefresh
- true to turn it onContentProviderException
- if auto refresh mode is not supportedIRefreshable.supportsAutoRefresh()
,
IRefreshable.getNeedRefresh()
,
IRefreshable.setNeedRefresh(boolean)
public boolean isAutoRefresh()
IRefreshable
true
if the provider is currenlty in auto-refresh modeisAutoRefresh
in interface IRefreshable
public boolean getNeedRefresh()
true
if refresh()
was never called or setNeedRefresh(boolean)
is set with true
value by the client.getNeedRefresh
in interface IRefreshable
true
when the output properties are not up-to-date with the current input parameters, i.e. IRefreshable.refresh()
needs to be executed manually or automatically.public void setNeedRefresh(boolean needRefresh)
IRefreshable
IContentProvider.getValue(Object)
.setNeedRefresh
in interface IRefreshable
needRefresh
- true
if the input parameters have changedprotected void setCookie()
protected void clearCookie()
protected boolean isSessionExpired()