Class ObjectMethodContentProvider
java.lang.Object
com.webmethods.caf.faces.bean.PageFlowScopeAdapter
com.webmethods.caf.faces.data.object.ObjectMethodContentProvider
- All Implemented Interfaces:
IPageFlowScopeAdapter
,IContentProvider
,IRefreshable
,IRefreshableContentProvider
,IUpdateableContentProvider
,Serializable
- Direct Known Subclasses:
BaseWSClientContentProvider
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();
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
protected IErrorHandler
protected Method
protected Object[]
protected String
protected boolean
protected Object
protected Class<?>
protected Object
protected Object[]
protected Object
protected Class<?>[]
protected static final String[]
protected static final String
protected static final String
protected static final String
protected Object
Fields inherited from class com.webmethods.caf.faces.bean.PageFlowScopeAdapter
fExpireWithPageFlow
-
Constructor Summary
ConstructorsConstructorDescriptionObjectMethodContentProvider
(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 -
Method Summary
Modifier and TypeMethodDescriptionprotected void
protected Method
Finds the method specified by its name and parametersprotected Object[]
Creates array of method arguments from the method call.protected String
Returns method nameboolean
Returnstrue
ifrefresh()
was never called orsetNeedRefresh(boolean)
is set withtrue
value by the client.protected Object
Returns object instance to call the method onprotected Class<?>
Returns object classprotected Object[]
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 beanprotected Class<?>[]
Gets method parameter typesprotected Object
getParameterValue
(Object parameterName) Object[]
Returns list of properties supported by this content provider.Class<?>
Returns java type of the given propertyReturns value of the given propertyboolean
hasProperty
(Object propertyKey) Checks if the given property is supported by this content providerboolean
Returnstrue
if the provider is currenlty in auto-refresh modeboolean
isReadOnly
(Object propertyKey) Returns true if the given property is readonly.protected boolean
void
refresh()
Invokes {link #getMethod()} method ongetObjectInstance()
passinggetMethodArgs()
and updates the result property.void
setAutoRefresh
(boolean autorefresh) Sets auto refresh mode on.protected void
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 viaIContentProvider.getValue(Object)
.protected void
setObjectInstance
(Object objectInstance) Sets new object intance to call the method onprotected void
setObjectType
(Class<?> objectType) Return object classvoid
Sets new value of the given propertyboolean
Returnstrue
.Methods inherited from class com.webmethods.caf.faces.bean.PageFlowScopeAdapter
getExpireWithPageFlow, setExpireWithPageFlow
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 Details
-
PROPERTYKEY_PARAMETERS
- See Also:
-
PROPERTYKEY_RESULT
- See Also:
-
PROPERTYKEY_OUTPUT
- See Also:
-
PROPERTY_KEYS
-
objectType
-
parameterTypes
-
parameterNames
-
methodName
-
method
-
objectInstance
-
parameters
-
result
-
output
-
methodArgs
-
autoRefresh
protected boolean autoRefresh -
needRefresh
protected boolean needRefresh -
errorHandler
-
-
Constructor Details
-
ObjectMethodContentProvider
Initializes provider with object class, method name to call and method parameter names.- Parameters:
objectType
- object class of the instancemethodName
- method nameparameterNames
- parameters bean property names that that match the order of the method to invoke
-
ObjectMethodContentProvider
public ObjectMethodContentProvider(Object objectInstance, String methodName, String[] parameterNames) Initializes provider with object instance, method name and parameters names- Parameters:
objectInstance
- the object instancemethodName
- method nameparameterNames
- method parameter names
-
-
Method Details
-
getMethod
Finds the method specified by its name and parameters- Returns:
- java reflection method or null
- Throws:
ContentProviderException
- if method cannot be found
-
getMethodName
Returns method name- Returns:
- method name
-
getObjectInstance
Returns object instance to call the method on- Returns:
- object instance
- Throws:
ContentProviderException
-
setObjectInstance
Sets new object intance to call the method on- Parameters:
objectInstance
- object instance
-
getObjectType
Returns object class- Returns:
- object class
- Throws:
ContentProviderException
-
setObjectType
Return object class- Parameters:
objectType
-
-
getParameterNames
Introspects parameter names from the actual parameters object.- Returns:
- array of parameter property names
- Throws:
ContentProviderException
-
getParameterTypes
Gets method parameter types- Returns:
- array of parameter types
- Throws:
ContentProviderException
-
getParameterType
Default implementation uses Application properyResolver to get type of the parameterName property on the parameters bean- Parameters:
parameterName
- method parameter name- Returns:
- type
-
getMethodArgs
Creates array of method arguments from the method call. Obtains parameter values from the parameters object.- Returns:
- initialized array of method arguments
- Throws:
ContentProviderException
-
getParameterValue
-
getPropertyKeys
Description copied from interface:IContentProvider
Returns list of properties supported by this content provider. Can returnObject[0]
, never null.- Specified by:
getPropertyKeys
in interfaceIContentProvider
- Returns:
- array of property keys which is typically of type
String
orInteger
-
getType
Description copied from interface:IContentProvider
Returns java type of the given property- Specified by:
getType
in interfaceIContentProvider
- Parameters:
propertyKey
- the property key of typeString
orInteger
- Returns:
- property java
Class
- Throws:
PropertyNotFoundException
- if property is not supported
-
getValue
Description copied from interface:IContentProvider
Returns value of the given property- Specified by:
getValue
in interfaceIContentProvider
- Parameters:
propertyKey
- the property key of typeString
orInteger
- Returns:
- value of the property, can be
null
- Throws:
PropertyNotFoundException
- if property is not supportedELException
-
getErrorHandler
-
setErrorHandler
-
hasProperty
Description copied from interface:IContentProvider
Checks if the given property is supported by this content provider- Specified by:
hasProperty
in interfaceIContentProvider
- Parameters:
propertyKey
- property key of typeString
orInteger
- Returns:
true
if property is supported
-
isReadOnly
Description copied from interface:IUpdateableContentProvider
Returns true if the given property is readonly. If it is readonly,
IUpdateableContentProvider.setValue(Object, Object)
will definitely fail.- Specified by:
isReadOnly
in interfaceIUpdateableContentProvider
- Parameters:
propertyKey
- property key of typeString
orInteger
- Returns:
- true if the property is readonly
- Throws:
PropertyNotFoundException
ELException
-
setValue
public void setValue(Object propertyKey, Object value) throws ELException, PropertyNotFoundException Description copied from interface:IUpdateableContentProvider
Sets new value of the given property
- Specified by:
setValue
in interfaceIUpdateableContentProvider
- Parameters:
propertyKey
- property key of typeString
orInteger
value
- new property value- Throws:
PropertyNotFoundException
- if property is not foundELException
-
refresh
Invokes {link #getMethod()} method ongetObjectInstance()
passinggetMethodArgs()
and updates the result property.- Specified by:
refresh
in interfaceIRefreshable
- Throws:
ContentProviderException
- if error loading data from the data source
-
supportsAutoRefresh
public boolean supportsAutoRefresh()Returnstrue
.- Specified by:
supportsAutoRefresh
in interfaceIRefreshable
- Returns:
- true when auto refresh is supported
- See Also:
-
setAutoRefresh
Description copied from interface: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 returnstrue
, the provider callsIRefreshable.refresh()
method to updated the result properties.- Specified by:
setAutoRefresh
in interfaceIRefreshable
- Parameters:
autorefresh
- true to turn it on- Throws:
ContentProviderException
- if auto refresh mode is not supported- See Also:
-
isAutoRefresh
public boolean isAutoRefresh()Description copied from interface:IRefreshable
Returnstrue
if the provider is currenlty in auto-refresh mode- Specified by:
isAutoRefresh
in interfaceIRefreshable
- Returns:
- false if auto-refresh mode is off or not supported
-
getNeedRefresh
public boolean getNeedRefresh()Returnstrue
ifrefresh()
was never called orsetNeedRefresh(boolean)
is set withtrue
value by the client.- Specified by:
getNeedRefresh
in interfaceIRefreshable
- Returns:
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.
-
setNeedRefresh
public void setNeedRefresh(boolean needRefresh) Description copied from interface:IRefreshable
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 viaIContentProvider.getValue(Object)
.- Specified by:
setNeedRefresh
in interfaceIRefreshable
- Parameters:
needRefresh
-true
if the input parameters have changed
-
setCookie
protected void setCookie() -
clearCookie
protected void clearCookie() -
isSessionExpired
protected boolean isSessionExpired()
-